@@ -227,13 +227,24 @@ Alternatively you can use the web api to query data. See [docs](https://firebase
227
227
228
228
Some key notes:
229
229
230
+ The DataSnapshot returned is vastly different from the native api's snapshot! Please follow the web api docs to see what
231
+ you can do with the datasnapshot returned. Note that Datasnapshot.ref() is yet implemented.
232
+
233
+ ` Query.on() ` does not accept a cancelCallbackOrContext. Similar to the native api, check if result.error is true before continuing.
234
+
235
+ ` once("eventType") ` behaves differently on Android and iOS. On Android once only works with an eventType of ` value ` whereas
236
+ iOS will work with all the eventTypes like ` child_added, child_removed ` etc.
237
+
230
238
` off("eventType") ` will remove all listeners for "eventType" at the given path. So you do not need to call ` off() `
231
239
the same number of times you call ` on() ` . Listeners for all eventTypes will be removed if no eventType is provided.
232
240
233
- Filters (equalTo, starAt , endAt, LimitBy, etc) are only usable after you chain it with a sort. (While Firebase exposes these without doing
234
- a sort, your callback is never called). Think about it, if you apply equalTo without an orderBy what are you checking key, value, priority ?? ?
241
+ Filters (` equalTo, startAt , endAt, LimitBy ` , etc) should be used with a sort. If not, you may not get the result expected.
242
+ If you apply equalTo without an orderBy what are you checking for ( key, value, priority) ?
235
243
236
- DO NOT try to apply more than one orderBy to the same query as this will throw (follows the api)
244
+ When using ` equalTo, startAt or endAt ` chained with ` orderByKey() ` , you MUST make sure they are all strings. Otherwise expect
245
+ an exception to be thrown.
246
+
247
+ DO NOT try to apply more than one orderBy to the same query as this will crash the application (follows the api)
237
248
``` typescript
238
249
const bad = firebaseWebApi .database ().ref (path ).orderByKey ();
239
250
bad .orderByValue (); // <------ will throw here!
@@ -251,7 +262,23 @@ DO NOT try to apply more than one orderBy to the same query as this will throw (
251
262
252
263
// You can also do the following
253
264
firebase .webQuery (" /companies" ).orderByKey ().on (" value" , onQueryEvent );
265
+
266
+ const onQueryEvent = (result : any ) {
267
+ if (!result.error) {
268
+ console .log (" Exists: " + result .exists ());
269
+ console .log (" Key: " + result .key );
270
+ console .log (" Value: " + JSON .stringify (result .val ()));
271
+ result .forEach (
272
+ snapshot => {
273
+ // Do something forEach children. Note that this goes one level deep
274
+ console .log (snapshot .toJSON ());
275
+ }
276
+ );
277
+ }
278
+ };
279
+
254
280
```
281
+ Since the webapi queries follow the Google Documentation you can look at their examples for more reference.
255
282
</details >
256
283
257
284
### update
0 commit comments