mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-05-02 00:07:23 +08:00
Moving to a class-based approach
This commit is contained in:
+16
@@ -1,6 +1,22 @@
|
||||
declare var window;
|
||||
|
||||
declare var Promise;
|
||||
|
||||
export function get(obj, path) {
|
||||
for (var i=0, path = path.split('.'), len = path.length; i < len; i++) {
|
||||
obj = obj[path[i]];
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
export const promisify = (pluginRef, methodName, successIndex, errorIndex) => {
|
||||
return (...args) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
args[successIndex] = resolve;
|
||||
args[errorIndex] = reject;
|
||||
|
||||
get(window, pluginRef)[methodName].apply(this, args);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user