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);
}
});
}
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));
}
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);
}
}
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);
}
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);
}
Aggregations