-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (37 loc) · 1.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require('harmony-reflect');
var promisify = require('es6-promisify');
var isPromise = require('is-promise');
function createInterimProxy(targetPromise) {
'use strict';
return Proxy(targetPromise, {
get: function(target, name) {
if (targetPromise[name] !== void 0) {
// Object should primarily behave as promise,
// including prototypes and getters
const ref = targetPromise[name];
if (typeof ref === 'function') {
return function() {
return ref.apply(targetPromise, arguments);
};
} else {
return ref;
}
}
return function() {
return createInterimProxy(targetPromise.then((obj) => {
const ref = obj[name];
if (typeof ref === 'function') {
return ref.apply(obj, arguments);
} else {
return ref;
}
}));
};
}
});
}
module.exports = function(fn) {
'use strict';
const promise = isPromise(fn) ? fn : promisify(fn)();
return createInterimProxy(promise);
};