Skip to content

Commit

Permalink
refactor(batterystatus): add interface for battery status object
Browse files Browse the repository at this point in the history
  • Loading branch information
ihadeed committed Mar 10, 2016
1 parent 046d17e commit e776541
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/plugins/batterystatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,26 @@ export class BatteryStatus {

/**
* Watch the change in battery level
* @returns {Observable} Returns an observable that pushes the new battery level
* @returns {Observable} Returns an observable that pushes a status object
*/
static onChange () : Observable<any> {
static onChange () : Observable<StatusObject> {
return new Observable(observer => {
let callback = (status : any) => observer.next(status);
window.addEventListener("batterystatus", callback, false);
return () => window.removeEventListener("batterystatus", callback, false);
});
}

}

interface StatusObject {
/**
* The battery charge percentage
*/
level : number,

/**
* A boolean that indicates whether the device is plugged in
*/
isPlugged : boolean
}

0 comments on commit e776541

Please sign in to comment.