feat: SignalInput — read a server-side Signal at trigger fire time#24428
feat: SignalInput — read a server-side Signal at trigger fire time#24428Artur- wants to merge 1 commit into
Conversation
| ui.getElement().appendChild(owner.getElement()); | ||
|
|
||
| ValueSignal<String> signal = new ValueSignal<>("first"); | ||
| new SignalInput<>(owner, signal); |
There was a problem hiding this comment.
It bothers a bit that constructor call generates effect and its initialization also calls executeJs that sets the property value.. and all that just by creating SignalInput object. Feels a bit too early, what if input is not even used.
Maybe this could be postponed to triggers(...) calls instead, meaning it could be moved to appendExpression method? Or new optional lifecycle method called initExpression.
Technically signal could be stored to SignalBindingFeature to bound it for garbage collection of the owner element with:
owner.getElement().getNode().getFeature(SignalBindingFeature.class)
.setBinding(propertyName, signal);and read with:
Signal<T> signal = owner.getElement().getNode().getFeature(SignalBindingFeature.class)
.getSignal(propertyName);where owner would go to new private field.
Benefits:
- signal effect and its initialization runs on
trigger(...)instead where inputs are actually used. SignalInputis similar as other inputs. Like a pojo without a trigger usage.
There was a problem hiding this comment.
Moved to appendExpression
| */ | ||
| public class SignalInput<T> extends Action.Input<T> { | ||
|
|
||
| private static final AtomicLong PROPERTY_INDEX = new AtomicLong(); |
There was a problem hiding this comment.
Add a comment explaining why the counter never resets. Long is probably "long" enough, but without any comment confirming that, it makes one wonder if some session-per-request scenario, or devmode hotdeploy could explode it. And in that case UUID could work nicer.
Adds SignalInput<T>(Component owner, Signal<T> signal) under com.vaadin.flow.component.trigger.internal. A component-scoped Signal.effect mirrors the signal value to a uniquely-named JS property on the owner element via executeJs; the input's rendered expression reads that property at fire time, so actions such as CopyTextToClipboardAction can use a server-side signal as their value source without first projecting it onto a DOM property. Includes unit tests covering the rendered expression, push-on-change, and per-input property naming, plus an IT that copies a ValueSignal, mutates it from a separate button, and verifies the next copy sees the updated value.
4b4b5df to
5f2d8be
Compare
|



Adds SignalInput(Component owner, Signal signal) under com.vaadin.flow.component.trigger.internal. A component-scoped Signal.effect mirrors the signal value to a uniquely-named JS property on the owner element via executeJs; the input's rendered expression reads that property at fire time, so actions such as CopyTextToClipboardAction can use a server-side signal as their value source without first projecting it onto a DOM property.
Includes unit tests covering the rendered expression, push-on-change, and per-input property naming, plus an IT that copies a ValueSignal, mutates it from a separate button, and verifies the next copy sees the updated value.