-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhenx.js
More file actions
77 lines (67 loc) · 1.56 KB
/
whenx.js
File metadata and controls
77 lines (67 loc) · 1.56 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
whenx v1.1.7
https://github.com/cdll/whenx
Released under the MIT License.
*/
var whenx = (function () {
'use strict';
var version = "1.1.7";
var thenx= (name, opts= {})=>{
return new Promise((resolve, reject)=>{
var method= wx[name]( Object.assign(opts, {
success: res=> resolve(res)
,fail: err=> reject(err)
,complete: opts.complete
}) );
//hook: add progress function hook for native returned task support
if(opts.progress){
if(typeof opts.progress== "function"){
var task= method;
Function.call(opts.progress, task);
}
else console.warn(`[whenx]progress must be a function to call with task but not: ${typeof(opts.progress)}`);
}
})
};
/**
* @desc
* @module Function
* @param {string} name
* @param {object} opts
* @return {promise}
*/
var thenx_1= thenx;
var thenx$1 = ({
default: thenx_1,
__moduleExports: thenx_1
});
var whenx= function(_wx= {}){
for(let k in wx){
if(typeof(wx[k]) === 'function'){
// console.info(`func: ${k}`)
_wx[k]= (v)=> thenx_1.call(this, k, v);
}
else{
// console.info(`val: ${k}`)
_wx[k]= wx[k];
}
}
return _wx
}();
/**
* @desc
* @module Object
* @return {object}
*/
var whenx_1= whenx;
var whenx$1 = ({
default: whenx_1,
__moduleExports: whenx_1
});
var main$1= whenx$1;
// console.info(main)
main$1.whenx= whenx$1;
main$1.thenx= thenx$1;
main$1._version_= version;
return main$1;
}());