Search in sources :

Example 11 with StateTree

use of com.vaadin.client.flow.StateTree 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));
        }
    };
}
Also used : StateTree(com.vaadin.client.flow.StateTree) ConstantPool(com.vaadin.client.flow.ConstantPool) URIResolver(com.vaadin.client.URIResolver) CustomScheduler(com.vaadin.client.CustomScheduler) Registry(com.vaadin.client.Registry) UILifecycle(com.vaadin.client.UILifecycle) ApplicationConfiguration(com.vaadin.client.ApplicationConfiguration)

Example 12 with StateTree

use of com.vaadin.client.flow.StateTree 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;
}
Also used : StateTree(com.vaadin.client.flow.StateTree) StateNode(com.vaadin.client.flow.StateNode)

Aggregations

StateTree (com.vaadin.client.flow.StateTree)12 StateNode (com.vaadin.client.flow.StateNode)8 Test (org.junit.Test)4 JsonArray (elemental.json.JsonArray)3 Registry (com.vaadin.client.Registry)2 ConstantPool (com.vaadin.client.flow.ConstantPool)2 JsElement (elemental.js.dom.JsElement)2 JsonObject (elemental.json.JsonObject)2 ApplicationConfiguration (com.vaadin.client.ApplicationConfiguration)1 CustomScheduler (com.vaadin.client.CustomScheduler)1 ExistingElementMap (com.vaadin.client.ExistingElementMap)1 InitialPropertiesHandler (com.vaadin.client.InitialPropertiesHandler)1 UILifecycle (com.vaadin.client.UILifecycle)1 URIResolver (com.vaadin.client.URIResolver)1 ServerConnector (com.vaadin.client.communication.ServerConnector)1 ExecuteJavaScriptProcessor (com.vaadin.client.flow.ExecuteJavaScriptProcessor)1 JsArray (com.vaadin.client.flow.collection.JsArray)1 Node (elemental.dom.Node)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1