Package com.vaadin.flow.signals.function
Interface ValueMerger<O extends @Nullable Object,I extends @Nullable Object>
- 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.
@FunctionalInterface
public interface ValueMerger<O extends @Nullable Object,I extends @Nullable Object>
extends Serializable
Creates a new outer value by merging a new inner value with the old outer
value. Used with the
ValueSignal.updater(ValueMerger) helper method
to create write callbacks for immutable value patterns.
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 task, boolean done) {
Todo withTask(String task) {
return new Todo(task, this.done);
}
Todo withDone(boolean done) {
return new Todo(this.task, done);
}
}
ValueSignal<Todo> todoSignal = new ValueSignal<>(
new Todo("Buy groceries", false));
textField.bindValue(todoSignal.map(Todo::task),
todoSignal.updater(Todo::withTask));
checkbox.bindValue(todoSignal.map(Todo::done),
todoSignal.updater(Todo::withDone));
- 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 valuenewInnerValue- the new inner value to merge- Returns:
- the new outer value
-