UNPKG

1.49 kBJavaScriptView Raw
1/*
2 whenx v0.2.0
3 https://github.com/cdll/whenx
4 Released under the MIT License.
5*/
6var whenx = (function () {
7 'use strict';
8
9 var version = "0.2.0";
10
11 const thenx= (name, opts= {})=>{
12 // console.info(`func: ${name}`)
13 return new Promise((resolve, reject)=>{
14 const method= wx[name]( Object.assign(opts, {
15 success: res=> resolve(res)
16 ,fail: err=> reject(err)
17 ,complete: opts.complete
18 }) );
19 if(opts.progress){
20 if(typeof opts.progress== "function"){
21 let 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 const whenx= function(){
44 let _wx= {};
45 for(let k in wx){
46 if(typeof wx[k] === 'function'){
47 // console.info(`func: ${k}`)
48 _wx[k]= (v)=> thenx_1.call(this, k, v);
49 }
50 }
51 return _wx
52 }();
53
54 /**
55 * @desc
56 * @module Object
57 * @return {bject}
58 */
59 var whenx_1= whenx;
60
61 var whenx$1 = ({
62 default: whenx_1,
63 __moduleExports: whenx_1
64 });
65
66 let main$1= whenx$1;
67 // console.info(main)
68 main$1.whenx= whenx$1;
69 main$1.thenx= thenx$1;
70 main$1.version= version;
71
72 return main$1;
73
74}());