Search in sources :

Example 1 with NodeList

use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.

the class ServerEventHandlerBinder method bindServerEventHandlerNames.

/**
 * Registers all the server event handler names found in the feature with
 * the {@code featureId} in the {@link ServerEventObject} {@code object}.
 * Additionally listens to changes in the feature and updates server event
 * object accordingly.
 *
 * @param objectProvider
 *            the provider of the event object to update
 * @param node
 *            the state node containing the feature
 * @param featureId
 *            the feature id which contains event handler methods
 * @return a handle which can be used to remove the listener for the feature
 */
public static EventRemover bindServerEventHandlerNames(Supplier<ServerEventObject> objectProvider, StateNode node, int featureId) {
    NodeList serverEventHandlerNamesList = node.getList(featureId);
    if (serverEventHandlerNamesList.length() > 0) {
        ServerEventObject object = objectProvider.get();
        for (int i = 0; i < serverEventHandlerNamesList.length(); i++) {
            String serverEventHandlerName = (String) serverEventHandlerNamesList.get(i);
            object.defineMethod(serverEventHandlerName, node);
        }
    }
    return serverEventHandlerNamesList.addSpliceListener(e -> {
        ServerEventObject serverObject = objectProvider.get();
        JsArray<?> remove = e.getRemove();
        for (int i = 0; i < remove.length(); i++) {
            serverObject.removeMethod((String) remove.get(i));
        }
        JsArray<?> add = e.getAdd();
        for (int i = 0; i < add.length(); i++) {
            serverObject.defineMethod((String) add.get(i), node);
        }
    });
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList)

Example 2 with NodeList

use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.

the class SimpleElementBindingStrategy method bindSynchronizedPropertyEvents.

private EventRemover bindSynchronizedPropertyEvents(BindingContext context) {
    synchronizeEventTypesChanged(context);
    NodeList propertyEvents = context.node.getList(NodeFeatures.SYNCHRONIZED_PROPERTY_EVENTS);
    return propertyEvents.addSpliceListener(e -> synchronizeEventTypesChanged(context));
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList)

Example 3 with NodeList

use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.

the class SimpleElementBindingStrategy method synchronizeEventTypesChanged.

private void synchronizeEventTypesChanged(BindingContext context) {
    NodeList propertyEvents = context.node.getList(NodeFeatures.SYNCHRONIZED_PROPERTY_EVENTS);
    // Remove all old listeners and add new ones
    context.synchronizedPropertyEventListeners.forEach(EventRemover::remove);
    context.synchronizedPropertyEventListeners.clear();
    for (int i = 0; i < propertyEvents.length(); i++) {
        String eventType = propertyEvents.get(i).toString();
        EventRemover remover = context.htmlNode.addEventListener(eventType, event -> handlePropertySyncDomEvent(context), false);
        context.synchronizedPropertyEventListeners.add(remover);
    }
}
Also used : EventRemover(elemental.events.EventRemover) NodeList(com.vaadin.client.flow.nodefeature.NodeList)

Example 4 with NodeList

use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.

the class GwtMultipleBindingTest method testSynchronizedPropertyDoubleBind.

public void testSynchronizedPropertyDoubleBind() {
    NodeList synchronizedPropertyList = node.getList(NodeFeatures.SYNCHRONIZED_PROPERTIES);
    NodeList synchronizedPropertyEventsList = node.getList(NodeFeatures.SYNCHRONIZED_PROPERTY_EVENTS);
    Binder.bind(node, element);
    synchronizedPropertyEventsList.add(0, "event");
    synchronizedPropertyList.add(0, "tagName");
    Reactive.flush();
    node.setBound();
    Binder.bind(node, element);
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList)

Example 5 with NodeList

use of com.vaadin.client.flow.nodefeature.NodeList in project flow by vaadin.

the class GwtMultipleBindingTest method testAddChildDoubleBind.

public void testAddChildDoubleBind() {
    Binder.bind(node, element);
    NodeList children = node.getList(NodeFeatures.ELEMENT_CHILDREN);
    children.add(0, createChild(1));
    Reactive.flush();
    node.setBound();
    Binder.bind(node, element);
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList)

Aggregations

NodeList (com.vaadin.client.flow.nodefeature.NodeList)25 JsonObject (elemental.json.JsonObject)9 StateNode (com.vaadin.client.flow.StateNode)7 Node (elemental.dom.Node)5 ExistingElementMap (com.vaadin.client.ExistingElementMap)3 DomNode (com.vaadin.client.flow.dom.DomNode)3 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)3 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)3 Element (elemental.dom.Element)3 JsonArray (elemental.json.JsonArray)3 Test (org.junit.Test)3 JsArray (com.vaadin.client.flow.collection.JsArray)2 EventRemover (elemental.events.EventRemover)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 JsCollections (com.vaadin.client.flow.collection.JsCollections)1 JsMap (com.vaadin.client.flow.collection.JsMap)1 JsSet (com.vaadin.client.flow.collection.JsSet)1 JsWeakMap (com.vaadin.client.flow.collection.JsWeakMap)1 DomApi (com.vaadin.client.flow.dom.DomApi)1 DomTokenList (com.vaadin.client.flow.dom.DomElement.DomTokenList)1