-
-
Save mlynch/d7a8d0ee91ecbdf07e21 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