use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testUnregister_sttributeBindingUpdateIsNotDone.
public void testUnregister_sttributeBindingUpdateIsNotDone() {
TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
templateNode.addAttribute("attr", TestBinding.createBinding(ModelValueBindingProvider.TYPE, MODEL_KEY));
NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
map.getProperty(MODEL_KEY).setValue("foo");
Element domNode = createElement(templateNode);
assertEquals(null, domNode.getAttribute("attr"));
stateNode.unregister();
Reactive.flush();
assertEquals(null, domNode.getAttribute("attr"));
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testTextNoValueTemplate.
public void testTextNoValueTemplate() {
TestTextTemplate templateNode = TestTextTemplate.create(TestBinding.createTextValueBinding(MODEL_KEY));
Node domNode = createText(templateNode);
NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
map.getProperty(MODEL_KEY).setValue(null);
Reactive.flush();
assertEquals("", domNode.getTextContent());
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testTemplateAttributes_bindOverrideNodeAttribute.
public void testTemplateAttributes_bindOverrideNodeAttribute() {
TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
templateNode.addAttribute("attr1", "value1");
templateNode.addAttribute("attr2", "value2");
int id = 37;
StateNode overrideNode = createSimpleOverrideNode(id);
Element element = createElement(templateNode, id);
NodeMap props = overrideNode.getMap(NodeFeatures.ELEMENT_ATTRIBUTES);
props.getProperty("attr2").setValue("foo");
Reactive.flush();
assertEquals("value1", element.getAttribute("attr1"));
assertEquals("foo", element.getAttribute("attr2"));
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testUnregister_propeprtyBindingUpdateIsNotDone.
public void testUnregister_propeprtyBindingUpdateIsNotDone() {
TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
templateNode.addProperty("prop", TestBinding.createBinding(ModelValueBindingProvider.TYPE, MODEL_KEY));
NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
map.getProperty(MODEL_KEY).setValue("foo");
Node domNode = createElement(templateNode);
assertEquals(null, WidgetUtil.getJsProperty(domNode, "prop"));
stateNode.unregister();
Reactive.flush();
assertEquals(null, WidgetUtil.getJsProperty(domNode, "prop"));
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class AbstractTemplateStrategy method getModelBindingValue.
/**
* Gets the value from the {@code node} for the {@code binding}.
*
* @param node
* the state node, not {@code null}
* @param binding
* binding data, not {@code null}
* @return map binding value, or an empty optional if no value for the
* binding
*/
private static Optional<Object> getModelBindingValue(StateNode node, Binding binding) {
NodeMap model = node.getMap(NodeFeatures.TEMPLATE_MODELMAP);
String key = binding.getValue();
assert key != null;
if (!node.hasFeature(NodeFeatures.TEMPLATE)) {
/*
* This is temporary legacy logic to support *ngFor bindings. JS
* evaluation should be used in any case. But at the moment JS
* evaluation doesn't work with *ngFor bindings so they are handled
* here.
*
* TODO: remove this and update JS evaluation to support *ngFor.
*/
String[] modelPathParts = key.split("\\.");
// The last part is the propertyName
for (int i = 0; i < modelPathParts.length - 1; i++) {
StateNode n = (StateNode) model.getProperty(modelPathParts[i]).getValue();
model = n.getMap(NodeFeatures.TEMPLATE_MODELMAP);
}
key = modelPathParts[modelPathParts.length - 1];
return Optional.ofNullable(model.getProperty(key).getValue());
} else {
String expression = key;
String modelDescriptorId = (String) node.getMap(NodeFeatures.TEMPLATE).getProperty(NodeProperties.MODEL_DESCRIPTOR).getValue();
assert modelDescriptorId != null;
JsonObject modelDescriptor = node.getTree().getRegistry().getConstantPool().get(modelDescriptorId);
NativeFunction function = new NativeFunction("model", "with(model) { return " + expression + "}");
BeanModelType type = new BeanModelType(modelDescriptor);
Object proxy = type.createProxy(model);
return Optional.ofNullable(function.call(null, proxy));
}
}
Aggregations