Skip to content

Commit

Permalink
feat(plugin): add sync option to @cordova for sync functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tlancina committed Feb 9, 2016
1 parent 5bed810 commit 17e3827
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion dist/plugins/plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/plugins/plugin.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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];
}

Expand Down

0 comments on commit 17e3827

Please sign in to comment.