Structured signal values are currently serialized only when a signal is initialized through dataSignal or dataSignals.
val person = dataSignal("person", Person("John Doe", 18))
This correctly renders the initial value as a JavaScript object:
$person = {name: 'John Doe', age: 18}
However, assigning a new Kotlin value through setValue does not use the same serialization logic:
person.setValue(Person("Jane Doe", 21))
The value is currently inserted directly into the generated JavaScript expression rather than being rendered as a JavaScript object literal. This leads to inconsistent behavior between signal initialization and signal updates, and prevents structured values from being safely assigned after initialization.
Serialization of a Kotlin signal value should be owned by the signal API and applied consistently wherever a value is emitted into a Datastar expression.
Possible API
@DatastarSignal
data class Person(
val name: String,
val age: Int,
)
val person = dataSignal("person", Person("John Doe", 18))
dataOn(Event.Click) {
person.setValue(Person("Jane Doe", 21))
}
Expected generated expression:
$person = {name: 'Jane Doe', age: 21}
Assignments from an existing Datastar expression should remain distinct from assignments of Kotlin values:
person.setValue(otherPerson)
Acceptance criteria
- A signal value is rendered consistently during both initialization and setValue.
- Nested typed values are serialized recursively into JavaScript object literals.
- Strings remain JavaScript strings and are not interpreted as raw JavaScript objects.
- Structured values are not rendered through arbitrary toString() output.
- Existing escaping behavior for object keys and string values is preserved.
- Tests cover signal initialization and setValue for scalars, nested values, null values, and escaped strings.
Related to: #15
Related to: #16
Structured signal values are currently serialized only when a signal is initialized through
dataSignalordataSignals.This correctly renders the initial value as a JavaScript object:
However, assigning a new Kotlin value through setValue does not use the same serialization logic:
The value is currently inserted directly into the generated JavaScript expression rather than being rendered as a JavaScript object literal. This leads to inconsistent behavior between signal initialization and signal updates, and prevents structured values from being safely assigned after initialization.
Serialization of a Kotlin signal value should be owned by the signal API and applied consistently wherever a value is emitted into a Datastar expression.
Possible API
Expected generated expression:
Assignments from an existing Datastar expression should remain distinct from assignments of Kotlin values:
Acceptance criteria
Related to: #15
Related to: #16