UNPKG

1.52 kBJavaScriptView Raw
1/*
2 whenx v1.1.5
3 https://github.com/cdll/whenx
4 Released under the MIT License.
5*/
6var whenx = (function () {
7 'use strict';
8
9 var version = "1.1.5";
10
11 var thenx= (name, opts= {})=>{
12 return new Promise((resolve, reject)=>{
13 var method= wx[name]( Object.assign(opts, {
14 success: res=> resolve(res)
15 ,fail: err=> reject(err)
16 ,complete: opts.complete
17 }) );
18 if(opts.progress){
19 if(typeof opts.progress== "function"){
20 var task= method;
21 Function.call(opts.progress, task);
22 }
23 else console.warn(`[whenx]progress must be a function to call with task but not: ${typeof(opts.progress)}`);
24 }
25 })
26 };
27
28 /**
29 * @desc
30 * @module Function
31 * @param {string} name
32 * @param {object} opts
33 * @return {promise}
34 */
35 var thenx_1= thenx;
36
37 var thenx$1 = ({
38 default: thenx_1,
39 __moduleExports: thenx_1
40 });
41
42 var whenx= function(_wx= {}){
43 for(let k in wx){
44 if(typeof(wx[k]) === 'function'){
45 // console.info(`func: ${k}`)
46 _wx[k]= (v)=> thenx_1.call(this, k, v);
47 }
48 else{
49 // console.info(`val: ${k}`)
50 _wx[k]= wx[k];
51 }
52 }
53 return _wx
54 }();
55
56 /**
57 * @desc
58 * @module Object
59 * @return {object}
60 */
61 var whenx_1= whenx;
62
63 var whenx$1 = ({
64 default: whenx_1,
65 __moduleExports: whenx_1
66 });
67
68 var main$1= whenx$1;
69 // console.info(main)
70 main$1.whenx= whenx$1;
71 main$1.thenx= thenx$1;
72 main$1._version_= version;
73
74 return main$1;
75
76}());