UNPKG

computed-async-mobx

Version:

Define a computed by returning a Promise

36 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.asyncComputed = void 0; var promisedComputed_1 = require("./promisedComputed"); var throttledComputed_1 = require("./throttledComputed"); /** * Composition of promisedComputed and throttledComputed, so performs * conversion of a promised value into a plain value and also waits for * the specified minimum delay before launching a new promise in response * to changes. * * @param init Value to assume until the promise first resolves * @param delay Minimum time to wait between creating new promises * @param compute Evaluates to a promised or plain value * @param name (optional) For MobX debug purposes */ function asyncComputed(init, delay, compute, name) { var throttled = throttledComputed_1.throttledComputed(compute, delay, name); var promised = promisedComputed_1.promisedComputed(init, throttled.get); return { get: function () { return promised.get(); }, get busy() { return promised.busy; }, getNonReactive: function () { return promised.getNonReactive(); }, refresh: function () { throttled.refresh(); } }; } exports.asyncComputed = asyncComputed; //# sourceMappingURL=asyncComputed.js.map