From 7efe311c8858e415f04d582ab9811b5326e6fd41 Mon Sep 17 00:00:00 2001 From: alisman Date: Mon, 24 Oct 2022 17:39:40 -0400 Subject: [PATCH 1/2] Add label property --- dist/index.js | 18 ++++++++++++++---- dist/index.js.map | 2 +- dist/src/MobxPromise.d.ts | 12 +++++++++--- src/MobxPromise.ts | 32 +++++++++++++++++++++++++------- 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/dist/index.js b/dist/index.js index 912fcc2..232ed43 100644 --- a/dist/index.js +++ b/dist/index.js @@ -173,6 +173,8 @@ var MobxPromiseImpl = function () { this.defaultResult = norm.default; this.onResult = norm.onResult; this.onError = norm.onError; + /*@ts-ignore */ + this.label = input.label; } _createClass(MobxPromiseImpl, [{ @@ -297,6 +299,14 @@ var MobxPromiseImpl = function () { key: "result", get: function get() { // checking status may trigger invoke + /*@ts-ignore*/ + if (this.isComplete === false) { + if (localStorage.debugMP) { + debugger; + } + /*@ts-ignore*/ + console.log(this.label + " accessed prior to completion", this); + } if (this.isError || this.internalResult == null) return this.defaultResult; return this.internalResult; } @@ -357,13 +367,13 @@ var MobxPromiseImpl = function () { } }, { key: "normalizeInput", - value: function normalizeInput(input, defaultResult) { - if (typeof input === 'function') return { invoke: input, default: defaultResult }; + value: function normalizeInput(input, defaultResult, label) { + if (typeof input === 'function') return { invoke: input, default: defaultResult, label: label }; if (MobxPromiseImpl.isPromiseLike(input)) return { invoke: function invoke() { return input; - }, default: defaultResult }; + }, default: defaultResult, label: label }; input = input; - if (defaultResult !== undefined) input = Object.assign(Object.assign({}, input), { default: defaultResult }); + if (defaultResult !== undefined) input = Object.assign(Object.assign({}, input), { default: defaultResult, label: label }); return input; } }]); diff --git a/dist/index.js.map b/dist/index.js.map index ded3c4e..0efd9dd 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap a79059a65a266adffb7d","webpack:///./src/MobxPromise.ts","webpack:///external \"mobx\"","webpack:///./src/index.ts","webpack:///./src/utils.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,KAAK;QACL;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;QAEA;QACA;;;;;;;;;;;;;;;;;;;;;;;;;;AC7DA;AAwDA;;;;;IAIa,e;AAqBT,6BAAY,KAAZ,EAA6C,aAA7C,EAA8D;AAAA;;AAY9D;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;mBAA2B;AAA3B;AACA;4BAAA;8BAAA;0BAAA;mBAAkC;AAAlC;AAEY;4BAAA;8BAAA;0BAAA;mBAA2D;AAA3D;AACI;4BAAA;8BAAA;0BAAA;mBAA6B;AAA7B;AACA;4BAAA;8BAAA;0BAAA;mBAAgC;AAAhC;AApBZ,8BAAmC,IAAnC;AAEA,YAAI,OAAO,gBAAgB,cAAhB,CAA+B,KAA/B,EAAsC,aAAtC,CAAX;AACA,aAAK,KAAL,GAAa,KAAK,KAAlB;AACA,aAAK,MAAL,GAAc,KAAK,MAAnB;AACA,aAAK,aAAL,GAAqB,KAAK,OAA1B;AACA,aAAK,QAAL,GAAgB,KAAK,QAArB;AACA,aAAK,OAAL,GAAe,KAAK,OAApB;AACH;;;;mCAmFkB,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aAAhB,CAA8E,MAA9E,EAAiG;AAAA,QAAT,KAAS,uEAAD,CAAC;;AAEhG,aAAS,WAAT,CACC,OADD,EAEC,IAFD,EAGC,OAHD,EAIC,MAJD,EAI2B;AAE1B,YACA;AACC,oBAAQ,OAAO,KAAP,CAAa,OAAb,EAAsB,IAAtB,CAAR;AACA,SAHD,CAIA,OAAO,CAAP,EACA;AACC,mBAAO,CAAP;AACA;AACD;AAED,QAAI,UAAU,CAAd;AACA,WAAO,YAAsB;AAAA,2CAAV,IAAU;AAAV,gBAAU;AAAA;;AAC5B,eAAO,IAAI,OAAJ,CACN,UAAS,OAAT,EAAkB,MAAlB,EAAwB;AACvB,mBAAO,YAAP,CAAoB,OAApB;AACA,sBAAU,OAAO,UAAP,CAAkB,WAAlB,EAA+B,KAA/B,EAAsC,IAAtC,EAA4C,IAA5C,EAAkD,OAAlD,EAA2D,MAA3D,CAAV;AACA,SAJK,CAAP;AAMK,KAPN;AAQA;AA3BD,sC","file":"index.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"mobx\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"mobx\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"index\"] = factory(require(\"mobx\"));\n\telse\n\t\troot[\"index\"] = factory(root[\"mobx\"]);\n})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_1__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap a79059a65a266adffb7d","import {observable, action, computed, makeObservable} from \"mobx\";\n\n/**\n * This tagged union type describes the interoperability of MobxPromise properties.\n */\ntype MobxPromiseStatus = 'pending' | 'error' | 'complete';\nexport type MobxPromiseUnionType = (\n { status: 'pending', isPending: true, isError: false, isComplete: false, result: R | undefined, error: Error | undefined } |\n { status: 'error', isPending: false, isError: true, isComplete: false, result: R | undefined, error: Error } |\n { status: 'complete', isPending: false, isError: false, isComplete: true, result: R, error: Error | undefined }\n ) & { peekStatus: MobxPromiseStatus };\nexport type MobxPromiseUnionTypeWithDefault = (\n { status: 'pending', isPending: true, isError: false, isComplete: false, result: R, error: Error | undefined } |\n { status: 'error', isPending: false, isError: true, isComplete: false, result: R, error: Error } |\n { status: 'complete', isPending: false, isError: false, isComplete: true, result: R, error: Error | undefined }\n ) & { peekStatus: MobxPromiseStatus };\n\nexport type MobxPromiseInputUnion = PromiseLike | (() => PromiseLike) | MobxPromiseInputParams;\nexport type MobxPromiseInputParams = {\n /**\n * A function that returns a list of MobxPromise objects which are dependencies of the invoke function.\n */\n await?: MobxPromise_await,\n\n /**\n * A function that returns the async result or a promise for the async result.\n */\n invoke: MobxPromise_invoke,\n\n /**\n * Default result in place of undefined\n */\n default?: R,\n\n /**\n * A function that will be called when the latest promise from invoke() is resolved.\n * It will not be called for out-of-date promises.\n */\n onResult?: (result?: R) => void,\n\n /**\n * A function that will be called when the latest promise from invoke() is rejected.\n * It will not be called for out-of-date promises.\n */\n onError?: (error: Error) => void,\n};\nexport type MobxPromise_await = () => Array | MobxPromiseUnionType | MobxPromise>;\nexport type MobxPromise_invoke = () => PromiseLike;\nexport type MobxPromiseInputParamsWithDefault = {\n await?: MobxPromise_await,\n invoke: MobxPromise_invoke,\n default: R,\n onResult?: (result: R) => void,\n onError?: (error: Error) => void,\n};\n\n/**\n * MobxPromise provides an observable interface for a computed promise.\n * @author adufilie http://github.com/adufilie\n */\nexport class MobxPromiseImpl {\n static isPromiseLike(value: any) {\n return value != null && typeof value === 'object' && typeof value.then === 'function';\n }\n\n static normalizeInput(input: MobxPromiseInputParamsWithDefault): MobxPromiseInputParamsWithDefault;\n static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R): MobxPromiseInputParamsWithDefault;\n static normalizeInput(input: MobxPromiseInputUnion): MobxPromiseInputParams;\n static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R) {\n if (typeof input === 'function')\n return {invoke: input, default: defaultResult};\n\n if (MobxPromiseImpl.isPromiseLike(input))\n return {invoke: () => input as PromiseLike, default: defaultResult};\n\n input = input as MobxPromiseInputParams;\n if (defaultResult !== undefined)\n input = {...input, default: defaultResult};\n return input;\n }\n\n constructor(input: MobxPromiseInputUnion, defaultResult?: R) {\n\n makeObservable>(this);\n\n let norm = MobxPromiseImpl.normalizeInput(input, defaultResult);\n this.await = norm.await;\n this.invoke = norm.invoke;\n this.defaultResult = norm.default;\n this.onResult = norm.onResult;\n this.onError = norm.onError;\n }\n\n private await?: MobxPromise_await;\n private invoke: MobxPromise_invoke;\n private onResult?: (result?: R) => void;\n private onError?: (error: Error) => void;\n private defaultResult?: R;\n private invokeId: number = 0;\n private _latestInvokeId: number = 0;\n\n @observable private internalStatus: 'pending' | 'complete' | 'error' = 'pending';\n @observable.ref private internalResult?: R = undefined;\n @observable.ref private internalError?: Error = undefined;\n\n @computed get status(): 'pending' | 'complete' | 'error' {\n // wait until all MobxPromise dependencies are complete\n if (this.await)\n for (let status of this.await().map(mp => mp.status)) // track all statuses before returning\n if (status !== 'complete')\n return status;\n\n let status = this.internalStatus; // force mobx to track changes to internalStatus\n if (this.latestInvokeId != this.invokeId)\n status = 'pending';\n return status;\n }\n\n @computed get peekStatus(): 'pending' | 'complete' | 'error' {\n // check status without triggering invoke\n\n // check status of all MobxPromise dependencies\n if (this.await)\n for (let status of this.await().map(mp => mp.peekStatus))\n if (status !== 'complete')\n return status;\n\n // otherwise, return internal status\n return this.internalStatus;\n }\n\n @computed get isPending() {\n return this.status == 'pending';\n }\n\n @computed get isComplete() {\n return this.status == 'complete';\n }\n\n @computed get isError() {\n return this.status == 'error';\n }\n\n @computed get result(): R | undefined {\n // checking status may trigger invoke\n if (this.isError || this.internalResult == null)\n return this.defaultResult;\n\n return this.internalResult;\n }\n\n @computed get error(): Error | undefined {\n // checking status may trigger invoke\n if (!this.isComplete && this.await)\n for (let error of this.await().map(mp => mp.error)) // track all errors before returning\n if (error)\n return error;\n\n return this.internalError;\n }\n\n /**\n * This lets mobx determine when to call this.invoke(),\n * taking advantage of caching based on observable property access tracking.\n */\n @computed\n private get latestInvokeId() {\n window.clearTimeout(this._latestInvokeId);\n let promise = this.invoke();\n let invokeId: number = window.setTimeout(() => this.setPending(invokeId, promise));\n return this._latestInvokeId = invokeId;\n }\n\n @action\n private setPending(invokeId: number, promise: PromiseLike) {\n this.invokeId = invokeId;\n promise.then(\n result => this.setComplete(invokeId, result),\n error => this.setError(invokeId, error)\n );\n this.internalStatus = 'pending';\n }\n\n @action\n private setComplete(invokeId: number, result: R) {\n if (invokeId === this.invokeId) {\n this.internalResult = result;\n this.internalError = undefined;\n this.internalStatus = 'complete';\n\n if (this.onResult)\n this.onResult(this.result); // may use defaultResult\n }\n }\n\n @action\n private setError(invokeId: number, error: Error) {\n if (invokeId === this.invokeId) {\n this.internalError = error;\n this.internalResult = undefined;\n this.internalStatus = 'error';\n\n if (this.onError)\n this.onError(error);\n }\n }\n}\n\nexport type MobxPromiseFactory = {\n // This provides more information for TypeScript code flow analysis\n (input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault;\n (input: MobxPromiseInputUnion, defaultResult: R): MobxPromiseUnionTypeWithDefault;\n (input: MobxPromiseInputUnion): MobxPromiseUnionType;\n};\n\nexport const MobxPromise = MobxPromiseImpl as {\n // This provides more information for TypeScript code flow analysis\n new(input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault;\n new(input: MobxPromiseInputUnion, defaultResult: R): MobxPromiseUnionTypeWithDefault;\n new(input: MobxPromiseInputUnion): MobxPromiseUnionType;\n};\n\nexport interface MobxPromise extends Pick, 'status' | 'error' | 'result' | 'isPending' | 'isError' | 'isComplete' | 'peekStatus'> {\n}\n\nexport default MobxPromise;\n\n\n\n// WEBPACK FOOTER //\n// ./src/MobxPromise.ts","module.exports = __WEBPACK_EXTERNAL_MODULE_1__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"mobx\"\n// module id = 1\n// module chunks = 0","export * from './MobxPromise';\nexport * from './utils';\n\nimport MobxPromise from './MobxPromise';\nexport default MobxPromise;\n\n\n\n// WEBPACK FOOTER //\n// ./src/index.ts","import {autorun, computed, getObserverTree, IComputedValue, IListenable, IObservable,\n_getAdministration, getAtom} from 'mobx';\nimport {MobxPromise} from \"./MobxPromise\";\n\n/**\n * A decorator for creating a @computed property that will be cached\n * after the first time it is accessed, even if it becomes unobserved later.\n * @param target\n * @param propertyKey\n * @param descriptor\n */\nexport function cached(target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor)\n{\n\tif (descriptor.get)\n\t{\n\t\tlet get = descriptor.get;\n\t\tdescriptor.get = function(...args:any[]) {\n\t\t\tconst atom = getAtom(this, propertyKey as string) as IObservable & IListenable;\n\t\t\t// to keep the cached value, add an observer if there are none\n\t\t\tif (!atom.isBeingObserved_)\n\t\t\t\tautorun(()=>atom);\n\n\t\t\treturn get.apply(this, args);\n\t\t};\n\t}\n\treturn descriptor;\n}\n\n/**\n * Checks if a property has observers.\n */\nexport function hasObservers(thing:T, property:keyof T)\n{\n\tlet tree = getObserverTree(thing, property as string);\n\treturn tree && tree.observers ? tree.observers.length > 0 : false;\n}\n\n/**\n * Update MobxPromise debug names to reflect their property names on a given object.\n * @param target An object which has properties that are MobxPromises.\n */\nexport function labelMobxPromises(target:T)\n{\n\tfor (let key in target)\n\t{\n\t\tlet desc = Object.getOwnPropertyDescriptor(target, key);\n\t\tif (desc && desc.value instanceof MobxPromise)\n\t\t{\n\t\t\tlet admin = _getAdministration(desc.value);\n\t\t\tadmin.name = `${key}(${admin.name})`;\n\t\t}\n\t}\n}\n\n/**\n * A function created with debounceAsync() returns a new Promise\n * every time, but only the last promise created before invoking the\n * original function will be resolved after a specified delay.\n */\nexport function debounceAsync PromiseLike>(invoke:F, delay = 0):F\n{\n\tfunction invokeLater(\n\t\tcontext:any,\n\t\targs:any[],\n\t\tresolve:(result:PromiseLike)=>void,\n\t\treject:(error:Error)=>void\n\t) {\n\t\ttry\n\t\t{\n\t\t\tresolve(invoke.apply(context, args));\n\t\t}\n\t\tcatch (e)\n\t\t{\n\t\t\treject(e);\n\t\t}\n\t}\n\n\tlet timeout = 0;\n\treturn function(...args:any[]):PromiseLike {\n\t\treturn new Promise(\n\t\t\tfunction(resolve, reject) {\n\t\t\t\twindow.clearTimeout(timeout);\n\t\t\t\ttimeout = window.setTimeout(invokeLater, delay, this, args, resolve, reject);\n\t\t\t}\n\t\t);\n\t} as F;\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils.ts"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 645502d9f99f7a6913eb","webpack:///./src/MobxPromise.ts","webpack:///external \"mobx\"","webpack:///./src/index.ts","webpack:///./src/utils.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,KAAK;QACL;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;QAEA;QACA;;;;;;;;;;;;;;;;;;;;;;;;;;AC7DA;AA2DA;;;;;IAIa,e;AAsBT,6BAAY,KAAZ,EAA6C,aAA7C,EAA8D;AAAA;;AAe9D;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;mBAA2B;AAA3B;AACA;4BAAA;8BAAA;0BAAA;mBAAkC;AAAlC;AAEY;4BAAA;8BAAA;0BAAA;mBAA2D;AAA3D;AACI;4BAAA;8BAAA;0BAAA;mBAA6B;AAA7B;AACA;4BAAA;8BAAA;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typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"mobx\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"mobx\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"index\"] = factory(require(\"mobx\"));\n\telse\n\t\troot[\"index\"] = factory(root[\"mobx\"]);\n})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_1__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 645502d9f99f7a6913eb","import {observable, action, computed, makeObservable} from \"mobx\";\n\n/**\n * This tagged union type describes the interoperability of MobxPromise properties.\n */\ntype MobxPromiseStatus = 'pending' | 'error' | 'complete';\nexport type MobxPromiseUnionType = (\n { status: 'pending', isPending: true, isError: false, isComplete: false, result: R | undefined, error: Error | undefined } |\n { status: 'error', isPending: false, isError: true, isComplete: false, result: R | undefined, error: Error } |\n { status: 'complete', isPending: false, isError: false, isComplete: true, result: R, error: Error | undefined }\n ) & { peekStatus: MobxPromiseStatus } & { label:string };\nexport type MobxPromiseUnionTypeWithDefault = (\n { status: 'pending', isPending: true, isError: false, isComplete: false, result: R, error: Error | undefined } |\n { status: 'error', isPending: false, isError: true, isComplete: false, result: R, error: Error } |\n { status: 'complete', isPending: false, isError: false, isComplete: true, result: R, error: Error | undefined }\n ) & { peekStatus: MobxPromiseStatus } & { label:string };\n\nexport type MobxPromiseInputUnion = PromiseLike | (() => PromiseLike) | MobxPromiseInputParams;\nexport type MobxPromiseInputParams = {\n /**\n * A function that returns a list of MobxPromise objects which are dependencies of the invoke function.\n */\n await?: MobxPromise_await,\n\n /**\n * A function that returns the async result or a promise for the async result.\n */\n invoke: MobxPromise_invoke,\n\n /**\n * Default result in place of undefined\n */\n default?: R,\n\n /**\n * A function that will be called when the latest promise from invoke() is resolved.\n * It will not be called for out-of-date promises.\n */\n onResult?: (result?: R) => void,\n\n /**\n * A function that will be called when the latest promise from invoke() is rejected.\n * It will not be called for out-of-date promises.\n */\n onError?: (error: Error) => void,\n\n label?: string,\n};\nexport type MobxPromise_await = () => Array | MobxPromiseUnionType | MobxPromise>;\nexport type MobxPromise_invoke = () => PromiseLike;\nexport type MobxPromiseInputParamsWithDefault = {\n await?: MobxPromise_await,\n invoke: MobxPromise_invoke,\n default: R,\n onResult?: (result: R) => void,\n onError?: (error: Error) => void,\n label?: string,\n};\n\n/**\n * MobxPromise provides an observable interface for a computed promise.\n * @author adufilie http://github.com/adufilie\n */\nexport class MobxPromiseImpl {\n static isPromiseLike(value: any) {\n return value != null && typeof value === 'object' && typeof value.then === 'function';\n }\n\n static normalizeInput(input: MobxPromiseInputParamsWithDefault): MobxPromiseInputParamsWithDefault;\n static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R, label?:string): MobxPromiseInputParamsWithDefault;\n static normalizeInput(input: MobxPromiseInputUnion): MobxPromiseInputParams;\n static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R, label?:string) {\n if (typeof input === 'function')\n return {invoke: input, default: defaultResult, label };\n\n if (MobxPromiseImpl.isPromiseLike(input))\n return {invoke: () => input as PromiseLike, default: defaultResult, label};\n\n input = input as MobxPromiseInputParams;\n if (defaultResult !== undefined)\n input = {...input, default: defaultResult, label};\n\n return input;\n }\n\n constructor(input: MobxPromiseInputUnion, defaultResult?: R) {\n\n makeObservable>(this);\n\n let norm = MobxPromiseImpl.normalizeInput(input, defaultResult);\n this.await = norm.await;\n this.invoke = norm.invoke;\n this.defaultResult = norm.default;\n this.onResult = norm.onResult;\n this.onError = norm.onError;\n\n /*@ts-ignore */\n this.label = input.label;\n }\n\n private await?: MobxPromise_await;\n private invoke: MobxPromise_invoke;\n private onResult?: (result?: R) => void;\n private onError?: (error: Error) => void;\n private defaultResult?: R;\n private invokeId: number = 0;\n private _latestInvokeId: number = 0;\n\n @observable private internalStatus: 'pending' | 'complete' | 'error' = 'pending';\n @observable.ref private internalResult?: R = undefined;\n @observable.ref private internalError?: Error = undefined;\n\n @computed get status(): 'pending' | 'complete' | 'error' {\n // wait until all MobxPromise dependencies are complete\n if (this.await)\n for (let status of this.await().map(mp => mp.status)) // track all statuses before returning\n if (status !== 'complete')\n return status;\n\n let status = this.internalStatus; // force mobx to track changes to internalStatus\n if (this.latestInvokeId != this.invokeId)\n status = 'pending';\n return status;\n }\n\n @computed get peekStatus(): 'pending' | 'complete' | 'error' {\n // check status without triggering invoke\n\n // check status of all MobxPromise dependencies\n if (this.await)\n for (let status of this.await().map(mp => mp.peekStatus))\n if (status !== 'complete')\n return status;\n\n // otherwise, return internal status\n return this.internalStatus;\n }\n\n @computed get isPending() {\n return this.status == 'pending';\n }\n\n @computed get isComplete() {\n return this.status == 'complete';\n }\n\n @computed get isError() {\n return this.status == 'error';\n }\n\n @computed get result(): R | undefined {\n // checking status may trigger invoke\n /*@ts-ignore*/\n if (this.isComplete === false) {\n\n if (localStorage.debugMP) {\n debugger;\n }\n\n /*@ts-ignore*/\n console.log(`${this.label} accessed prior to completion`, this);\n }\n\n if (this.isError || this.internalResult == null)\n return this.defaultResult;\n\n return this.internalResult;\n }\n\n @computed get error(): Error | undefined {\n // checking status may trigger invoke\n if (!this.isComplete && this.await)\n for (let error of this.await().map(mp => mp.error)) // track all errors before returning\n if (error)\n return error;\n\n return this.internalError;\n }\n\n /**\n * This lets mobx determine when to call this.invoke(),\n * taking advantage of caching based on observable property access tracking.\n */\n @computed\n private get latestInvokeId() {\n window.clearTimeout(this._latestInvokeId);\n let promise = this.invoke();\n let invokeId: number = window.setTimeout(() => this.setPending(invokeId, promise));\n return this._latestInvokeId = invokeId;\n }\n\n @action\n private setPending(invokeId: number, promise: PromiseLike) {\n this.invokeId = invokeId;\n promise.then(\n result => this.setComplete(invokeId, result),\n error => this.setError(invokeId, error)\n );\n this.internalStatus = 'pending';\n }\n\n @action\n private setComplete(invokeId: number, result: R) {\n if (invokeId === this.invokeId) {\n this.internalResult = result;\n this.internalError = undefined;\n this.internalStatus = 'complete';\n\n if (this.onResult)\n this.onResult(this.result); // may use defaultResult\n }\n }\n\n @action\n private setError(invokeId: number, error: Error) {\n if (invokeId === this.invokeId) {\n this.internalError = error;\n this.internalResult = undefined;\n this.internalStatus = 'error';\n\n if (this.onError)\n this.onError(error);\n }\n }\n}\n\nexport type MobxPromiseFactory = {\n // This provides more information for TypeScript code flow analysis\n (input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault;\n (input: MobxPromiseInputUnion, defaultResult: R | undefined, label?:string): MobxPromiseUnionTypeWithDefault;\n (input: MobxPromiseInputUnion): MobxPromiseUnionType;\n};\n\nexport const MobxPromise = MobxPromiseImpl as {\n // This provides more information for TypeScript code flow analysis\n new(input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault;\n new(input: MobxPromiseInputUnion, defaultResult: R | undefined, label?:string): MobxPromiseUnionTypeWithDefault;\n new(input: MobxPromiseInputUnion): MobxPromiseUnionType;\n};\n\nexport interface MobxPromise extends Pick, 'status' | 'error' | 'result' | 'isPending' | 'isError' | 'isComplete' | 'peekStatus'> {\n}\n\nexport default MobxPromise;\n\n\n\n// WEBPACK FOOTER //\n// ./src/MobxPromise.ts","module.exports = __WEBPACK_EXTERNAL_MODULE_1__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"mobx\"\n// module id = 1\n// module chunks = 0","export * from './MobxPromise';\nexport * from './utils';\n\nimport MobxPromise from './MobxPromise';\nexport default MobxPromise;\n\n\n\n// WEBPACK FOOTER //\n// ./src/index.ts","import {autorun, computed, getObserverTree, IComputedValue, IListenable, IObservable,\n_getAdministration, getAtom} from 'mobx';\nimport {MobxPromise} from \"./MobxPromise\";\n\n/**\n * A decorator for creating a @computed property that will be cached\n * after the first time it is accessed, even if it becomes unobserved later.\n * @param target\n * @param propertyKey\n * @param descriptor\n */\nexport function cached(target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor)\n{\n\tif (descriptor.get)\n\t{\n\t\tlet get = descriptor.get;\n\t\tdescriptor.get = function(...args:any[]) {\n\t\t\tconst atom = getAtom(this, propertyKey as string) as IObservable & IListenable;\n\t\t\t// to keep the cached value, add an observer if there are none\n\t\t\tif (!atom.isBeingObserved_)\n\t\t\t\tautorun(()=>atom);\n\n\t\t\treturn get.apply(this, args);\n\t\t};\n\t}\n\treturn descriptor;\n}\n\n/**\n * Checks if a property has observers.\n */\nexport function hasObservers(thing:T, property:keyof T)\n{\n\tlet tree = getObserverTree(thing, property as string);\n\treturn tree && tree.observers ? tree.observers.length > 0 : false;\n}\n\n/**\n * Update MobxPromise debug names to reflect their property names on a given object.\n * @param target An object which has properties that are MobxPromises.\n */\nexport function labelMobxPromises(target:T)\n{\n\tfor (let key in target)\n\t{\n\t\tlet desc = Object.getOwnPropertyDescriptor(target, key);\n\t\tif (desc && desc.value instanceof MobxPromise)\n\t\t{\n\t\t\tlet admin = _getAdministration(desc.value);\n\t\t\tadmin.name = `${key}(${admin.name})`;\n\t\t}\n\t}\n}\n\n/**\n * A function created with debounceAsync() returns a new Promise\n * every time, but only the last promise created before invoking the\n * original function will be resolved after a specified delay.\n */\nexport function debounceAsync PromiseLike>(invoke:F, delay = 0):F\n{\n\tfunction invokeLater(\n\t\tcontext:any,\n\t\targs:any[],\n\t\tresolve:(result:PromiseLike)=>void,\n\t\treject:(error:Error)=>void\n\t) {\n\t\ttry\n\t\t{\n\t\t\tresolve(invoke.apply(context, args));\n\t\t}\n\t\tcatch (e)\n\t\t{\n\t\t\treject(e);\n\t\t}\n\t}\n\n\tlet timeout = 0;\n\treturn function(...args:any[]):PromiseLike {\n\t\treturn new Promise(\n\t\t\tfunction(resolve, reject) {\n\t\t\t\twindow.clearTimeout(timeout);\n\t\t\t\ttimeout = window.setTimeout(invokeLater, delay, this, args, resolve, reject);\n\t\t\t}\n\t\t);\n\t} as F;\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils.ts"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/src/MobxPromise.d.ts b/dist/src/MobxPromise.d.ts index 395a68b..7e937a2 100644 --- a/dist/src/MobxPromise.d.ts +++ b/dist/src/MobxPromise.d.ts @@ -25,6 +25,8 @@ export declare type MobxPromiseUnionType = ({ error: Error | undefined; }) & { peekStatus: MobxPromiseStatus; +} & { + label: string; }; export declare type MobxPromiseUnionTypeWithDefault = ({ status: 'pending'; @@ -49,6 +51,8 @@ export declare type MobxPromiseUnionTypeWithDefault = ({ error: Error | undefined; }) & { peekStatus: MobxPromiseStatus; +} & { + label: string; }; export declare type MobxPromiseInputUnion = PromiseLike | (() => PromiseLike) | MobxPromiseInputParams; export declare type MobxPromiseInputParams = { @@ -74,6 +78,7 @@ export declare type MobxPromiseInputParams = { * It will not be called for out-of-date promises. */ onError?: (error: Error) => void; + label?: string; }; export declare type MobxPromise_await = () => Array | MobxPromiseUnionType | MobxPromise>; export declare type MobxPromise_invoke = () => PromiseLike; @@ -83,6 +88,7 @@ export declare type MobxPromiseInputParamsWithDefault = { default: R; onResult?: (result: R) => void; onError?: (error: Error) => void; + label?: string; }; /** * MobxPromise provides an observable interface for a computed promise. @@ -91,7 +97,7 @@ export declare type MobxPromiseInputParamsWithDefault = { export declare class MobxPromiseImpl { static isPromiseLike(value: any): boolean; static normalizeInput(input: MobxPromiseInputParamsWithDefault): MobxPromiseInputParamsWithDefault; - static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R): MobxPromiseInputParamsWithDefault; + static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R, label?: string): MobxPromiseInputParamsWithDefault; static normalizeInput(input: MobxPromiseInputUnion): MobxPromiseInputParams; constructor(input: MobxPromiseInputUnion, defaultResult?: R); private await?; @@ -122,12 +128,12 @@ export declare class MobxPromiseImpl { } export declare type MobxPromiseFactory = { (input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault; - (input: MobxPromiseInputUnion, defaultResult: R): MobxPromiseUnionTypeWithDefault; + (input: MobxPromiseInputUnion, defaultResult: R | undefined, label?: string): MobxPromiseUnionTypeWithDefault; (input: MobxPromiseInputUnion): MobxPromiseUnionType; }; export declare const MobxPromise: { new (input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault; - new (input: MobxPromiseInputUnion, defaultResult: R_1): MobxPromiseUnionTypeWithDefault; + new (input: MobxPromiseInputUnion, defaultResult: R_1 | undefined, label?: string | undefined): MobxPromiseUnionTypeWithDefault; new (input: MobxPromiseInputUnion): MobxPromiseUnionType; }; export interface MobxPromise extends Pick, 'status' | 'error' | 'result' | 'isPending' | 'isError' | 'isComplete' | 'peekStatus'> { diff --git a/src/MobxPromise.ts b/src/MobxPromise.ts index 7302cfb..acf8467 100644 --- a/src/MobxPromise.ts +++ b/src/MobxPromise.ts @@ -43,6 +43,8 @@ export type MobxPromiseInputParams = { * It will not be called for out-of-date promises. */ onError?: (error: Error) => void, + + label?: string, }; export type MobxPromise_await = () => Array | MobxPromiseUnionType | MobxPromise>; export type MobxPromise_invoke = () => PromiseLike; @@ -52,6 +54,7 @@ export type MobxPromiseInputParamsWithDefault = { default: R, onResult?: (result: R) => void, onError?: (error: Error) => void, + label?: string, }; /** @@ -64,18 +67,19 @@ export class MobxPromiseImpl { } static normalizeInput(input: MobxPromiseInputParamsWithDefault): MobxPromiseInputParamsWithDefault; - static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R): MobxPromiseInputParamsWithDefault; + static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R, label?:string): MobxPromiseInputParamsWithDefault; static normalizeInput(input: MobxPromiseInputUnion): MobxPromiseInputParams; - static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R) { + static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R, label?:string) { if (typeof input === 'function') - return {invoke: input, default: defaultResult}; + return {invoke: input, default: defaultResult, label }; if (MobxPromiseImpl.isPromiseLike(input)) - return {invoke: () => input as PromiseLike, default: defaultResult}; + return {invoke: () => input as PromiseLike, default: defaultResult, label}; input = input as MobxPromiseInputParams; if (defaultResult !== undefined) - input = {...input, default: defaultResult}; + input = {...input, default: defaultResult, label}; + return input; } @@ -89,6 +93,9 @@ export class MobxPromiseImpl { this.defaultResult = norm.default; this.onResult = norm.onResult; this.onError = norm.onError; + + /*@ts-ignore */ + this.label = input.label; } private await?: MobxPromise_await; @@ -143,6 +150,17 @@ export class MobxPromiseImpl { @computed get result(): R | undefined { // checking status may trigger invoke + /*@ts-ignore*/ + if (this.isComplete === false) { + + if (localStorage.debugMP) { + debugger; + } + + /*@ts-ignore*/ + console.log(`${this.label} accessed prior to completion`, this); + } + if (this.isError || this.internalResult == null) return this.defaultResult; @@ -209,14 +227,14 @@ export class MobxPromiseImpl { export type MobxPromiseFactory = { // This provides more information for TypeScript code flow analysis (input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault; - (input: MobxPromiseInputUnion, defaultResult: R): MobxPromiseUnionTypeWithDefault; + (input: MobxPromiseInputUnion, defaultResult: R | undefined, label?:string): MobxPromiseUnionTypeWithDefault; (input: MobxPromiseInputUnion): MobxPromiseUnionType; }; export const MobxPromise = MobxPromiseImpl as { // This provides more information for TypeScript code flow analysis new(input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault; - new(input: MobxPromiseInputUnion, defaultResult: R): MobxPromiseUnionTypeWithDefault; + new(input: MobxPromiseInputUnion, defaultResult: R | undefined, label?:string): MobxPromiseUnionTypeWithDefault; new(input: MobxPromiseInputUnion): MobxPromiseUnionType; }; From 3f4a75755700fc045f7f0b94e0c3c9330f676636 Mon Sep 17 00:00:00 2001 From: alisman Date: Tue, 25 Oct 2022 10:49:07 -0400 Subject: [PATCH 2/2] Add label property and onPrematureRead hook --- dist/index.js | 9 +++------ dist/index.js.map | 2 +- dist/src/MobxPromise.d.ts | 4 ---- src/MobxPromise.ts | 12 ++++-------- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/dist/index.js b/dist/index.js index 232ed43..cf2000d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -298,15 +298,12 @@ var MobxPromiseImpl = function () { }, { key: "result", get: function get() { - // checking status may trigger invoke - /*@ts-ignore*/ + // we need to if (this.isComplete === false) { - if (localStorage.debugMP) { - debugger; - } /*@ts-ignore*/ - console.log(this.label + " accessed prior to completion", this); + if (this.onPrematureRead) this.onPrematureRead.call(this); } + // checking status may trigger invoke if (this.isError || this.internalResult == null) return this.defaultResult; return this.internalResult; } diff --git a/dist/index.js.map b/dist/index.js.map index 0efd9dd..7ab67a8 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 645502d9f99f7a6913eb","webpack:///./src/MobxPromise.ts","webpack:///external \"mobx\"","webpack:///./src/index.ts","webpack:///./src/utils.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,KAAK;QACL;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;QAEA;QACA;;;;;;;;;;;;;;;;;;;;;;;;;;AC7DA;AA2DA;;;;;IAIa,e;AAsBT,6BAAY,KAAZ,EAA6C,aAA7C,EAA8D;AAAA;;AAe9D;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;;AAAA;AACA;4BAAA;8BAAA;0BAAA;mBAA2B;AAA3B;AACA;4BAAA;8BAAA;0BAAA;mBAAkC;AAAlC;AAEY;4BAAA;8BAAA;0BAAA;mBAA2D;AAA3D;AACI;4BAAA;8BAAA;0BAAA;mBAA6B;AAA7B;AACA;4BAAA;8BAAA;0BAAA;mBAAgC;AAAhC;AAvBZ,8BAAmC,IAAnC;AAEA,YAAI,OAA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AExD,QAAI,OAAO,uBAAgB,KAAhB,EAAuB,QAAvB,CAAX;AACA,WAAO,QAAQ,KAAK,SAAb,GAAyB,KAAK,SAAL,CAAe,MAAf,GAAwB,CAAjD,GAAqD,KAA5D;AACA;AAJD;AAMA;;;;AAIA,SAAgB,iBAAhB,CAAoD,MAApD,EAA4D;AAE3D,SAAK,IAAI,GAAT,IAAgB,MAAhB,EACA;AACC,YAAI,OAAO,OAAO,wBAAP,CAAgC,MAAhC,EAAwC,GAAxC,CAAX;AACA,YAAI,QAAQ,KAAK,KAAL,YAAsB,yBAAlC,EACA;AACC,gBAAI,QAAQ,0BAAmB,KAAK,KAAxB,CAAZ;AACA,kBAAM,IAAN,GAAgB,GAAhB,SAAuB,MAAM,IAA7B;AACA;AACD;AACD;AAXD;AAaA;;;;;AAKA,SAAgB,aAAhB,CAA8E,MAA9E,EAAiG;AAAA,QAAT,KAAS,uEAAD,CAAC;;AAEhG,aAAS,WAAT,CACC,OADD,EAEC,IAFD,EAGC,OAHD,EAIC,MAJD,EAI2B;AAE1B,YACA;AACC,oBAAQ,OAAO,KAAP,CAAa,OAAb,EAAsB,IAAtB,CAAR;AACA,SAHD,CAIA,OAAO,CAAP,EACA;AACC,mBAAO,CAAP;AACA;AACD;AAED,QAAI,UAAU,CAAd;AACA,WAAO,YAAsB;AAAA,2CAAV,IAAU;AAAV,gBAAU;AAAA;;AAC5B,eAAO,IAAI,OAAJ,CACN,UAAS,OAAT,EAAkB,MAAlB,EAAwB;AACvB,mBAAO,YAAP,CAAoB,OAApB;AACA,sBAAU,OAAO,UAAP,CAAkB,WAAlB,EAA+B,KAA/B,EAAsC,IAAtC,EAA4C,IAA5C,EAAkD,OAAlD,EAA2D,MAA3D,CAAV;AACA,SAJK,CAAP;AAMK,KAPN;AAQA;AA3BD,sC","file":"index.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"mobx\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"mobx\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"index\"] = factory(require(\"mobx\"));\n\telse\n\t\troot[\"index\"] = factory(root[\"mobx\"]);\n})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_1__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 645502d9f99f7a6913eb","import {observable, action, computed, makeObservable} from \"mobx\";\n\n/**\n * This tagged union type describes the interoperability of MobxPromise properties.\n */\ntype MobxPromiseStatus = 'pending' | 'error' | 'complete';\nexport type MobxPromiseUnionType = (\n { status: 'pending', isPending: true, isError: false, isComplete: false, result: R | undefined, error: Error | undefined } |\n { status: 'error', isPending: false, isError: true, isComplete: false, result: R | undefined, error: Error } |\n { status: 'complete', isPending: false, isError: false, isComplete: true, result: R, error: Error | undefined }\n ) & { peekStatus: MobxPromiseStatus } & { label:string };\nexport type MobxPromiseUnionTypeWithDefault = (\n { status: 'pending', isPending: true, isError: false, isComplete: false, result: R, error: Error | undefined } |\n { status: 'error', isPending: false, isError: true, isComplete: false, result: R, error: Error } |\n { status: 'complete', isPending: false, isError: false, isComplete: true, result: R, error: Error | undefined }\n ) & { peekStatus: MobxPromiseStatus } & { label:string };\n\nexport type MobxPromiseInputUnion = PromiseLike | (() => PromiseLike) | MobxPromiseInputParams;\nexport type MobxPromiseInputParams = {\n /**\n * A function that returns a list of MobxPromise objects which are dependencies of the invoke function.\n */\n await?: MobxPromise_await,\n\n /**\n * A function that returns the async result or a promise for the async result.\n */\n invoke: MobxPromise_invoke,\n\n /**\n * Default result in place of undefined\n */\n default?: R,\n\n /**\n * A function that will be called when the latest promise from invoke() is resolved.\n * It will not be called for out-of-date promises.\n */\n onResult?: (result?: R) => void,\n\n /**\n * A function that will be called when the latest promise from invoke() is rejected.\n * It will not be called for out-of-date promises.\n */\n onError?: (error: Error) => void,\n\n label?: string,\n};\nexport type MobxPromise_await = () => Array | MobxPromiseUnionType | MobxPromise>;\nexport type MobxPromise_invoke = () => PromiseLike;\nexport type MobxPromiseInputParamsWithDefault = {\n await?: MobxPromise_await,\n invoke: MobxPromise_invoke,\n default: R,\n onResult?: (result: R) => void,\n onError?: (error: Error) => void,\n label?: string,\n};\n\n/**\n * MobxPromise provides an observable interface for a computed promise.\n * @author adufilie http://github.com/adufilie\n */\nexport class MobxPromiseImpl {\n static isPromiseLike(value: any) {\n return value != null && typeof value === 'object' && typeof value.then === 'function';\n }\n\n static normalizeInput(input: MobxPromiseInputParamsWithDefault): MobxPromiseInputParamsWithDefault;\n static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R, label?:string): MobxPromiseInputParamsWithDefault;\n static normalizeInput(input: MobxPromiseInputUnion): MobxPromiseInputParams;\n static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R, label?:string) {\n if (typeof input === 'function')\n return {invoke: input, default: defaultResult, label };\n\n if (MobxPromiseImpl.isPromiseLike(input))\n return {invoke: () => input as PromiseLike, default: defaultResult, label};\n\n input = input as MobxPromiseInputParams;\n if (defaultResult !== undefined)\n input = {...input, default: defaultResult, label};\n\n return input;\n }\n\n constructor(input: MobxPromiseInputUnion, defaultResult?: R) {\n\n makeObservable>(this);\n\n let norm = MobxPromiseImpl.normalizeInput(input, defaultResult);\n this.await = norm.await;\n this.invoke = norm.invoke;\n this.defaultResult = norm.default;\n this.onResult = norm.onResult;\n this.onError = norm.onError;\n\n /*@ts-ignore */\n this.label = input.label;\n }\n\n private await?: MobxPromise_await;\n private invoke: MobxPromise_invoke;\n private onResult?: (result?: R) => void;\n private onError?: (error: Error) => void;\n private defaultResult?: R;\n private invokeId: number = 0;\n private _latestInvokeId: number = 0;\n\n @observable private internalStatus: 'pending' | 'complete' | 'error' = 'pending';\n @observable.ref private internalResult?: R = undefined;\n @observable.ref private internalError?: Error = undefined;\n\n @computed get status(): 'pending' | 'complete' | 'error' {\n // wait until all MobxPromise dependencies are complete\n if (this.await)\n for (let status of this.await().map(mp => mp.status)) // track all statuses before returning\n if (status !== 'complete')\n return status;\n\n let status = this.internalStatus; // force mobx to track changes to internalStatus\n if (this.latestInvokeId != this.invokeId)\n status = 'pending';\n return status;\n }\n\n @computed get peekStatus(): 'pending' | 'complete' | 'error' {\n // check status without triggering invoke\n\n // check status of all MobxPromise dependencies\n if (this.await)\n for (let status of this.await().map(mp => mp.peekStatus))\n if (status !== 'complete')\n return status;\n\n // otherwise, return internal status\n return this.internalStatus;\n }\n\n @computed get isPending() {\n return this.status == 'pending';\n }\n\n @computed get isComplete() {\n return this.status == 'complete';\n }\n\n @computed get isError() {\n return this.status == 'error';\n }\n\n @computed get result(): R | undefined {\n // checking status may trigger invoke\n /*@ts-ignore*/\n if (this.isComplete === false) {\n\n if (localStorage.debugMP) {\n debugger;\n }\n\n /*@ts-ignore*/\n console.log(`${this.label} accessed prior to completion`, this);\n }\n\n if (this.isError || this.internalResult == null)\n return this.defaultResult;\n\n return this.internalResult;\n }\n\n @computed get error(): Error | undefined {\n // checking status may trigger invoke\n if (!this.isComplete && this.await)\n for (let error of this.await().map(mp => mp.error)) // track all errors before returning\n if (error)\n return error;\n\n return this.internalError;\n }\n\n /**\n * This lets mobx determine when to call this.invoke(),\n * taking advantage of caching based on observable property access tracking.\n */\n @computed\n private get latestInvokeId() {\n window.clearTimeout(this._latestInvokeId);\n let promise = this.invoke();\n let invokeId: number = window.setTimeout(() => this.setPending(invokeId, promise));\n return this._latestInvokeId = invokeId;\n }\n\n @action\n private setPending(invokeId: number, promise: PromiseLike) {\n this.invokeId = invokeId;\n promise.then(\n result => this.setComplete(invokeId, result),\n error => this.setError(invokeId, error)\n );\n this.internalStatus = 'pending';\n }\n\n @action\n private setComplete(invokeId: number, result: R) {\n if (invokeId === this.invokeId) {\n this.internalResult = result;\n this.internalError = undefined;\n this.internalStatus = 'complete';\n\n if (this.onResult)\n this.onResult(this.result); // may use defaultResult\n }\n }\n\n @action\n private setError(invokeId: number, error: Error) {\n if (invokeId === this.invokeId) {\n this.internalError = error;\n this.internalResult = undefined;\n this.internalStatus = 'error';\n\n if (this.onError)\n this.onError(error);\n }\n }\n}\n\nexport type MobxPromiseFactory = {\n // This provides more information for TypeScript code flow analysis\n (input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault;\n (input: MobxPromiseInputUnion, defaultResult: R | undefined, label?:string): MobxPromiseUnionTypeWithDefault;\n (input: MobxPromiseInputUnion): MobxPromiseUnionType;\n};\n\nexport const MobxPromise = MobxPromiseImpl as {\n // This provides more information for TypeScript code flow analysis\n new(input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault;\n new(input: MobxPromiseInputUnion, defaultResult: R | undefined, label?:string): MobxPromiseUnionTypeWithDefault;\n new(input: MobxPromiseInputUnion): MobxPromiseUnionType;\n};\n\nexport interface MobxPromise extends Pick, 'status' | 'error' | 'result' | 'isPending' | 'isError' | 'isComplete' | 'peekStatus'> {\n}\n\nexport default MobxPromise;\n\n\n\n// WEBPACK FOOTER //\n// ./src/MobxPromise.ts","module.exports = __WEBPACK_EXTERNAL_MODULE_1__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"mobx\"\n// module id = 1\n// module chunks = 0","export * from './MobxPromise';\nexport * from './utils';\n\nimport MobxPromise from './MobxPromise';\nexport default MobxPromise;\n\n\n\n// WEBPACK FOOTER //\n// ./src/index.ts","import {autorun, computed, getObserverTree, IComputedValue, IListenable, IObservable,\n_getAdministration, getAtom} from 'mobx';\nimport {MobxPromise} from \"./MobxPromise\";\n\n/**\n * A decorator for creating a @computed property that will be cached\n * after the first time it is accessed, even if it becomes unobserved later.\n * @param target\n * @param propertyKey\n * @param descriptor\n */\nexport function cached(target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor)\n{\n\tif (descriptor.get)\n\t{\n\t\tlet get = descriptor.get;\n\t\tdescriptor.get = function(...args:any[]) {\n\t\t\tconst atom = getAtom(this, propertyKey as string) as IObservable & IListenable;\n\t\t\t// to keep the cached value, add an observer if there are none\n\t\t\tif (!atom.isBeingObserved_)\n\t\t\t\tautorun(()=>atom);\n\n\t\t\treturn get.apply(this, args);\n\t\t};\n\t}\n\treturn descriptor;\n}\n\n/**\n * Checks if a property has observers.\n */\nexport function hasObservers(thing:T, property:keyof T)\n{\n\tlet tree = getObserverTree(thing, property as string);\n\treturn tree && tree.observers ? tree.observers.length > 0 : false;\n}\n\n/**\n * Update MobxPromise debug names to reflect their property names on a given object.\n * @param target An object which has properties that are MobxPromises.\n */\nexport function labelMobxPromises(target:T)\n{\n\tfor (let key in target)\n\t{\n\t\tlet desc = Object.getOwnPropertyDescriptor(target, key);\n\t\tif (desc && desc.value instanceof MobxPromise)\n\t\t{\n\t\t\tlet admin = _getAdministration(desc.value);\n\t\t\tadmin.name = `${key}(${admin.name})`;\n\t\t}\n\t}\n}\n\n/**\n * A function created with debounceAsync() returns a new Promise\n * every time, but only the last promise created before invoking the\n * original function will be resolved after a specified delay.\n */\nexport function debounceAsync PromiseLike>(invoke:F, delay = 0):F\n{\n\tfunction invokeLater(\n\t\tcontext:any,\n\t\targs:any[],\n\t\tresolve:(result:PromiseLike)=>void,\n\t\treject:(error:Error)=>void\n\t) {\n\t\ttry\n\t\t{\n\t\t\tresolve(invoke.apply(context, args));\n\t\t}\n\t\tcatch (e)\n\t\t{\n\t\t\treject(e);\n\t\t}\n\t}\n\n\tlet timeout = 0;\n\treturn function(...args:any[]):PromiseLike {\n\t\treturn new Promise(\n\t\t\tfunction(resolve, reject) {\n\t\t\t\twindow.clearTimeout(timeout);\n\t\t\t\ttimeout = window.setTimeout(invokeLater, delay, this, args, resolve, reject);\n\t\t\t}\n\t\t);\n\t} as F;\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils.ts"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap c19eb210d71c780681dc","webpack:///./src/MobxPromise.ts","webpack:///external \"mobx\"","webpack:///./src/index.ts","webpack:///./src/utils.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;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A7B;AACA;AACD;AACD;AAXD;AAaA;;;;;AAKA,SAAgB,aAAhB,CAA8E,MAA9E,EAAiG;AAAA,QAAT,KAAS,uEAAD,CAAC;;AAEhG,aAAS,WAAT,CACC,OADD,EAEC,IAFD,EAGC,OAHD,EAIC,MAJD,EAI2B;AAE1B,YACA;AACC,oBAAQ,OAAO,KAAP,CAAa,OAAb,EAAsB,IAAtB,CAAR;AACA,SAHD,CAIA,OAAO,CAAP,EACA;AACC,mBAAO,CAAP;AACA;AACD;AAED,QAAI,UAAU,CAAd;AACA,WAAO,YAAsB;AAAA,2CAAV,IAAU;AAAV,gBAAU;AAAA;;AAC5B,eAAO,IAAI,OAAJ,CACN,UAAS,OAAT,EAAkB,MAAlB,EAAwB;AACvB,mBAAO,YAAP,CAAoB,OAApB;AACA,sBAAU,OAAO,UAAP,CAAkB,WAAlB,EAA+B,KAA/B,EAAsC,IAAtC,EAA4C,IAA5C,EAAkD,OAAlD,EAA2D,MAA3D,CAAV;AACA,SAJK,CAAP;AAMK,KAPN;AAQA;AA3BD,sC","file":"index.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"mobx\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"mobx\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"index\"] = factory(require(\"mobx\"));\n\telse\n\t\troot[\"index\"] = factory(root[\"mobx\"]);\n})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_1__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap c19eb210d71c780681dc","import {observable, action, computed, makeObservable} from \"mobx\";\n\n/**\n * This tagged union type describes the interoperability of MobxPromise properties.\n */\ntype MobxPromiseStatus = 'pending' | 'error' | 'complete';\nexport type MobxPromiseUnionType = (\n { status: 'pending', isPending: true, isError: false, isComplete: false, result: R | undefined, error: Error | undefined } |\n { status: 'error', isPending: false, isError: true, isComplete: false, result: R | undefined, error: Error } |\n { status: 'complete', isPending: false, isError: false, isComplete: true, result: R, error: Error | undefined }\n ) & { peekStatus: MobxPromiseStatus };\nexport type MobxPromiseUnionTypeWithDefault = (\n { status: 'pending', isPending: true, isError: false, isComplete: false, result: R, error: Error | undefined } |\n { status: 'error', isPending: false, isError: true, isComplete: false, result: R, error: Error } |\n { status: 'complete', isPending: false, isError: false, isComplete: true, result: R, error: Error | undefined }\n ) & { peekStatus: MobxPromiseStatus };\n\nexport type MobxPromiseInputUnion = PromiseLike | (() => PromiseLike) | MobxPromiseInputParams;\nexport type MobxPromiseInputParams = {\n /**\n * A function that returns a list of MobxPromise objects which are dependencies of the invoke function.\n */\n await?: MobxPromise_await,\n\n /**\n * A function that returns the async result or a promise for the async result.\n */\n invoke: MobxPromise_invoke,\n\n /**\n * Default result in place of undefined\n */\n default?: R,\n\n /**\n * A function that will be called when the latest promise from invoke() is resolved.\n * It will not be called for out-of-date promises.\n */\n onResult?: (result?: R) => void,\n\n /**\n * A function that will be called when the latest promise from invoke() is rejected.\n * It will not be called for out-of-date promises.\n */\n onError?: (error: Error) => void,\n\n label?: string,\n};\nexport type MobxPromise_await = () => Array | MobxPromiseUnionType | MobxPromise>;\nexport type MobxPromise_invoke = () => PromiseLike;\nexport type MobxPromiseInputParamsWithDefault = {\n await?: MobxPromise_await,\n invoke: MobxPromise_invoke,\n default: R,\n onResult?: (result: R) => void,\n onError?: (error: Error) => void,\n label?: string,\n};\n\n/**\n * MobxPromise provides an observable interface for a computed promise.\n * @author adufilie http://github.com/adufilie\n */\nexport class MobxPromiseImpl {\n static isPromiseLike(value: any) {\n return value != null && typeof value === 'object' && typeof value.then === 'function';\n }\n\n static normalizeInput(input: MobxPromiseInputParamsWithDefault): MobxPromiseInputParamsWithDefault;\n static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R, label?:string): MobxPromiseInputParamsWithDefault;\n static normalizeInput(input: MobxPromiseInputUnion): MobxPromiseInputParams;\n static normalizeInput(input: MobxPromiseInputUnion, defaultResult?: R, label?:string) {\n if (typeof input === 'function')\n return {invoke: input, default: defaultResult, label };\n\n if (MobxPromiseImpl.isPromiseLike(input))\n return {invoke: () => input as PromiseLike, default: defaultResult, label};\n\n input = input as MobxPromiseInputParams;\n if (defaultResult !== undefined)\n input = {...input, default: defaultResult, label};\n\n return input;\n }\n\n constructor(input: MobxPromiseInputUnion, defaultResult?: R) {\n\n makeObservable>(this);\n\n let norm = MobxPromiseImpl.normalizeInput(input, defaultResult);\n this.await = norm.await;\n this.invoke = norm.invoke;\n this.defaultResult = norm.default;\n this.onResult = norm.onResult;\n this.onError = norm.onError;\n\n /*@ts-ignore */\n this.label = input.label;\n }\n\n private await?: MobxPromise_await;\n private invoke: MobxPromise_invoke;\n private onResult?: (result?: R) => void;\n private onError?: (error: Error) => void;\n private defaultResult?: R;\n private invokeId: number = 0;\n private _latestInvokeId: number = 0;\n\n @observable private internalStatus: 'pending' | 'complete' | 'error' = 'pending';\n @observable.ref private internalResult?: R = undefined;\n @observable.ref private internalError?: Error = undefined;\n\n @computed get status(): 'pending' | 'complete' | 'error' {\n // wait until all MobxPromise dependencies are complete\n if (this.await)\n for (let status of this.await().map(mp => mp.status)) // track all statuses before returning\n if (status !== 'complete')\n return status;\n\n let status = this.internalStatus; // force mobx to track changes to internalStatus\n if (this.latestInvokeId != this.invokeId)\n status = 'pending';\n return status;\n }\n\n @computed get peekStatus(): 'pending' | 'complete' | 'error' {\n // check status without triggering invoke\n\n // check status of all MobxPromise dependencies\n if (this.await)\n for (let status of this.await().map(mp => mp.peekStatus))\n if (status !== 'complete')\n return status;\n\n // otherwise, return internal status\n return this.internalStatus;\n }\n\n @computed get isPending() {\n return this.status == 'pending';\n }\n\n @computed get isComplete() {\n return this.status == 'complete';\n }\n\n @computed get isError() {\n return this.status == 'error';\n }\n\n @computed get result(): R | undefined {\n\n // we need to\n if (this.isComplete === false) {\n /*@ts-ignore*/\n if (this.onPrematureRead) this.onPrematureRead.call(this);\n }\n\n // checking status may trigger invoke\n if (this.isError || this.internalResult == null)\n return this.defaultResult;\n\n return this.internalResult;\n }\n\n @computed get error(): Error | undefined {\n // checking status may trigger invoke\n if (!this.isComplete && this.await)\n for (let error of this.await().map(mp => mp.error)) // track all errors before returning\n if (error)\n return error;\n\n return this.internalError;\n }\n\n /**\n * This lets mobx determine when to call this.invoke(),\n * taking advantage of caching based on observable property access tracking.\n */\n @computed\n private get latestInvokeId() {\n window.clearTimeout(this._latestInvokeId);\n let promise = this.invoke();\n let invokeId: number = window.setTimeout(() => this.setPending(invokeId, promise));\n return this._latestInvokeId = invokeId;\n }\n\n @action\n private setPending(invokeId: number, promise: PromiseLike) {\n this.invokeId = invokeId;\n promise.then(\n result => this.setComplete(invokeId, result),\n error => this.setError(invokeId, error)\n );\n this.internalStatus = 'pending';\n }\n\n @action\n private setComplete(invokeId: number, result: R) {\n if (invokeId === this.invokeId) {\n this.internalResult = result;\n this.internalError = undefined;\n this.internalStatus = 'complete';\n\n if (this.onResult)\n this.onResult(this.result); // may use defaultResult\n }\n }\n\n @action\n private setError(invokeId: number, error: Error) {\n if (invokeId === this.invokeId) {\n this.internalError = error;\n this.internalResult = undefined;\n this.internalStatus = 'error';\n\n if (this.onError)\n this.onError(error);\n }\n }\n}\n\nexport type MobxPromiseFactory = {\n // This provides more information for TypeScript code flow analysis\n (input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault;\n (input: MobxPromiseInputUnion, defaultResult: R | undefined, label?:string): MobxPromiseUnionTypeWithDefault;\n (input: MobxPromiseInputUnion): MobxPromiseUnionType;\n};\n\nexport const MobxPromise = MobxPromiseImpl as {\n // This provides more information for TypeScript code flow analysis\n new(input: MobxPromiseInputParamsWithDefault): MobxPromiseUnionTypeWithDefault;\n new(input: MobxPromiseInputUnion, defaultResult: R | undefined, label?:string): MobxPromiseUnionTypeWithDefault;\n new(input: MobxPromiseInputUnion): MobxPromiseUnionType;\n};\n\nexport interface MobxPromise extends Pick, 'status' | 'error' | 'result' | 'isPending' | 'isError' | 'isComplete' | 'peekStatus'> {\n}\n\nexport default MobxPromise;\n\n\n\n// WEBPACK FOOTER //\n// ./src/MobxPromise.ts","module.exports = __WEBPACK_EXTERNAL_MODULE_1__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"mobx\"\n// module id = 1\n// module chunks = 0","export * from './MobxPromise';\nexport * from './utils';\n\nimport MobxPromise from './MobxPromise';\nexport default MobxPromise;\n\n\n\n// WEBPACK FOOTER //\n// ./src/index.ts","import {autorun, computed, getObserverTree, IComputedValue, IListenable, IObservable,\n_getAdministration, getAtom} from 'mobx';\nimport {MobxPromise} from \"./MobxPromise\";\n\n/**\n * A decorator for creating a @computed property that will be cached\n * after the first time it is accessed, even if it becomes unobserved later.\n * @param target\n * @param propertyKey\n * @param descriptor\n */\nexport function cached(target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor)\n{\n\tif (descriptor.get)\n\t{\n\t\tlet get = descriptor.get;\n\t\tdescriptor.get = function(...args:any[]) {\n\t\t\tconst atom = getAtom(this, propertyKey as string) as IObservable & IListenable;\n\t\t\t// to keep the cached value, add an observer if there are none\n\t\t\tif (!atom.isBeingObserved_)\n\t\t\t\tautorun(()=>atom);\n\n\t\t\treturn get.apply(this, args);\n\t\t};\n\t}\n\treturn descriptor;\n}\n\n/**\n * Checks if a property has observers.\n */\nexport function hasObservers(thing:T, property:keyof T)\n{\n\tlet tree = getObserverTree(thing, property as string);\n\treturn tree && tree.observers ? tree.observers.length > 0 : false;\n}\n\n/**\n * Update MobxPromise debug names to reflect their property names on a given object.\n * @param target An object which has properties that are MobxPromises.\n */\nexport function labelMobxPromises(target:T)\n{\n\tfor (let key in target)\n\t{\n\t\tlet desc = Object.getOwnPropertyDescriptor(target, key);\n\t\tif (desc && desc.value instanceof MobxPromise)\n\t\t{\n\t\t\tlet admin = _getAdministration(desc.value);\n\t\t\tadmin.name = `${key}(${admin.name})`;\n\t\t}\n\t}\n}\n\n/**\n * A function created with debounceAsync() returns a new Promise\n * every time, but only the last promise created before invoking the\n * original function will be resolved after a specified delay.\n */\nexport function debounceAsync PromiseLike>(invoke:F, delay = 0):F\n{\n\tfunction invokeLater(\n\t\tcontext:any,\n\t\targs:any[],\n\t\tresolve:(result:PromiseLike)=>void,\n\t\treject:(error:Error)=>void\n\t) {\n\t\ttry\n\t\t{\n\t\t\tresolve(invoke.apply(context, args));\n\t\t}\n\t\tcatch (e)\n\t\t{\n\t\t\treject(e);\n\t\t}\n\t}\n\n\tlet timeout = 0;\n\treturn function(...args:any[]):PromiseLike {\n\t\treturn new Promise(\n\t\t\tfunction(resolve, reject) {\n\t\t\t\twindow.clearTimeout(timeout);\n\t\t\t\ttimeout = window.setTimeout(invokeLater, delay, this, args, resolve, reject);\n\t\t\t}\n\t\t);\n\t} as F;\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils.ts"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/src/MobxPromise.d.ts b/dist/src/MobxPromise.d.ts index 7e937a2..7c18111 100644 --- a/dist/src/MobxPromise.d.ts +++ b/dist/src/MobxPromise.d.ts @@ -25,8 +25,6 @@ export declare type MobxPromiseUnionType = ({ error: Error | undefined; }) & { peekStatus: MobxPromiseStatus; -} & { - label: string; }; export declare type MobxPromiseUnionTypeWithDefault = ({ status: 'pending'; @@ -51,8 +49,6 @@ export declare type MobxPromiseUnionTypeWithDefault = ({ error: Error | undefined; }) & { peekStatus: MobxPromiseStatus; -} & { - label: string; }; export declare type MobxPromiseInputUnion = PromiseLike | (() => PromiseLike) | MobxPromiseInputParams; export declare type MobxPromiseInputParams = { diff --git a/src/MobxPromise.ts b/src/MobxPromise.ts index acf8467..5f297e9 100644 --- a/src/MobxPromise.ts +++ b/src/MobxPromise.ts @@ -149,18 +149,14 @@ export class MobxPromiseImpl { } @computed get result(): R | undefined { - // checking status may trigger invoke - /*@ts-ignore*/ - if (this.isComplete === false) { - - if (localStorage.debugMP) { - debugger; - } + // we need to + if (this.isComplete === false) { /*@ts-ignore*/ - console.log(`${this.label} accessed prior to completion`, this); + if (this.onPrematureRead) this.onPrematureRead.call(this); } + // checking status may trigger invoke if (this.isError || this.internalResult == null) return this.defaultResult;