Created
November 18, 2015 23:07
-
-
Save robwormald/877a496039909dadf9cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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