Skip to content

Commit

Permalink
feat(plugin): add event wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ihadeed committed Mar 13, 2016
1 parent 21dba10 commit 0d1bd13
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
40 changes: 40 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'build_bundle' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild_bundle', 'build_bundle', 'postbuild_bundle' ]
5 info prebuild_bundle [email protected]
6 info build_bundle [email protected]
7 verbose unsafe-perm in lifecycle true
8 info [email protected] Failed to exec build_bundle script
9 verbose stack Error: [email protected] build_bundle: `npm run-script build && browserify dist/index.js > dist/ionic.native.js`
9 verbose stack Exit status 1
9 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:214:16)
9 verbose stack at emitTwo (events.js:87:13)
9 verbose stack at EventEmitter.emit (events.js:172:7)
9 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:24:14)
9 verbose stack at emitTwo (events.js:87:13)
9 verbose stack at ChildProcess.emit (events.js:172:7)
9 verbose stack at maybeClose (internal/child_process.js:818:16)
9 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
10 verbose pkgid [email protected]
11 verbose cwd C:\Users\Ibrahim\WebstormProjects\ionic-native
12 error Windows_NT 10.0.10586
13 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build_bundle"
14 error node v4.2.4
15 error npm v2.14.12
16 error code ELIFECYCLE
17 error [email protected] build_bundle: `npm run-script build && browserify dist/index.js > dist/ionic.native.js`
17 error Exit status 1
18 error Failed at the [email protected] build_bundle script 'npm run-script build && browserify dist/index.js > dist/ionic.native.js'.
18 error This is most likely a problem with the ionic-native package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error npm run-script build && browserify dist/index.js > dist/ionic.native.js
18 error You can get their info via:
18 error npm owner ls ionic-native
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]
25 changes: 21 additions & 4 deletions src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ function wrapObservable(pluginObj:any, methodName:string, args:any[], opts:any =
});
}

/**
* Wrap the event with an observable
* @param event
* @returns {Observable}
*/
function wrapEventObservable (event : string) : Observable<any> {
return new Observable(observer => {
let callback = (status : any) => observer.next(status);
window.addEventListener(event, callback, false);
return () => window.removeEventListener(event, callback, false);
});
}

/**
* @private
* @param pluginObj
Expand All @@ -151,13 +164,17 @@ function wrapObservable(pluginObj:any, methodName:string, args:any[], opts:any =
export const wrap = function(pluginObj:any, methodName:string, opts:any = {}) {
return (...args) => {

if (opts.sync){
if (opts.sync)
return callCordovaPlugin(pluginObj, methodName, args, opts);
} else if (opts.observable) {

else if (opts.observable)
return wrapObservable(pluginObj, methodName, args, opts);
} else {

else if (opts.eventObservable && opts.event)
return wrapEventObservable(opts.event);

else
return wrapPromise(pluginObj, methodName, args, opts);
}
}
};

Expand Down

0 comments on commit 0d1bd13

Please sign in to comment.