mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-19 16:52:53 +08:00
feat(plugin): add sync option to @Cordova for sync functions
This commit is contained in:
parent
5bed810624
commit
17e3827831
5
dist/plugins/plugin.js
vendored
5
dist/plugins/plugin.js
vendored
@ -114,7 +114,10 @@ exports.wrap = function (pluginObj, methodName, opts) {
|
|||||||
for (var _i = 0; _i < arguments.length; _i++) {
|
for (var _i = 0; _i < arguments.length; _i++) {
|
||||||
args[_i - 0] = arguments[_i];
|
args[_i - 0] = arguments[_i];
|
||||||
}
|
}
|
||||||
if (opts.observable) {
|
if (opts.sync) {
|
||||||
|
return callCordovaPlugin(pluginObj, methodName, args, opts);
|
||||||
|
}
|
||||||
|
else if (opts.observable) {
|
||||||
return wrapObservable(pluginObj, methodName, args, opts);
|
return wrapObservable(pluginObj, methodName, args, opts);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
2
dist/plugins/plugin.js.map
vendored
2
dist/plugins/plugin.js.map
vendored
File diff suppressed because one or more lines are too long
@ -32,12 +32,12 @@ export const cordovaWarn = function(pluginName: string, method: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function callCordovaPlugin(pluginObj:any, methodName:string, args:any[], opts:any={}, resolve:any, reject:any) {
|
function callCordovaPlugin(pluginObj:any, methodName:string, args:any[], opts:any={}, resolve?: Function, reject?: Function) {
|
||||||
// Try to figure out where the success/error callbacks need to be bound
|
// Try to figure out where the success/error callbacks need to be bound
|
||||||
// to our promise resolve/reject handlers.
|
// to our promise resolve/reject handlers.
|
||||||
|
|
||||||
// If the plugin method expects myMethod(success, err, options)
|
// If the plugin method expects myMethod(success, err, options)
|
||||||
if(opts.callbackOrder == 'reverse') {
|
if (opts.callbackOrder == 'reverse') {
|
||||||
// Get those arguments in the order [resolve, reject, ...restOfArgs]
|
// Get those arguments in the order [resolve, reject, ...restOfArgs]
|
||||||
args.unshift(reject);
|
args.unshift(reject);
|
||||||
args.unshift(resolve);
|
args.unshift(resolve);
|
||||||
@ -121,7 +121,9 @@ function wrapObservable(pluginObj:any, methodName:string, args:any[], opts:any =
|
|||||||
export const wrap = function(pluginObj:any, methodName:string, opts:any = {}) {
|
export const wrap = function(pluginObj:any, methodName:string, opts:any = {}) {
|
||||||
return (...args) => {
|
return (...args) => {
|
||||||
|
|
||||||
if(opts.observable) {
|
if (opts.sync){
|
||||||
|
return callCordovaPlugin(pluginObj, methodName, args, opts);
|
||||||
|
} else if (opts.observable) {
|
||||||
return wrapObservable(pluginObj, methodName, args, opts);
|
return wrapObservable(pluginObj, methodName, args, opts);
|
||||||
} else {
|
} else {
|
||||||
return wrapPromise(pluginObj, methodName, args, opts);
|
return wrapPromise(pluginObj, methodName, args, opts);
|
||||||
@ -136,7 +138,7 @@ export function Plugin(config) {
|
|||||||
return function(cls) {
|
return function(cls) {
|
||||||
|
|
||||||
// Add these fields to the class
|
// Add these fields to the class
|
||||||
for(let k in config) {
|
for (let k in config) {
|
||||||
cls[k] = config[k];
|
cls[k] = config[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user