feat(plugin): add sync option to @Cordova for sync functions

This commit is contained in:
Tim Lancina 2016-02-09 14:45:57 -06:00
parent 5bed810624
commit 17e3827831
3 changed files with 11 additions and 6 deletions

View File

@ -114,7 +114,10 @@ exports.wrap = function (pluginObj, methodName, opts) {
for (var _i = 0; _i < arguments.length; _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);
}
else {

File diff suppressed because one or more lines are too long

View File

@ -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
// to our promise resolve/reject handlers.
// 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]
args.unshift(reject);
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 = {}) {
return (...args) => {
if(opts.observable) {
if (opts.sync){
return callCordovaPlugin(pluginObj, methodName, args, opts);
} else if (opts.observable) {
return wrapObservable(pluginObj, methodName, args, opts);
} else {
return wrapPromise(pluginObj, methodName, args, opts);
@ -136,7 +138,7 @@ export function Plugin(config) {
return function(cls) {
// Add these fields to the class
for(let k in config) {
for (let k in config) {
cls[k] = config[k];
}