docs(firestore): emulator documentation (#3690)

* format(*): ran formatting script

* docs(firestore): added emulator docs

* chore(firestore): typedoc generate

* docs(firestore): with sidebar

* chore(firestore): generate docs

* docs(firestore): spelling/grammar

* chore(app): reversed test index

* chore(firestore): emulator update

* chore(firestore): emulator docs and code

* fix(firestore): emulator configuration

* chore(firestore): code review update

Co-authored-by: Mike Diarmid <mike.diarmid@gmail.com>

* chore(firestore): rm http protocol

Co-authored-by: Mike Diarmid <mike.diarmid@gmail.com>
[publish]
This commit is contained in:
Russell Wheatley
2020-06-03 13:53:04 +01:00
committed by GitHub
parent 31ca27fa03
commit 7a5a1ced6f
8 changed files with 2061 additions and 1816 deletions

View File

@@ -96,7 +96,7 @@ The iOS Notes app is a good place to paste your dynamic link and test it opens y
![iOS troubleshooting second step](https://images.prismic.io/invertase/4af777b7-7a2e-48a8-a0dc-23cea50e1a4b_Screenshot+2020-05-22+at+09.40.18.png?auto=compress,format)
3. Paste your link into the iOS Notes app. Long press the link which will open the menu and ensure you click "Open in [YOUR APP NAME]". Be sure *not* to press "Open in Safari" as that will disable that dynamic link domain for your device.
3. Paste your link into the iOS Notes app. Long press the link which will open the menu and ensure you click "Open in [YOUR APP NAME]". Be sure _not_ to press "Open in Safari" as that will disable that dynamic link domain for your device.
![iOS troubleshooting third step](https://images.prismic.io/invertase/1f8b049d-e54c-4901-a369-e7f6a19a444c_FA031D26-E14F-4A92-87F2-442191455537.png?auto=compress,format)

View File

@@ -0,0 +1,50 @@
---
title: Cloud Firestore Emulator
description: Using the Cloud Firestore emulator to test your app locally.
next: /firestore/usage-with-flatlists
previous: /firestore/usage
---
You can test your app and its Firestore implementation with an emulator which is built to mimic the behavior of Cloud Firestore. This means you can connect your app directly to the emulator to perform integration testing or QA without touching production data.
For example, you can connect your app to the emulator to safely read and write documents in testing.
## Running the emulator
To be able to mimic the behavior of Cloud Firestore, you need to run the emulator. This is effectively a server that will receive and send requests in lieu of Cloud Firestore. This is achieved by running the following commands:
```bash
// install the Firebase CLI which will run the emulator
curl -sL firebase.tools | bash
// run this command to start the emulator, it will also install it if this is your first time running the command
firebase emulators:start --only firestore
```
You should see a `firestore-debug.log` file in the directory you ran the command which will have a log of all the requests.
# Connect to emulator from your app
You need to configure the following property as soon as possible in the startup of your application:
```jsx
import '@react-native-firebase/app';
import firestore from '@react-native-firebase/firestore';
const db = firestore();
// set the host property to connect to the emulator
// set these before any read/write operations occur to ensure it doesn't affect your Cloud Firestore data!
db.settings({ host: 'localhost:8080' });
```
# Clear locally stored emulator data
Run the following command to clear the data accumulated locally from using the emulator. Please note that you have to insert your project id in the request at this point `[INSERT YOUR PROJECT ID HERE]`.
```bash
curl -v -X DELETE "http://localhost:8080/emulator/v1/projects/[INSERT YOUR PROJECT ID HERE]/databases/(default)/documents"
```
There are more things that can be achieved with the emulator such as using local rules to test the integrity & security of your database. For further information, please follow the Firebase emulator documentation [here](https://firebase.google.com/docs/emulator-suite).

View File

@@ -2,7 +2,7 @@
title: Usage with FlatLists
description: Using Cloud Firestore collections with FlatLists.
next: /functions/usage
previous: /firestore/usage
previous: /firestore/emulator
---
Cloud Firestore provides out of the box support for subscribing to [realtime changes](/firestore/usage#realtime-changes)

View File

@@ -54,8 +54,7 @@ import messaging, { AuthorizationStatus } from '@react-native-firebase/messaging
async function requestUserPermission() {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === AuthorizationStatus.AUTHORIZED ||
authStatus === AuthorizationStatus.PROVISIONAL;
authStatus === AuthorizationStatus.AUTHORIZED || authStatus === AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log('Authorization status:', authStatus);

View File

@@ -40,6 +40,8 @@
- - Cloud Firestore
- - - Usage
- '/firestore/usage'
- - Usage with Emulator
- '/firestore/emulator'
- - Usage with FlatLists
- '/firestore/usage-with-flatlists'
- - Building a "TODO" app

3806
docs/typedoc.json vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -22,6 +22,7 @@ import {
isObject,
isString,
isUndefined,
isAndroid,
} from '@react-native-firebase/app/lib/common';
import {
createModuleNamespace,
@@ -210,6 +211,15 @@ class FirebaseFirestoreModule extends FirebaseModule {
"firebase.firestore().settings(*) 'settings.host' must not be an empty string.",
);
}
if (isAndroid) {
if (settings.host.startsWith('localhost')) {
settings.host = settings.host.replace('localhost', '10.0.2.2');
}
if (settings.host.startsWith('127.0.0.1')) {
settings.host = settings.host.replace('127.0.0.1', '10.0.2.2');
}
}
}
if (!isUndefined(settings.persistence) && !isBoolean(settings.persistence)) {