vaadin / hilla

Build better business applications, faster. No more juggling REST endpoints or deciphering GraphQL queries. Hilla seamlessly connects Spring Boot and React to accelerate application development.
https://hilla.dev
Apache License 2.0
903 stars 57 forks source link

[Full-stack Signals] make default value optional #2746

Open platosha opened 1 week ago

platosha commented 1 week ago

Calling a signal endpoint requires providing initial client-side value. Coming up with initial value for complex types is inherently complex. A full value could end up as a lengthy literal:

const person = new PersonEndpoint.personSignal({defaultValue: {name: '', dob: '1970-01-01'}});

This complexity could be mitigated with some help from a generated model:

const person = new PersonEndpoint.personSignal({defaultValue: PersonModel.createEmptyValue()});

However, we could reduce the complexity even further by using the model data on the Hilla end, so that using the signals don't require default value:

const person = new PersonEndpoint.personSignal(); // initialized using the model
Legioth commented 1 week ago

From where does 1970-01-01 end up as the date of birth in PersonModel.createEmptyValue()?

platosha commented 4 days ago

For nullable signals, we could use undefined as the default value instead of the model's value.