mirror of
https://github.com/zotero/zotero.git
synced 2026-09-29 01:41:24 +00:00
Add functional shim for Zotero.Promise.method()
For translation.
This commit is contained in:
parent
da18a465c5
commit
d035c94ae3
1 changed files with 22 additions and 3 deletions
|
|
@ -13,10 +13,29 @@ export class BluebirdShimPromise extends Promise {
|
|||
}
|
||||
|
||||
static method(fn) {
|
||||
// TEMP: "Implement" this with a stub until we update zotero/translate
|
||||
// Don't bother with synchronous resolution - this is just enough to get the client to load
|
||||
// ONLY exists for translator code that needs synchronous resolution.
|
||||
// Please don't use this anywhere else. It's a bad idea!
|
||||
return function (...args) {
|
||||
return Promise.resolve(fn.apply(this, args));
|
||||
try {
|
||||
let returnValue = fn.apply(this, args);
|
||||
let promise;
|
||||
let isResolved = false;
|
||||
if (returnValue && returnValue.then) {
|
||||
promise = returnValue;
|
||||
}
|
||||
else {
|
||||
promise = Promise.resolve(returnValue);
|
||||
isResolved = true;
|
||||
}
|
||||
if (typeof promise.isResolved === 'undefined') {
|
||||
promise.then(() => isResolved = true, () => {});
|
||||
promise.isResolved = () => isResolved;
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue