Package com.vaadin.flow.signals.function
Interface ValueMerger<O,I>
- Type Parameters:
O- the outer (parent) signal value typeI- the inner (mapped) signal value type
- All Superinterfaces:
Serializable
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Creates a new outer value by merging a new inner value with the old outer
value. Used for creating two-way computed signals where changes to the mapped
signal propagate back to the parent signal.
This interface is used with immutable value patterns where changing the inner value requires creating a new outer value instance.
Example usage with a record:
record Todo(String text, boolean done) {
Todo withDone(boolean done) {
return new Todo(this.text, done);
}
}
WritableSignal<Todo> todoSignal = new ValueSignal<>(
new Todo("Buy milk", false));
WritableSignal<Boolean> doneSignal = todoSignal.map(Todo::done,
Todo::withDone);
doneSignal.set(true); // Updates todoSignal to Todo("Buy milk", true)
- See Also:
-
Method Summary
-
Method Details
-
merge
Creates a new outer value by merging the new inner value with the old outer value.- Parameters:
outerValue- the current outer signal value, may benullnewInnerValue- the new inner value to merge, may benull- Returns:
- the new outer value, may be
null
-