forked from maichong/labrador
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
52 lines (44 loc) · 1 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
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @copyright Maichong Software Ltd. 2016 http://maichong.it
* @date 2016-09-26
* @author Liang <[email protected]>
*/
'use strict';
const labrador = module.exports = {};
labrador.default = labrador;
labrador.Component = require('./component');
labrador.__defineGetter__('app', function () {
return getApp();
});
const noPromise = {
some: true
};
function forEach(key) {
if (noPromise[key] || key.substr(0, 2) == 'on' || /\w+Sync$/.test(key)) {
if (wx.__lookupGetter__(key)) {
labrador.__defineGetter__(key, function () {
return wx[key];
});
} else {
labrador[key] = wx;
}
return;
}
labrador[key] = function (obj) {
obj = obj || {};
return new Promise(function (resolve, reject) {
obj.success = resolve;
obj.fail = function (res) {
if (res && res.errMsg) {
reject(new Error(res.errMsg))
} else {
reject(res);
}
};
wx[key](obj);
});
}
}
for (let key in wx) {
forEach(key);
}