use of com.vaadin.flow.internal.StateTree in project flow by vaadin.
the class JsonCodecTest method encodeWithTypeInfo_attachedElement.
@Test
public void encodeWithTypeInfo_attachedElement() {
Element element = ElementFactory.createDiv();
StateTree tree = new StateTree(new UI(), ElementChildrenList.class);
tree.getRootNode().getFeature(ElementChildrenList.class).add(0, element.getNode());
JsonValue json = JsonCodec.encodeWithTypeInfo(element);
assertJsonEquals(JsonUtils.createArray(Json.create(JsonCodec.NODE_TYPE), Json.create(element.getNode().getId())), json);
}
use of com.vaadin.flow.internal.StateTree in project flow by vaadin.
the class NodeMapTest method put_sameValue_hasNoEffect.
@Test
public void put_sameValue_hasNoEffect() {
StateTree tree = new StateTree(new UI(), ElementChildrenList.class);
StateNode child = new StateNode();
AtomicBoolean listenerIsCalled = new AtomicBoolean();
child.addAttachListener(() -> {
Assert.assertFalse(listenerIsCalled.get());
listenerIsCalled.set(true);
});
nodeMap.put("foo", child);
tree.getRootNode().getFeature(ElementChildrenList.class).add(child.getParent());
Assert.assertTrue(listenerIsCalled.get());
// The attach listener is not called one more time
nodeMap.put("foo", child);
}
use of com.vaadin.flow.internal.StateTree in project flow by vaadin.
the class RouterLink method getRouter.
private RouterInterface getRouter() {
Optional<RouterInterface> router = Optional.empty();
if (getElement().getNode().isAttached()) {
StateTree tree = (StateTree) getElement().getNode().getOwner();
router = tree.getUI().getRouterInterface();
if (!router.isPresent()) {
throw new IllegalArgumentException("RouterLink cannot be used if Router is not used");
}
}
if (!router.isPresent()) {
router = Optional.ofNullable(VaadinService.getCurrent()).map(VaadinService::getRouter);
}
if (!router.isPresent()) {
throw new IllegalStateException("Implicit router instance is not available. " + "Use overloaded method with explicit router parameter.");
}
return router.get();
}
Aggregations