docs(database): fix typos & tweak wording

This commit is contained in:
Mike Diarmid
2020-04-08 17:59:22 +01:00
committed by GitHub
parent 926aab83c2
commit a2bb98ed95

View File

@@ -5,18 +5,18 @@ next: /dynamic-links/usage
previous: /database/offline-support
---
The Realtime Data provides the ability to trigger events on the Firebase servers whenever a device is disconnected. This
could be whenever a user has no access to a network or they quit the app.
Realtime Database provides the ability to trigger events on the Firebase servers whenever a device is disconnected. This
could be whenever a user has no access to a network or when they quit the app.
One use-case using this functionality is to build a simple presence detection system, whereby we can hold a realtime list
of users currently connected with the application. This could be useful when building a chat application
of users currently online within our application. This could be useful when building a chat application
and you wish to view which of your users are currently online.
# Setup
To get started, we first need a location to store our online users.
To keep things simple we'll assume the user is authenticated (e.g. with [Firebase Authentication](/auth)) so we can use a unique user ID.
To keep things simple we'll assume the user is authenticated (e.g. with [Firebase Authentication](/auth)) so we can use their unique user identifier.
Whenever the application opens, [write a new value](/database/usage#writing-data) on a reference node (e.g. `/online/:userId`):
@@ -38,19 +38,18 @@ function App() {
}
```
Whenever the application boots and can connect to the remote server, the value will be written to the database indicating
which users are online.
Whenever the application boots and can connect to the remote server, the value will be written to the database indicating the user is online.
# On Disconnect
Next we need to remove the value whenever a user disconnects. Typically you would execute this functionality from the device
Next we need to remove the value when our user disconnects. Typically you would execute this functionality from the device
itself, however this presents a problem.
If the device suddenly goes offline, or is quit, the app can no longer execute code or connect to Firebase. Luckily, the
Realtime Database API provides a way to execute code on the Firebase servers whenever the connection between an app & server
is lost.
The `onDisconnect` method on a reference returns a new [`OnDisconnect`](/reference/database/ondisconnect) instance. The instance
The `onDisconnect` method on a reference returns a new [`OnDisconnect`](/reference/database/ondisconnect) instance. This instance
provides functionality to remove or set data whenever a client disconnects. Using the
[`remove`](/reference/database/ondisconnect#remove) method we can remove the node on the database if the client disconnects: