Skip to content

Commit 04174af

Browse files
authored
Update README.md
Includes more information about the DatabaseRef
1 parent 843a6d5 commit 04174af

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -592,23 +592,33 @@ storageRef.downloadUrl()
592592

593593
### Realtime Database
594594

595-
#### database attribute
596-
597595
The native Firebase JavaScript library provides a featureful realtime database that works out of the box. Firestack provides an attribute to interact with the database without needing to configure the JS library.
598596

597+
#### DatabaseRef
598+
599+
Firestack attempts to provide the same API as the JS Firebase library for both Android and iOS platforms. [Check out the firebase guide](https://firebase.google.com/docs/database/web/read-and-write) for more information on how to use the JS library.
600+
601+
#### Example
602+
599603
```javascript
600-
firestack.database
601-
.ref(LIST_KEY)
602-
.on('value', snapshot => {
603-
if (snapshot.val()) {
604-
console.log('The list was updated');
605-
}
606-
});
607-
```
608604

609-
#### DatabaseRef
605+
function handleValueChange(snapshot) {
606+
if (snapshot.val()) {
607+
console.log('The list was updated');
608+
}
609+
}
610+
611+
const LIST_KEY = 'path/to/data';
612+
firestack.database.ref(LIST_KEY).on('value', handleValueChange);
610613

611-
Firestack attempts to provide the same API as the JS Firebase library for both Android and iOS platforms.
614+
// Calling `.off` with a reference to the callback function will only remove that specific listener.
615+
// This is useful if multiple components are listening and unlistening to the same ref path.
616+
firestack.database.ref(LIST_KEY).off('value', handleValueChange);
617+
618+
// Calling `.off` without passing the callback function will remove *all* 'value' listeners for that ref
619+
firestack.database.ref(LIST_KEY).off('value');
620+
621+
```
612622

613623
// TODO: Finish documenting
614624

0 commit comments

Comments
 (0)