use of com.vaadin.client.flow.reactive.Computation in project flow by vaadin.
the class TextBindingStrategy method bind.
@Override
public void bind(StateNode stateNode, Text htmlNode, BinderContext nodeFactory) {
assert stateNode.hasFeature(NodeFeatures.TEXT_NODE);
if (BOUND.has(stateNode)) {
return;
}
BOUND.set(stateNode, true);
NodeMap textMap = stateNode.getMap(NodeFeatures.TEXT_NODE);
MapProperty textProperty = textMap.getProperty(NodeProperties.TEXT);
Computation computation = Reactive.runWhenDependenciesChange(() -> htmlNode.setData((String) textProperty.getValue()));
stateNode.addUnregisterListener(e -> unbind(stateNode, computation));
}
use of com.vaadin.client.flow.reactive.Computation in project flow by vaadin.
the class AbstractTemplateStrategy method bind.
/**
* Binds the {@code modelNode} using the given {@code binding} and
* {@code executor} to set the {@code binding} data to the node.
*
* @param modelNode
* the state node containing model data, not {@code null}
* @param binding
* binding data to set, not {@code null}
* @param executor
* the operation to set the binding data to the node
*/
protected void bind(StateNode modelNode, Binding binding, Consumer<Optional<Object>> executor) {
if (ModelValueBindingProvider.TYPE.equals(binding.getType())) {
Computation computation = Reactive.runWhenDependenciesChange(() -> executor.accept(getModelBindingValue(modelNode, binding)));
modelNode.addUnregisterListener(event -> computation.stop());
} else {
// Only static bindings is known as a final call
assert binding.getType().equals(StaticBindingValueProvider.TYPE);
executor.accept(Optional.of(getStaticBindingValue(binding)));
}
}
use of com.vaadin.client.flow.reactive.Computation in project flow by vaadin.
the class ForTemplateBindingStrategy method bind.
@Override
protected void bind(StateNode modelNode, Node anchor, int templateId, TemplateBinderContext context) {
ForTemplateNode templateNode = (ForTemplateNode) getTemplateNode(modelNode.getTree(), templateId);
Computation computation = Reactive.runWhenDependenciesChange(new ForTemplateNodeUpdate(context, anchor, modelNode, templateNode));
modelNode.addUnregisterListener(event -> computation.stop());
}
Aggregations