Search in sources :

Example 41 with StateNode

use of com.vaadin.client.flow.StateNode in project flow by vaadin.

the class GwtTemplateBinderTest method testBindOverrideNode_properties_beforeBind.

public void testBindOverrideNode_properties_beforeBind() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    int id = 83;
    StateNode overrideNode = createSimpleOverrideNode(id);
    NodeMap props = overrideNode.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    props.getProperty("foo").setValue("bar");
    Element element = createElement(templateNode, id);
    Reactive.flush();
    assertEquals("bar", WidgetUtil.getJsProperty(element, "foo"));
}
Also used : Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 42 with StateNode

use of com.vaadin.client.flow.StateNode in project flow by vaadin.

the class GwtTemplateBinderTest method testUnregisterOverrideNode.

public void testUnregisterOverrideNode() {
    int id = 83;
    StateNode overrideNode = createSimpleOverrideNode(id, 2);
    // Must register so that we can fire an unregister event later on
    tree.registerNode(stateNode);
    tree.registerNode(overrideNode);
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    MapProperty idProperty = overrideNode.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("id");
    idProperty.setValue("override");
    Element element = createElement(templateNode, id);
    Reactive.flush();
    tree.unregisterNode(stateNode);
    tree.unregisterNode(overrideNode);
    Reactive.flush();
    // Updating override node after unregistering the nodes should not
    // cause the element to update
    idProperty.setValue("new");
    Reactive.flush();
    assertEquals("override", element.getId());
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode)

Example 43 with StateNode

use of com.vaadin.client.flow.StateNode in project flow by vaadin.

the class GwtTemplateBinderTest method createSimpleOverrideNode.

private StateNode createSimpleOverrideNode(int mainNodeTemplateId, int overrideNodeId) {
    StateNode overrideNode = new StateNode(overrideNodeId, tree);
    // make it recognizable as an override element
    overrideNode.getMap(NodeFeatures.OVERRIDE_DATA);
    stateNode.getMap(NodeFeatures.TEMPLATE_OVERRIDES).getProperty(String.valueOf(mainNodeTemplateId)).setValue(overrideNode);
    return overrideNode;
}
Also used : StateNode(com.vaadin.client.flow.StateNode)

Example 44 with StateNode

use of com.vaadin.client.flow.StateNode in project flow by vaadin.

the class GwtTemplateBinderTest method testBindOverrideNode_attributes_beforeBind.

public void testBindOverrideNode_attributes_beforeBind() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    int id = 48;
    StateNode overrideNode = createSimpleOverrideNode(id);
    NodeMap attrs = overrideNode.getMap(NodeFeatures.ELEMENT_ATTRIBUTES);
    attrs.getProperty("foo").setValue("bar");
    Element element = createElement(templateNode, id);
    Reactive.flush();
    assertEquals("bar", element.getAttribute("foo"));
}
Also used : Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 45 with StateNode

use of com.vaadin.client.flow.StateNode in project flow by vaadin.

the class GwtTemplateBinderTest method testChildSlotAfterUnregister.

public void testChildSlotAfterUnregister() {
    StateNode childContentNode = new StateNode(79, stateNode.getTree());
    // Must register so that we can fire an unregister event later on
    tree.registerNode(stateNode);
    tree.registerNode(childContentNode);
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    TestTemplateNode childSlot = TestTemplateNode.create(ChildSlotNode.TYPE);
    int childId = 67;
    registry.getTemplateRegistry().register(childId, childSlot);
    templateNode.setChildrenIds(new double[] { childId });
    childContentNode.getMap(NodeFeatures.ELEMENT_DATA).getProperty(NodeProperties.TAG).setValue("span");
    stateNode.getMap(NodeFeatures.TEMPLATE).getProperty(TemplateMap.CHILD_SLOT_CONTENT).setValue(childContentNode);
    Reactive.flush();
    Element element = createElement(templateNode);
    assertEquals(1, element.getChildNodes().getLength());
    tree.unregisterNode(stateNode);
    tree.unregisterNode(childContentNode);
    Reactive.flush();
    stateNode.getMap(NodeFeatures.TEMPLATE).getProperty(TemplateMap.CHILD_SLOT_CONTENT).setValue(null);
    Reactive.flush();
    // Emptying child slot should have not effect when node is unregistered
    assertEquals(1, element.getChildNodes().getLength());
}
Also used : Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode)

Aggregations

StateNode (com.vaadin.client.flow.StateNode)73 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)21 Element (elemental.dom.Element)21 Test (org.junit.Test)16 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)14 Node (elemental.dom.Node)13 JsonObject (elemental.json.JsonObject)11 StateTree (com.vaadin.client.flow.StateTree)9 DomNode (com.vaadin.client.flow.dom.DomNode)9 NodeList (com.vaadin.client.flow.nodefeature.NodeList)7 JsonValue (elemental.json.JsonValue)5 ExistingElementMap (com.vaadin.client.ExistingElementMap)4 JsArray (com.vaadin.client.flow.collection.JsArray)4 NativeFunction (com.vaadin.client.flow.util.NativeFunction)4 JsonArray (elemental.json.JsonArray)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 Command (com.vaadin.client.Command)2 InitialPropertiesHandler (com.vaadin.client.InitialPropertiesHandler)2