-
Notifications
You must be signed in to change notification settings - Fork 191
feat: Make two-way signal bindings explicit with a write callback parameter #23469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ameter Change bindValue(WritableSignal<V>) to bindValue(Signal<V>, SerializableConsumer<V>) so that two-way bindings require an explicit write-back callback. This forces developers to acknowledge when user input is received, providing an additional layer of safety. The first parameter is a read-only Signal for the signal-to-component direction. The second parameter is the callback for propagating value changes back to the signal. After invoking the callback, the signal is re-consulted via peek() and if the value differs, the component reverts to the signal's value. A null callback creates a read-only binding that throws on setValue while attached.
| throw new BindingActiveException(); | ||
| } | ||
|
|
||
| this.readSignal = valueSignal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readSignal is not needed here as it's already stored in SignalBindingFeature. writeCallback should be stored in SignalBindingFeature instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
| SignalBindingFeature.VALUE, newValue); | ||
| } | ||
| }); | ||
| if (!valueSetFromSignal && readSignal != null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better if old code is just replaced here so that this new logic is executed inside if (component.isAttached()) { ... } block. Reading signal and consumer from the SignalBindingFeature feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
…ractFieldSupport Move the readSignal and writeCallback fields out of AbstractFieldSupport and into SignalBindingFeature where the signal is already stored. The setValue write-back logic now reads both the signal and callback from the feature using the existing getFeatureIfInitialized pattern, keeping state centralized in one place.
|



Change bindValue(WritableSignal) to bindValue(Signal, SerializableConsumer) so that two-way bindings require an explicit write-back callback. This forces developers to acknowledge when user input is received, providing an additional layer of safety.
The first parameter is a read-only Signal for the signal-to-component direction. The second parameter is the callback for propagating value changes back to the signal. After invoking the callback, the signal is re-consulted via peek() and if the value differs, the component reverts to the signal's value. A null callback creates a read-only binding that throws on setValue while attached.