use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class SimpleElementBindingStrategy method handleListItemPropertyChange.
private static void handleListItemPropertyChange(double nodeId, Element host, String property, Object value, StateTree tree) {
// Warning : it's important that <code>tree</code> is passed as an
// argument instead of StateNode or Element ! We have replaced a method
// in the prototype which means that it may not use the context from the
// hookUpPolymerElement method. Only a tree may be use as a context
// since StateTree is a singleton.
StateNode node = tree.getNode((int) nodeId);
if (!node.hasFeature(NodeFeatures.ELEMENT_PROPERTIES)) {
return;
}
assert checkParent(node, host) : "Host element is not a parent of the node whose property has changed. " + "This is an implementation error. " + "Most likely it means that there are several StateTrees on the same page " + "(might be possible with portlets) and the target StateTree should not be passed " + "into the method as an argument but somehow detected from the host element. " + "Another option is that host element is calculated incorrectly.";
// TODO: this code doesn't care about "security feature" which prevents
// sending
// data from the client side to the server side if property is not
// "updatable". See <code>handlePropertyChange</code> and
// UpdatableModelProperties.
// It should be aware of that. The current issue is that we don't know
// the full property path (dot separated) to the property which is a
// property for the <code>host</code> StateNode and not
// for the <code>node</code> below. It's tricky to calculate FQN
// property name at this point though the <code>host</code> element
// which is
// the template element could be used for that: a StateNode of
// <code>host</code> is an ancestor of the <code>node</code> and it
// should be possible to calculate FQN using this info. Also at the
// moment
// AllowClientUpdates ignores bean properties in
// lists ( if "list" is a property name of list type property and
// "name" is a property of a bean then
// "list.name" is not in the UpdatableModelProperties ).
NodeMap map = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
MapProperty mapProperty = map.getProperty(property);
mapProperty.syncToServer(value);
}
use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class GwtExecuteJavaScriptElementUtilsTest method testAttachExistingElement_elementHasServersideCounterpart.
public void testAttachExistingElement_elementHasServersideCounterpart() {
Element child1 = addChildElement("span");
StateNode childNode = addChild(child1, 0);
addChildElement("button");
ExecuteJavaScriptElementUtils.attachExistingElement(node, null, "span", requestedId);
assertRpcToServerArguments(childNode.getId(), child1.getTagName(), 0);
}
use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class MapProperty method getSyncToServerCommand.
/**
* Sets the value of this property and returns a synch to server command.
*
* @param newValue
* the new value to set.
* @see #syncToServer(Object)
*/
public Runnable getSyncToServerCommand(Object newValue) {
Object currentValue = hasValue() ? getValue() : null;
if (Objects.equals(newValue, currentValue)) {
// in case we are here with the same value that has been set from
// the server then we unlock client side updates already here via
// unmarking the server update flag. It allows another client side
// potential change for the same property being propagated to the
// server once the server value is set successfully (e.g. mutation
// the same property from its observer).
isServerUpdate = false;
}
if (!(Objects.equals(newValue, currentValue) && hasValue()) && !isServerUpdate) {
StateNode node = getMap().getNode();
StateTree tree = node.getTree();
if (tree.isActive(node)) {
doSetValue(newValue);
return () -> tree.sendNodePropertySyncToServer(this);
} else {
/*
* Fire an fake event to reset the property value back in the
* DOM element: we don't know how exactly set this property but
* it has to be set to the property value because of listener
* added to the property during binding.
*/
eventRouter.fireEvent(new MapPropertyChangeEvent(this, currentValue, currentValue));
// Flush is needed because we are out of normal lifecycle which
// call the flush() automatically.
Reactive.flush();
}
}
return NO_OP;
}
Aggregations