use of com.vaadin.flow.component.internal.PendingJavaScriptInvocation in project flow by vaadin.
the class Element method scheduleJavaScriptInvocation.
private PendingJavaScriptResult scheduleJavaScriptInvocation(String expression, Stream<Serializable> parameters) {
StateNode node = getNode();
JavaScriptInvocation invocation = new JavaScriptInvocation(expression, parameters.toArray(Serializable[]::new));
PendingJavaScriptInvocation pending = new PendingJavaScriptInvocation(node, invocation);
node.runWhenAttached(ui -> ui.getInternals().getStateTree().beforeClientResponse(node, context -> {
if (!pending.isCanceled()) {
context.getUI().getInternals().addJavaScriptInvocation(pending);
}
}));
return pending;
}
use of com.vaadin.flow.component.internal.PendingJavaScriptInvocation 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
* @param resync
* True iff the client should be asked to resynchronize
* @return JSON object containing the UIDL response
*/
public JsonObject createUidl(UI ui, boolean async, boolean resync) {
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);
if (resync) {
response.put(ApplicationConstants.RESYNCHRONIZE_ID, true);
}
int nextClientToServerMessageId = uiInternals.getLastProcessedClientToServerId() + 1;
response.put(ApplicationConstants.CLIENT_TO_SERVER_ID, nextClientToServerMessageId);
SystemMessages messages = service.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();
encodeChanges(ui, stateChanges);
populateDependencies(response, uiInternals.getDependencyList(), new ResolveContext(service, session.getBrowser()));
if (uiInternals.getConstantPool().hasNewConstants()) {
response.put("constants", uiInternals.getConstantPool().dumpConstants());
}
if (stateChanges.length() != 0) {
response.put("changes", stateChanges);
}
List<PendingJavaScriptInvocation> executeJavaScriptList = uiInternals.dumpPendingJavaScriptInvocations();
if (!executeJavaScriptList.isEmpty()) {
response.put(JsonConstants.UIDL_KEY_EXECUTE, encodeExecuteJavaScriptList(executeJavaScriptList));
}
if (service.getDeploymentConfiguration().isRequestTiming()) {
response.put("timings", createPerformanceData(ui));
}
uiInternals.incrementServerId();
return response;
}
Aggregations