use of com.vaadin.flow.component.internal.UIInternals in project flow by vaadin.
the class ComponentTest method usesChain.
@Test
public void usesChain() {
UIInternals internals = new UI().getInternals();
internals.addComponentDependencies(UsesUsesComponentWithDependencies.class);
Map<String, Dependency> pendingDependencies = getDependenciesMap(internals.getDependencyList().getPendingSendToClient());
Assert.assertEquals(5, pendingDependencies.size());
assertDependency(Dependency.Type.HTML_IMPORT, "usesuses.html", pendingDependencies);
assertDependency(Dependency.Type.HTML_IMPORT, "html.html", pendingDependencies);
assertDependency(Dependency.Type.JAVASCRIPT, "uses.js", pendingDependencies);
assertDependency(Dependency.Type.JAVASCRIPT, "js.js", pendingDependencies);
assertDependency(Dependency.Type.STYLESHEET, "css.css", pendingDependencies);
}
use of com.vaadin.flow.component.internal.UIInternals in project flow by vaadin.
the class ComponentTest method circularDependencies.
@Test
public void circularDependencies() {
UIInternals internals = new UI().getInternals();
DependencyList dependencyList = internals.getDependencyList();
internals.addComponentDependencies(CircularDependencies1.class);
Map<String, Dependency> pendingDependencies = getDependenciesMap(dependencyList.getPendingSendToClient());
Assert.assertEquals(2, pendingDependencies.size());
assertDependency(Dependency.Type.JAVASCRIPT, "dep1.js", pendingDependencies);
assertDependency(Dependency.Type.JAVASCRIPT, "dep2.js", pendingDependencies);
internals = new UI().getInternals();
dependencyList = internals.getDependencyList();
internals.addComponentDependencies(CircularDependencies2.class);
pendingDependencies = getDependenciesMap(dependencyList.getPendingSendToClient());
Assert.assertEquals(2, pendingDependencies.size());
assertDependency(Dependency.Type.JAVASCRIPT, "dep2.js", pendingDependencies);
assertDependency(Dependency.Type.JAVASCRIPT, "dep1.js", pendingDependencies);
}
use of com.vaadin.flow.component.internal.UIInternals in project flow by vaadin.
the class UidlWriter method createUidl.
/**
* Creates a JSON object containing all pending changes to the given UI.
*
* @param ui
* The {@link UI} whose changes to write
* @param async
* True if this message is sent by the server asynchronously,
* false if it is a response to a client message.
* @return JSON object containing the UIDL response
*/
public JsonObject createUidl(UI ui, boolean async) {
JsonObject response = Json.createObject();
UIInternals uiInternals = ui.getInternals();
VaadinSession session = ui.getSession();
VaadinService service = session.getService();
// Purge pending access calls as they might produce additional changes
// to write out
service.runPendingAccessTasks(session);
// Paints components
getLogger().debug("* Creating response to client");
int syncId = service.getDeploymentConfiguration().isSyncIdCheckEnabled() ? uiInternals.getServerSyncId() : -1;
response.put(ApplicationConstants.SERVER_SYNC_ID, syncId);
int nextClientToServerMessageId = uiInternals.getLastProcessedClientToServerId() + 1;
response.put(ApplicationConstants.CLIENT_TO_SERVER_ID, nextClientToServerMessageId);
SystemMessages messages = ui.getSession().getService().getSystemMessages(ui.getLocale(), null);
JsonObject meta = new MetadataWriter().createMetadata(ui, false, async, messages);
if (meta.keys().length > 0) {
response.put("meta", meta);
}
JsonArray stateChanges = Json.createArray();
JsonObject templates = Json.createObject();
encodeChanges(ui, stateChanges, templates);
populateDependencies(response, session, uiInternals.getDependencyList());
if (uiInternals.getConstantPool().hasNewConstants()) {
response.put("constants", uiInternals.getConstantPool().dumpConstants());
}
if (stateChanges.length() != 0) {
response.put("changes", stateChanges);
}
if (templates.keys().length > 0) {
response.put("templates", templates);
}
List<JavaScriptInvocation> executeJavaScriptList = uiInternals.dumpPendingJavaScriptInvocations();
if (!executeJavaScriptList.isEmpty()) {
response.put(JsonConstants.UIDL_KEY_EXECUTE, encodeExecuteJavaScriptList(executeJavaScriptList));
}
if (ui.getSession().getService().getDeploymentConfiguration().isRequestTiming()) {
response.put("timings", createPerformanceData(ui));
}
uiInternals.incrementServerId();
return response;
}
use of com.vaadin.flow.component.internal.UIInternals in project flow by vaadin.
the class UidlWriter method encodeChanges.
/**
* Encodes the state tree changes of the given UI. The executions registered
* at
* {@link StateTree#beforeClientResponse(com.vaadin.flow.internal.StateNode, com.vaadin.flow.function.SerializableConsumer)}
* at evaluated before the changes are encoded.
*
* @param ui
* the UI
* @param stateChanges
* a JSON array to put state changes into
* @param templates
* a JSON object to put new template nodes into
* @see StateTree#runExecutionsBeforeClientResponse()
*/
private void encodeChanges(UI ui, JsonArray stateChanges, JsonObject templates) {
UIInternals uiInternals = ui.getInternals();
StateTree stateTree = uiInternals.getStateTree();
stateTree.runExecutionsBeforeClientResponse();
Consumer<TemplateNode> templateEncoder = new Consumer<TemplateNode>() {
@Override
public void accept(TemplateNode templateNode) {
// Send to client if it's a new template
if (!uiInternals.isTemplateSent(templateNode)) {
uiInternals.setTemplateSent(templateNode);
templates.put(Integer.toString(templateNode.getId()), templateNode.toJson(this));
}
}
};
Set<Class<? extends Component>> componentsWithDependencies = new LinkedHashSet<>();
stateTree.collectChanges(change -> {
// Ensure new templates are sent to the client
runIfNewTemplateChange(change, templateEncoder);
if (attachesComponent(change)) {
change.getNode().getFeature(ComponentMapping.class).getComponent().ifPresent(component -> addComponentHierarchy(ui, componentsWithDependencies, component));
}
// Encode the actual change
stateChanges.set(stateChanges.length(), change.toJson(uiInternals.getConstantPool()));
});
componentsWithDependencies.forEach(uiInternals::addComponentDependencies);
}
Aggregations