From 88553595272bfddf20a64bc4eabd20118792a536 Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Tue, 8 Mar 2016 13:26:55 -0500 Subject: [PATCH] fix(plugin): combine watch and clearwatch functions --- src/plugins/deviceorientation.ts | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/plugins/deviceorientation.ts b/src/plugins/deviceorientation.ts index 66159367..1f193f65 100644 --- a/src/plugins/deviceorientation.ts +++ b/src/plugins/deviceorientation.ts @@ -1,4 +1,5 @@ import {Plugin, Cordova} from './plugin'; +import {Observable} from "rxjs/Observable"; export interface CompassHeading { @@ -70,29 +71,24 @@ export class DeviceOrientation { } /** - * Gets the device's current heading at a regular interval + * Get the device current heading at a regular interval + * + * Stop the watch by unsubscribing from the observable * @param options - * @returns {Promise} + * @returns {Observable} */ @Cordova({ - callbackOrder: 'reverse' + callbackOrder: 'reverse', + observable: true, + cancelFunction: 'clearWatch' }) - static watchHeading(options? : CompassOptions) : Promise { - // This Promise is replaced by one from the @Cordova decorator that wraps + static watchHeading(options? : CompassOptions) : Observable { + // This Observable is replaced by one from the @Cordova decorator that wraps // the plugin's callbacks. We provide a dummy one here so TypeScript - // knows that the correct return type is Promise, because there's no way + // knows that the correct return type is Observable, because there's no way // for it to know the return type from a decorator. // See https://github.com/Microsoft/TypeScript/issues/4881 - return new Promise((res, rej) => {}); + return new Observable(observer => {}); } - /** - * Stop watching the compass referenced by the watch ID parameter. - * @param watchID - */ - @Cordova({ - sync: true - }) - static clearWatch(watchID) : void {} - }