/******************************************************************
 MIT License http://www.opensource.org/licenses/mit-license.php
 Author Mora <qiuzhongleiabc@126.com> (https://github.com/qiu8310)
*******************************************************************/ import './polyfill' ; const PROMISABLE = { FUNCS : [ ] , KLASS : { } } ; const wxp = { } ; Object . getOwnPropertyNames ( wx ) . forEach ( key => { let desc = Object . getOwnPropertyDescriptor ( wx , key ) ; if ( desc ) { if ( PROMISABLE . FUNCS . indexOf ( key ) >= 0 ) { Object . defineProperty ( wxp , key , { configurable : desc . configurable , enumerable : desc . enumerable , get ( ) { return wxpromisify ( wx [ key ] , wx ) ; } } ) ; } else { Object . defineProperty ( wxp , key , desc ) ; } } } ) ; function wxpromisify < T > ( func , context ? , callbackIndex = 0 ) { return ( ... args ) => new Promise ( ( resolve , reject ) => { let { success , fail , complete , ... arg } = ( args [ callbackIndex ] || { } ) as any ; args [ callbackIndex ] = { ... arg , success : ( res ) => { resolve ( res ) ; if ( success ) success ( res ) ; } , fail : ( err ) => { reject ( err ) ; if ( fail ) fail ( err ) ; } , complete } ; func . call ( context , ... args ) ; } ) ; } export default wxp ;