Search in sources :

Example 1 with Computation

use of com.vaadin.client.flow.reactive.Computation in project flow by vaadin.

the class SimpleElementBindingStrategy method bindEventHandlerProperty.

private void bindEventHandlerProperty(MapProperty eventHandlerProperty, BindingContext context) {
    String name = eventHandlerProperty.getName();
    assert !context.listenerBindings.has(name);
    Computation computation = Reactive.runWhenDependenciesChange(() -> {
        boolean hasValue = eventHandlerProperty.hasValue();
        boolean hasListener = context.listenerRemovers.has(name);
        if (hasValue != hasListener) {
            if (hasValue) {
                addEventHandler(name, context);
            } else {
                removeEventHandler(name, context);
            }
        }
    });
    context.listenerBindings.set(name, computation);
}
Also used : Computation(com.vaadin.client.flow.reactive.Computation)

Example 2 with Computation

use of com.vaadin.client.flow.reactive.Computation in project flow by vaadin.

the class ChildSlotBindingStrategy method bind.

@Override
protected void bind(StateNode modelNode, Node anchor, int templateId, TemplateBinderContext context) {
    Computation computation = Reactive.runWhenDependenciesChange(new ChildSlotBinder(context, anchor, modelNode));
    modelNode.addUnregisterListener(e -> computation.stop());
}
Also used : Computation(com.vaadin.client.flow.reactive.Computation)

Example 3 with Computation

use of com.vaadin.client.flow.reactive.Computation in project flow by vaadin.

the class SimpleElementBindingStrategy method bindProperty.

private static void bindProperty(PropertyUser user, MapProperty property, JsMap<String, Computation> bindings) {
    String name = property.getName();
    assert !bindings.has(name) : "There's already a binding for " + name;
    Computation computation = Reactive.runWhenDependenciesChange(() -> user.use(property));
    bindings.set(name, computation);
}
Also used : Computation(com.vaadin.client.flow.reactive.Computation)

Example 4 with Computation

use of com.vaadin.client.flow.reactive.Computation in project flow by vaadin.

the class SimpleElementBindingStrategy method invokeWhenNodeIsConstructed.

private void invokeWhenNodeIsConstructed(Command command, StateNode node) {
    Computation computation = Reactive.runWhenDependenciesChange(command);
    node.addUnregisterListener(event -> computation.stop());
}
Also used : Computation(com.vaadin.client.flow.reactive.Computation)

Example 5 with Computation

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));
}
Also used : Computation(com.vaadin.client.flow.reactive.Computation) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Aggregations

Computation (com.vaadin.client.flow.reactive.Computation)7 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)1 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)1