UNPKG

computed-async-mobx

Version:

Define a computed by returning a Promise

27 lines (26 loc) 1.2 kB
import { Getter } from "./Getter"; export declare function isPromiseLike<T>(result: PromiseLike<T> | T): result is PromiseLike<T>; /** * PromisedComputedValue */ export interface PromisedComputedValue<T> extends Getter<T> { /** True if the promise is currently resolving */ readonly busy: boolean; refresh(): void; getNonReactive(): T; } /** * Similar to the standard computed, except that it converts promises into * plain values, unwrapping them when they resolve and updating to the new * value. The supplied function may return a plain value in which case the * update is entirely synchronous like standard computed. * * As with the standard computed, exceptions (and rejected promises) are * propagated as re-thrown exceptions. To avoid this, perform your own * error handling in your supplied function. * * @param init Value to assume until the promise first resolves * @param compute Evaluates to a promised or plain value */ export declare function promisedComputed<T>(init: T, compute: () => PromiseLike<T> | T): PromisedComputedValue<T>; export declare function promisedComputedInternal<T>(init: T, compute: () => PromiseLike<T> | T): PromisedComputedValue<T>;