mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-05-02 00:07:23 +08:00
Demo
This commit is contained in:
+16
@@ -20,3 +20,19 @@ export const promisify = (pluginRef, methodName, successIndex, errorIndex) => {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const wrap = (pluginRef, methodName, successIndex=null, errorIndex=null) => {
|
||||
return (...args) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if(successIndex) {
|
||||
args[successIndex] = resolve;
|
||||
}
|
||||
if(errorIndex) {
|
||||
args[errorIndex] = reject;
|
||||
}
|
||||
|
||||
get(window, pluginRef)[methodName].apply(this, args);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user