3.2.7 • Published 8 years ago

rxjsfirebase v3.2.7

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

#RXJS 5 (beta currently at Beta 2) wrapper around Firebase's API.

Great with Angular2! Install using npm

npm install rxjsfirebase --save

This project was built with TypeScript To create an instance, you'll simply have to supply a native Firebase object to the constructor

    import {RxFirebase, EventType} from 'rxjsfirebase'
    import * as Firebase from 'firebase'
    
    var rootref = new Firebase("MY_FIREBASE_URL");
    var rx_rootRef = new RxFirebase(firebase);

I tried to port almost all the methods to be Observable friendly.

#Returning Child Paths and Queries

Getting a child path is exactly the same as the original objects. You can always call

child(mySubPath)

orderByChild(childPath)

orderByKey(key)

orderByValue(val)

orderByPriority()

startAt

endAt

equalTo

limitToFirst

limitToLast

limit

ref

#Observing Values

You'll need to import the modules EventType enum. The enum as these values:

EventType.CHILD_ADDED

EventType.CHILD_REMOVED

EventType.CHILD_MOVED

EventType.CHILD_REMOVED

EventType.VALUE

    import {EventType} from 'rxjsfirebase'

    rx_rootref.rx_observe(EventType.CHILD_ADDED)
        .subscribe((snapshot) => {
            console.log("Completed observing snapshot: ", snapshot.val())
        }, (err) => {
            console.log(err)
        })

#Observing Values Once

To keep respectful to RxJS, we simply just fire a take(1) to observe the value once.

    rx_rootref.rx_observe(EventType.CHILD_ADDED).take(1)
        .subscribe((snapshot) => {
            console.log("Completed observing snapshot just once: ", snapshot.val())
        }, (err) => {
            console.log(err)
        })

#Observing Values with a Sister Key

This is actually a separate method: rx_observeWithSiblingKey and it returns an object with the keys snapshot and siblingKey Remember the sibling key might be null

    rx_rootref.rx_observeWithSiblingKey(EventType.CHILD_ADDED)
        .subscribe(snapshotWithKey => {
            console.log("snapshot", snapshotWithKey.snapshot)
            console.log("siblingKey (might be null!)", snapshotWithKey.siblingKey)
        })

#Observing Auth Values

This will return the authData. This does not throw an error if you are not authenticated.

    rx_rootRef.rx_observeAuth().subscribe(authData => {
        if (authData) {
            console.log("User " + authData.uid + " is logged in with " + authData.provider);
        } else {
            console.log("User is logged out");
        }
    })

#Setting Values

But this one will wrap that callback into an Observable

    rx_rootref.rx_set(myValue)
        .subscribe(() => {
            console.log("Completed setting the value at this ref")
        }, (err) => {
            console.log(err)
        })

#Updating Values

But this one will wrap that callback into an Observable<{}>

    rx_rootref.rx_update(valuesToUpdate)
        .subscribe(() => {
            console.log("Completed updating values at this ref")
        }, (err) => {
            console.log(err)
        })

#Push Values

But this one will wrap that callback into an Observable<RxFirebase> The RxFirebase instance is the location of the new ref that was pushed

    rx_rootref.rx_push(myValue)
        .subscribe(newFirebaseRef => {
            console.log("Completed pushing and it's located at this ref", newFirebaseRef)
        }, (err) => {
            console.log(err)
        })
3.2.7

8 years ago

3.2.6

8 years ago

3.2.5

8 years ago

3.2.4

8 years ago

3.2.3

8 years ago

3.2.2

8 years ago

3.2.1

8 years ago

3.2.0

8 years ago

1.0.21

8 years ago

1.0.20

8 years ago

1.0.19

8 years ago

1.0.18

8 years ago

1.0.17

8 years ago

1.0.16

8 years ago

1.0.15

8 years ago

1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago