fix(plugin): combine watch and clearwatch functions
This commit is contained in:
parent
5944bd13d3
commit
8855359527
@ -1,4 +1,5 @@
|
|||||||
import {Plugin, Cordova} from './plugin';
|
import {Plugin, Cordova} from './plugin';
|
||||||
|
import {Observable} from "rxjs/Observable";
|
||||||
|
|
||||||
export interface CompassHeading {
|
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
|
* @param options
|
||||||
* @returns {Promise<CompassHeading>}
|
* @returns {Observable<CompassHeading>}
|
||||||
*/
|
*/
|
||||||
@Cordova({
|
@Cordova({
|
||||||
callbackOrder: 'reverse'
|
callbackOrder: 'reverse',
|
||||||
|
observable: true,
|
||||||
|
cancelFunction: 'clearWatch'
|
||||||
})
|
})
|
||||||
static watchHeading(options? : CompassOptions) : Promise<CompassHeading> {
|
static watchHeading(options? : CompassOptions) : Observable<CompassHeading> {
|
||||||
// This Promise is replaced by one from the @Cordova decorator that wraps
|
// This Observable is replaced by one from the @Cordova decorator that wraps
|
||||||
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
// 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.
|
// for it to know the return type from a decorator.
|
||||||
// See https://github.com/Microsoft/TypeScript/issues/4881
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
||||||
return new Promise<CompassHeading>((res, rej) => {});
|
return new Observable<CompassHeading>(observer => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop watching the compass referenced by the watch ID parameter.
|
|
||||||
* @param watchID
|
|
||||||
*/
|
|
||||||
@Cordova({
|
|
||||||
sync: true
|
|
||||||
})
|
|
||||||
static clearWatch(watchID) : void {}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user