UNPKG

1.6 kBJavaScriptView Raw
1/*
2 whenx v1.1.7
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.7";
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 //hook: add progress function hook for native returned task support
19 if(opts.progress){
20 if(typeof opts.progress== "function"){
21 var task= method;
22 Function.call(opts.progress, task);
23 }
24 else console.warn(`[whenx]progress must be a function to call with task but not: ${typeof(opts.progress)}`);
25 }
26 })
27 };
28
29 /**
30 * @desc
31 * @module Function
32 * @param {string} name
33 * @param {object} opts
34 * @return {promise}
35 */
36 var thenx_1= thenx;
37
38 var thenx$1 = ({
39 default: thenx_1,
40 __moduleExports: thenx_1
41 });
42
43 var whenx= function(_wx= {}){
44 for(let k in wx){
45 if(typeof(wx[k]) === 'function'){
46 // console.info(`func: ${k}`)
47 _wx[k]= (v)=> thenx_1.call(this, k, v);
48 }
49 else{
50 // console.info(`val: ${k}`)
51 _wx[k]= wx[k];
52 }
53 }
54 return _wx
55 }();
56
57 /**
58 * @desc
59 * @module Object
60 * @return {object}
61 */
62 var whenx_1= whenx;
63
64 var whenx$1 = ({
65 default: whenx_1,
66 __moduleExports: whenx_1
67 });
68
69 var main$1= whenx$1;
70 // console.info(main)
71 main$1.whenx= whenx$1;
72 main$1.thenx= thenx$1;
73 main$1._version_= version;
74
75 return main$1;
76
77}());