Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.