From 27d6674452b472c7a3960bfb7f3498044d27b937 Mon Sep 17 00:00:00 2001 From: NativeScript-Bot Date: Mon, 2 Sep 2024 08:06:48 +0000 Subject: [PATCH] chore(update-plugins): Mon Sep 2 08:06:48 UTC 2024 --- plugins/firebase-database.md | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/plugins/firebase-database.md b/plugins/firebase-database.md index ef54d721..c6b621f3 100644 --- a/plugins/firebase-database.md +++ b/plugins/firebase-database.md @@ -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 @@ -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.