use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class PolymerUtils method registerChangeHandlers.
private static void registerChangeHandlers(StateNode node, NodeFeature feature, JsonValue value) {
JsArray<EventRemover> registrations = JsCollections.array();
if (node.hasFeature(NodeFeatures.ELEMENT_PROPERTIES)) {
assert feature instanceof NodeMap : "Received an inconsistent NodeFeature for a node that has a ELEMENT_PROPERTIES feature. It should be NodeMap, but it is: " + feature;
NodeMap map = (NodeMap) feature;
registerPropertyChangeHandlers(value, registrations, map);
registerPropertyAddHandler(value, registrations, map);
} else if (node.hasFeature(NodeFeatures.TEMPLATE_MODELLIST)) {
assert feature instanceof NodeList : "Received an inconsistent NodeFeature for a node that has a TEMPLATE_MODELLIST feature. It should be NodeList, but it is: " + feature;
NodeList list = (NodeList) feature;
registrations.push(list.addSpliceListener(event -> handleListChange(event, value)));
}
assert !registrations.isEmpty() : "Node should have ELEMENT_PROPERTIES or TEMPLATE_MODELLIST feature";
registrations.push(node.addUnregisterListener(event -> registrations.forEach(EventRemover::remove)));
}
use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class PushConfiguration method getParameters.
/**
* Gets all configured push parameters.
*
* The parameters configured on the server, including transports.
*
* @return a map of all parameters configured on the server
*/
public JsMap<String, String> getParameters() {
MapProperty p = getConfigurationMap().getProperty(PushConfigurationMap.PARAMETERS_KEY);
StateNode parametersNode = (StateNode) p.getValue();
NodeMap parametersMap = parametersNode.getMap(NodeFeatures.UI_PUSHCONFIGURATION_PARAMETERS);
JsMap<String, String> parameters = JsCollections.map();
parametersMap.forEachProperty((property, key) -> {
parameters.set(key, (String) property.getValue());
});
return parameters;
}
use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class MessageHandler method processChanges.
private void processChanges(JsonObject json) {
StateTree tree = registry.getStateTree();
JsSet<StateNode> updatedNodes = TreeChangeProcessor.processChanges(tree, json.getArray("changes"));
if (!registry.getApplicationConfiguration().isProductionMode()) {
try {
JsonObject debugJson = tree.getRootNode().getDebugJson();
Console.log("StateTree after applying changes:");
Console.log(debugJson);
} catch (Exception e) {
Console.error("Failed to log state tree");
Console.error(e);
}
}
Reactive.addPostFlushListener(() -> Scheduler.get().scheduleDeferred(() -> updatedNodes.forEach(this::afterServerUpdates)));
}
use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class InitialPropertiesHandlerTest method flushPropertyUpdates_updateIsNotInProgress_flushForEechProperty.
@Test
public void flushPropertyUpdates_updateIsNotInProgress_flushForEechProperty() {
Mockito.when(tree.isUpdateInProgress()).thenReturn(false);
StateNode node = new StateNode(1, tree);
NodeMap properties = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
MapProperty property1 = properties.getProperty("foo");
property1.setValue("bar");
MapProperty property2 = properties.getProperty("other");
property2.setValue("value");
handler.nodeRegistered(node);
Mockito.when(tree.getNode(node.getId())).thenReturn(node);
handler.flushPropertyUpdates();
property1.setValue("baz");
property2.setValue("foo");
handler.handlePropertyUpdate(property1);
handler.handlePropertyUpdate(property2);
AtomicInteger count = new AtomicInteger();
FlushListener listener = () -> count.incrementAndGet();
property1.addChangeListener(event -> Reactive.addFlushListener(listener));
property2.addChangeListener(event -> Reactive.addFlushListener(listener));
Reactive.flush();
Assert.assertEquals(2, count.get());
}
use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class ClientJsonCodecTest method decodeWithTypeInfo_element.
@Test
public void decodeWithTypeInfo_element() {
StateTree tree = new StateTree(null);
StateNode node = new StateNode(42, tree);
tree.registerNode(node);
JsElement element = new JsElement() {
};
node.setDomNode(element);
JsonArray json = JsonUtils.createArray(Json.create(JsonCodec.NODE_TYPE), Json.create(node.getId()));
Object decoded = ClientJsonCodec.decodeWithTypeInfo(tree, json);
Assert.assertSame(element, decoded);
}
Aggregations