@JsOverlay public static final <V> Promise<V> resolve(V value) { return resolve(Js.<ResolveValueUnionType<V>>uncheckedCast(value)); }
@JsOverlay public static final <V> Promise<V> resolve(V value) { return resolve(Js.<ResolveValueUnionType<V>>uncheckedCast(value)); }
public static native <V> Promise<V> resolve(ResolveValueUnionType<V> value);
public static native <V> Promise<V> resolve(ResolveValueUnionType<V> value);
@JsOverlay public final Promise<String> put(Document document) { return internalPut(document).then(response -> Promise.resolve(response.id)); }
/** Returns all documents whose ID starts with the specified ID. */ @JsOverlay public final Promise<List<Document>> prefixSearch(String id) { AllDocsOptions options = new AllDocsOptions(); options.include_docs = true; options.startkey = id; options.endkey = id + "\ufff0"; return allDocs(options).then(response -> { List<Document> documents = new ArrayList<>(); for (int i = 0; i < response.rows.getLength(); i++) { Row row = response.rows.getAt(i); if (!"not_found".equals(row.error)) { documents.add(row.doc); } } return Promise.resolve(documents); }); }
@Override public Disposable schedule(Runnable action, long delayTime, TimeUnit unit) { action = RxJavaPlugins.onSchedule(action); ScheduledAction scheduledAction = new ScheduledAction(action); if (incremental && (delayTime <= 0 || unit == null)) { Promise.resolve(0).then(o -> { scheduledAction.run(); return null; }); } else { DomGlobal.setTimeout(args -> scheduledAction.run(), (int) unit.toMillis(delayTime)); } return scheduledAction; }
@Override public Disposable schedule(Runnable action, long delayTime, TimeUnit unit) { action = RxJavaPlugins.onSchedule(action); ScheduledAction scheduledAction = new ScheduledAction(action); if (incremental && (delayTime <= 0 || unit == null)) { Promise.resolve(0).then(o -> { scheduledAction.run(); return null; }); } else { DomGlobal.setTimeout(args -> scheduledAction.run(), (int) unit.toMillis(delayTime)); } return scheduledAction; }
/** Returns the documents for the specified ids. Only documents with existing IDs will be returned. */ @JsOverlay public final Promise<List<Document>> getAll(Set<String> ids) { AllDocsOptions options = new AllDocsOptions(); options.include_docs = true; options.keys = new JsArray<>(); for (String id : ids) { options.keys.push(id); } return allDocs(options).then(response -> { List<Document> documents = new ArrayList<>(); for (int i = 0; i < response.rows.getLength(); i++) { Row row = response.rows.getAt(i); if (!"not_found".equals(row.error)) { documents.add(row.doc); } } return Promise.resolve(documents); }); }
/** * The first time an arez component is rendered it will lock the Arez scheduler and release * the lock in the micro-task immediately following the task that prompted the render. If this * is not done it is possible that Arez can re-trigger a component render when the scheduler is * triggered after the tracked render completes but before the render method has returned to the * react runtime. This results in error message from react as a setState()/forceRender() was invoked * while still within a render() method. * * <p>NOTE: While render methods are read-only transactions, they can un-observe components with * <code>disposeOnDeactivate=true</code> that would result in the component being disposed and * triggering an update that would mark particular React Components/Observers as STALE and trigger * a re-render of that component.</p> */ protected final void pauseArezSchedulerUntilRenderLoopComplete() { if ( null == c_schedulerLock ) { c_schedulerLock = getContext().pauseScheduler(); // Use a hack of an empty promise that immediately resolves to // schedule the block immediately after this call stack pops. Promise.resolve( (Object) null ).then( ignored -> { c_schedulerLock.dispose(); c_schedulerLock = null; return null; } ); } }
@JsOverlay public final Promise<Set<String>> putAll(List<Document> documents) { JsArray<Document> docs = new JsArray<>(); for (Document document : documents) { docs.push(document); } return bulkDocs(docs).then(response -> { Set<String> ids = new HashSet<>(); for (int i = 0; i < response.getLength(); i++) { BulkDocsSingleUnionType unionType = response.getAt(i); if (unionType.isSuccess()) { ids.add(unionType.asSuccess().id); } } return Promise.resolve(ids); }); }
/** * The first time an arez component is rendered it will lock the Arez scheduler and release * the lock in the micro-task immediately following the task that prompted the render. If this * is not done it is possible that Arez can re-trigger a component render when the scheduler is * triggered after the tracked render completes but before the render method has returned to the * react runtime. This results in error message from react as a setState()/forceRender() was invoked * while still within a render() method. * * <p>NOTE: While render methods are read-only transactions, they can un-observe components with * {@link ArezComponent#disposeOnDeactivate()}set to <code>true</code> that would result in the component * being disposed and triggering an update that would mark particular React Components/Observers as STALE and * trigger a re-render of that component.</p> */ public static void pauseUntilRenderLoopComplete() { if ( null == c_schedulerLock ) { c_schedulerLock = Arez.context().pauseScheduler(); // Use a hack of an empty promise that immediately resolves to // schedule the block immediately after this call stack pops. Promise.resolve( (Object) null ).then( ignored -> { c_schedulerLock.dispose(); c_schedulerLock = null; return null; } ); } } }