use of com.vaadin.client.flow.ConstantPool in project flow by vaadin.
the class ServerEventObject method getEventData.
/**
* Collect extra data for element event if any has been sent from the
* server. Note! Data is sent in the array in the same order as defined on
* the server side.
*
* @param event
* The fired Event
* @param methodName
* Method name that is called
* @param node
* Target node
* @return Array of extra event data
*/
private JsonArray getEventData(Event event, String methodName, StateNode node) {
if (node.getMap(NodeFeatures.POLYMER_EVENT_LISTENERS).hasPropertyValue(methodName)) {
JsonArray dataArray = Json.createArray();
ConstantPool constantPool = node.getTree().getRegistry().getConstantPool();
String expressionConstantKey = (String) node.getMap(NodeFeatures.POLYMER_EVENT_LISTENERS).getProperty(methodName).getValue();
JsArray<String> dataExpressions = constantPool.get(expressionConstantKey);
for (int i = 0; i < dataExpressions.length(); i++) {
String expression = dataExpressions.get(i);
dataArray.set(i, getExpressionValue(event, node, expression));
}
return dataArray;
}
return null;
}
use of com.vaadin.client.flow.ConstantPool in project flow by vaadin.
the class SimpleElementBindingStrategy method handleDomEvent.
private void handleDomEvent(Event event, BindingContext context) {
assert context != null;
Node element = context.htmlNode;
StateNode node = context.node;
assert element instanceof Element : "Cannot handle DOM event for a Node";
String type = event.getType();
NodeMap listenerMap = getDomEventListenerMap(node);
ConstantPool constantPool = node.getTree().getRegistry().getConstantPool();
String expressionConstantKey = (String) listenerMap.getProperty(type).getValue();
assert expressionConstantKey != null;
assert constantPool.has(expressionConstantKey);
JsonObject expressionSettings = constantPool.get(expressionConstantKey);
String[] expressions = expressionSettings.keys();
JsonObject eventData;
JsSet<String> synchronizeProperties = JsCollections.set();
if (expressions.length == 0) {
eventData = null;
} else {
eventData = Json.createObject();
}
for (String expressionString : expressions) {
if (expressionString.startsWith(JsonConstants.SYNCHRONIZE_PROPERTY_TOKEN)) {
String property = expressionString.substring(JsonConstants.SYNCHRONIZE_PROPERTY_TOKEN.length());
synchronizeProperties.add(property);
} else if (expressionString.equals(JsonConstants.MAP_STATE_NODE_EVENT_DATA)) {
// map event.target to the closest state node
int targetNodeId = getClosestStateNodeIdToEventTarget(node, event.getTarget());
eventData.put(JsonConstants.MAP_STATE_NODE_EVENT_DATA, targetNodeId);
} else if (expressionString.startsWith(JsonConstants.MAP_STATE_NODE_EVENT_DATA)) {
// map element returned by JS to the closest state node
String jsEvaluation = expressionString.substring(JsonConstants.MAP_STATE_NODE_EVENT_DATA.length());
EventExpression expression = getOrCreateExpression(jsEvaluation);
JsonValue expressionValue = expression.evaluate(event, (Element) element);
// find the closest state node matching the expression value
int targetNodeId = getClosestStateNodeIdToDomNode(node.getTree(), expressionValue, jsEvaluation);
eventData.put(expressionString, targetNodeId);
} else {
EventExpression expression = getOrCreateExpression(expressionString);
JsonValue expressionValue = expression.evaluate(event, (Element) element);
eventData.put(expressionString, expressionValue);
}
}
JsArray<Runnable> commands = JsCollections.array();
synchronizeProperties.forEach(name -> commands.push(getSyncPropertyCommand(name, context)));
Consumer<String> sendCommand = debouncePhase -> {
commands.forEach(Runnable::run);
sendEventToServer(node, type, eventData, debouncePhase);
};
boolean sendNow = resolveFilters(element, type, expressionSettings, eventData, sendCommand);
if (sendNow) {
// Send if there were not filters or at least one matched
sendCommand.accept(null);
}
}
use of com.vaadin.client.flow.ConstantPool in project flow by vaadin.
the class GwtAtmoshperePushConnectionTest method gwtSetUp.
@Override
protected void gwtSetUp() throws Exception {
super.gwtSetUp();
initScheduler(new CustomScheduler());
registry = new Registry() {
{
set(ConstantPool.class, new ConstantPool());
set(StateTree.class, new StateTree(this));
set(URIResolver.class, new URIResolver(this));
set(UILifecycle.class, new UILifecycle());
set(ApplicationConfiguration.class, new ApplicationConfiguration());
set(MessageHandler.class, new MessageHandler(this));
set(PushConfiguration.class, new PushConfiguration(this) {
@Override
public JsMap<String, String> getParameters() {
return JsCollections.map();
}
});
set(ConnectionStateHandler.class, new DefaultConnectionStateHandler(this));
}
};
}
Aggregations