Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 31179aa

Browse files
committed
[docs][database] - Update webapi queries to show error callbacks
1 parent 0475099 commit 31179aa

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

docs/DATABASE.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,17 +371,25 @@ The link is for the iOS SDK, but it's the same for Android.
371371
<summary>Web API</summary>
372372

373373
```js
374-
const onValueEvent = result => {
375-
if (result.error) {
376-
console.log("Listener error: " + result.error);
377-
} else {
378-
console.log("Key: " + result.key);
379-
console.log("key exists? " + result.exists());
380-
console.log("Value: " + JSON.stringify(result.val()));
381-
}
382-
};
374+
public doWebAddValueEventListenerForCompanies(): void {
375+
const path = "/companies";
376+
const onValueEvent = (result: firebase.DataSnapshot ) => {
377+
// NOTE: we no longer check for result.error as it doesn't exist. Pass in an onError callback to handle errors!
378+
console.log("value : " + result.forEach(datasnapshot => {
379+
console.log(datasnapshot.key + " " + JSON.stringify(datasnapshot.val()));
380+
}));
381+
console.log("key exists? " + result.exists());
382+
this.set("path", path);
383+
this.set("key", result.key);
384+
this.set("value", JSON.stringify(result.val()));
385+
};
386+
387+
const onErrorEvent = (err: Error ) => {
388+
console.log("Encountered an error: " + err);
389+
};
390+
firebaseWebApi.database().ref("/companies").on("value", onValueEvent, onErrorEvent /* Totally Optional */);
391+
}
383392

384-
firebaseWebApi.database().ref("/companies").on("value", onValueEvent);
385393
```
386394
</details>
387395

0 commit comments

Comments
 (0)