Skip to content

Instantly share code, notes, and snippets.

@robwormald
Created November 18, 2015 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robwormald/877a496039909dadf9cc to your computer and use it in GitHub Desktop.
Save robwormald/877a496039909dadf9cc to your computer and use it in GitHub Desktop.
const promisifyCordova = (pluginName:string, methodName:string) => {
return (...args) => {
return new Promise((resolve, reject) => {
cordova.exec(resolve, reject, pluginName, methodName, args);
})
}
}
const observablifyCordova = (pluginName:string, methodName:string, cleanUpMethodName?:string) => {
return (..args) => {
return new Observable(observer => {
cordova.exec((val) => observer.next(val), (err) => observer.error(err), pluginName, methodName, args);
return () => {
if(cleanupMethodName){
cordova.exec(noop, noop, pluginName, methodName);
}
}
})
}
}
let getPicture = promisifyCordova('camera', 'getPicture');
getPicture(options).then(...);
let GeoLocation = observablifyCordova('geolocation', 'startWatch', 'stopWatch');
let watcher = GeoLocation.subscribe(...);
//later
watcher.unsubscribe(...);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment