import * as firebase from 'firebase' ; import { Observable , fromEventPattern , from as fromPromise } from 'rxjs' ; export class ObservableDbRef { ref : any ; constructor ( ref ) { this . ref = ref ; } limitToLast ( limit ) { return new ObservableDbRef ( this . ref . limitToLast ( limit ) ) ; } limitToFirst ( limit ) { return new ObservableDbRef ( this . ref . limitToFirst ( limit ) ) ; } orderByChild ( value ) { return new ObservableDbRef ( this . ref . orderByChild ( value ) ) ; } startAt ( value , key ? ) { return new ObservableDbRef ( this . ref . startAt ( value , key ) ) ; } equalTo ( value ) { return new ObservableDbRef ( this . ref . equalTo ( value ) ) ; } once ( eventType ) { return fromPromise ( this . ref . once ( eventType ) ) ; } onceValue ( ) { return this . once ( 'value' ) ; } set ( data ) { return fromPromise ( this . ref . set ( data ) ) ; } update ( data ) { return fromPromise ( this . ref . update ( data ) ) ; } childAdded ( ) { return this . on ( 'child_added' ) ; } value ( ) { return this . on ( 'value' ) ; } on ( eventName ) { return fromEventPattern ( handler => this . ref . on ( eventName , val => handler ( val ) ) , handler => this . ref . off ( eventName , handler ) ) ; } }