1
- #RXJS 5 (beta currently at Beta 2 ) wrapper around Firebase's API.
1
+ #RXJS 5 (beta currently at Beta 6 ) wrapper around Firebase's API.
2
2
3
- Great with Angular2! Install using npm
3
+ Works great with Angular2! Install using npm, you don't need typings since it's already packaged with the project.
4
4
5
5
` npm install rxjsfirebase --save `
6
6
7
- ** This project was built with TypeScript**
7
+ ** Works on ES5 but also with ES6 and TypeScript**
8
8
To create an instance, you'll simply have to supply a native Firebase object to the constructor
9
9
10
10
``` javascript
11
- import {RxFirebase , EventType } from ' rxjsfirebase'
12
- import * as Firebase from ' firebase'
13
-
14
- var rootref = new Firebase (" MY_FIREBASE_URL" );
15
- var rx_rootRef = new RxFirebase (firebase);
11
+ import {RxFirebaseApp , RxFirebaseAuth , RxFirebaseView , EventType } from ' rxjsfirebase'
12
+
13
+ var config = config = {
14
+ apiKey: ' <your-api-key>' ,
15
+ authDomain: ' <your-auth-domain>' ,
16
+ databaseURL: ' <your-database-url>' ,
17
+ storageBucket: ' <your-storage-bucket>'
18
+ }
19
+
20
+ var applicationInstance = new RxFirebaseApp (config);
21
+ // or you can give the instance a name:
22
+ var applicationInstance = new RxFirebaseApp (config, " myAppInstanceName" );
16
23
```
17
-
18
- I tried to port almost all the methods to be Observable friendly.
19
24
20
- #Returning Child Paths and Queries
25
+ #Note
21
26
22
- Getting a child path is exactly the same as the original objects. You can always call
27
+ I made an opinionated effort to name data-endpoints as ** RxFirebaseView** .
28
+ The RxFirebaseView is essentially a ` ref ` or ` query ` in the old Firebase documentation.
29
+ The logic is that it's some sort of database-path location that you can observe.
30
+ It has all the methods that you love like
23
31
24
32
` child(mySubPath) `
25
33
@@ -43,7 +51,7 @@ Getting a child path is exactly the same as the original objects. You can always
43
51
44
52
` limit `
45
53
46
- ` ref `
54
+
47
55
48
56
#Observing Values
49
57
@@ -63,7 +71,7 @@ The enum as these values:
63
71
``` javascript
64
72
import {EventType } from ' rxjsfirebase'
65
73
66
- rx_rootref .rx_observe (EventType .CHILD_ADDED )
74
+ viewReference .rx_observe (EventType .CHILD_ADDED )
67
75
.subscribe ((snapshot ) => {
68
76
console .log (" Completed observing snapshot: " , snapshot .val ())
69
77
}, (err ) => {
@@ -74,10 +82,10 @@ The enum as these values:
74
82
75
83
#Observing Values Once
76
84
77
- To keep respectful to RxJS, we simply just fire a ` take(1) ` to observe the value once.
85
+ To keep the API respectful to RxJS, we simply just fire a ` take(1) ` to observe the value once.
78
86
79
87
``` javascript
80
- rx_rootref .rx_observe (EventType .CHILD_ADDED ).take (1 )
88
+ viewReference .rx_observe (EventType .CHILD_ADDED ).take (1 )
81
89
.subscribe ((snapshot ) => {
82
90
console .log (" Completed observing snapshot just once: " , snapshot .val ())
83
91
}, (err ) => {
@@ -88,9 +96,10 @@ To keep respectful to RxJS, we simply just fire a `take(1)` to observe the value
88
96
#Observing Values with a Sister Key
89
97
90
98
This is actually a separate method: ` rx_observeWithSiblingKey ` and it returns an object with the keys ` snapshot ` and ` siblingKey `
91
- Remember the sibling key might be ` null `
99
+ ** Remember the sibling key might be ` null ` **
100
+
92
101
``` javascript
93
- rx_rootref .rx_observeWithSiblingKey (EventType .CHILD_ADDED )
102
+ viewReference .rx_observeWithSiblingKey (EventType .CHILD_ADDED )
94
103
.subscribe (snapshotWithKey => {
95
104
console .log (" snapshot" , snapshotWithKey .snapshot )
96
105
console .log (" siblingKey (might be null!)" , snapshotWithKey .siblingKey )
@@ -102,7 +111,7 @@ Remember the sibling key might be `null`
102
111
This will return the authData. This does not throw an error if you are not authenticated.
103
112
104
113
``` javascript
105
- rx_rootRef .rx_observeAuth ().subscribe (authData => {
114
+ applicationInstance . auth .rx_observeAuth ().subscribe (authData => {
106
115
if (authData) {
107
116
console .log (" User " + authData .uid + " is logged in with " + authData .provider );
108
117
} else {
@@ -116,7 +125,7 @@ This will return the authData. This does not throw an error if you are not authe
116
125
But this one will wrap that callback into an Observable
117
126
118
127
``` javascript
119
- rx_rootref .rx_set (myValue)
128
+ viewReference .rx_set (myValue)
120
129
.subscribe (() => {
121
130
console .log (" Completed setting the value at this ref" )
122
131
}, (err ) => {
@@ -129,7 +138,7 @@ But this one will wrap that callback into an Observable
129
138
But this one will wrap that callback into an ` Observable<{}> `
130
139
131
140
``` javascript
132
- rx_rootref .rx_update (valuesToUpdate)
141
+ viewReference .rx_update (valuesToUpdate)
133
142
.subscribe (() => {
134
143
console .log (" Completed updating values at this ref" )
135
144
}, (err ) => {
@@ -139,11 +148,11 @@ But this one will wrap that callback into an `Observable<{}>`
139
148
140
149
#Push Values
141
150
142
- But this one will wrap that callback into an ` Observable<RxFirebase > `
151
+ But this one will wrap that callback into an ` Observable<RxFirebaseView > `
143
152
The RxFirebase instance is the location of the new ref that was pushed
144
153
145
154
``` javascript
146
- rx_rootref .rx_push (myValue)
155
+ viewReference .rx_push (myValue)
147
156
.subscribe (newFirebaseRef => {
148
157
console .log (" Completed pushing and it's located at this ref" , newFirebaseRef)
149
158
}, (err ) => {
0 commit comments