Skip to content

Commit

Permalink
chore(update-plugins): Mon Sep 2 08:06:48 UTC 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
nativescript-oss committed Sep 2, 2024
1 parent 7fe95c1 commit 27d6674
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions plugins/firebase-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,14 @@ If you are listening to a node with many children, only listening to data you ca
```ts
import { firebase } from '@nativescript/firebase-core'

const onChildAdd = firebase()
.database()
.ref('/users')
.on('child_added', snapshot => {
console.log('A new node has been added', snapshot.val())
})
const ref = firebase().database().ref('/users')

const onChildAdd = ref.on('child_added', snapshot => {
console.log('A new node has been added', snapshot.val())
})

// Stop listening for updates when no longer required
firebase().database().ref('/users').off('child_added', onChildAdd)
ref.off('child_added', onChildAdd)
```

### Remove a reference event listener
Expand All @@ -186,17 +185,22 @@ To unsubscribe from an event, call the `off` method on the reference passing it
```ts
import { firebase } from '@nativescript/firebase-core'

const onValueChange = firebase()
.database()
.ref(`/users/${userId}`)
.on('value', snapshot => {
console.log('User data: ', snapshot.val())
})
const ref = firebase().database().ref(`/users/${userId}`)

const onValueChange = ref.on('value', snapshot => {
console.log('User data: ', snapshot.val())
})

// Stop listening for updates when no longer required
firebase().database().ref(`/users/${userId}`).off('value', onValueChange)
ref.off('value', onValueChange)
```

:::tip Note

The `off` method requires the same `ref` as specified on the corresponding `on` method. The event handler specified in the `on` method must be unique. If a common event handler is used for multiple events, an anonymous function can be used to invoke the common handler.

:::

### Data querying

Realtime Database provides support for basic querying of your data. When a reference node contains children, you can both order & limit the returned results.
Expand Down

0 comments on commit 27d6674

Please sign in to comment.