Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions docs/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,77 +60,77 @@ AngularFire provides observables to allow convenient use of the Realtime Databas

The `object()` function creates an observable that emits object changes.

| | |
|-----------------|------------------------------------------|
| **function** | `object(ref)` |
| **params** | ref: `Reference` |
| **return** | `Observable<QueryChange>` |
| | |
|-----------------|-----------------------------------|
| **function** | `object(query)` |
| **params** | query: `DatabaseReference\|Query` |
| **return** | `Observable<QueryChange>` |

### `objectVal`

The `objectVal` function creates an observable that emits an array of object values, optionally with a mapped key.
The `objectVal()` function creates an observable that emits the value of the node (an object, a primitive, or `null` if it does not exist), optionally with its key mapped to `keyField`.

| | |
|-----------------|-------------------------------------------------------|
| **function** | `objectVal(query, options?)` |
| **params** | query: `Reference\|Query`, options?: { keyField?: `string` } |
| **return** | `Observable<T>` |
| | |
|-----------------|----------------------------------------------------------------------|
| **function** | `objectVal(query, options?)` |
| **params** | query: `DatabaseReference\|Query`, options?: `{ keyField?: string }` |
| **return** | `Observable<T>` |

### `list`

The `list()` function creates an observable that emits a sorted array for each child event change. The optional `events` parameter will filter which child events populate the array.

| | |
|-----------------|-------------------------------------------------------|
| **function** | `list(ref, options?)` |
| **params** | ref: `Reference\|Query`, options?: { events?: `ListenEvent[]` } |
| **return** | `Observable<QueryChange[]>` |
| | |
|-----------------|-------------------------------------------------------------------------|
| **function** | `list(ref, options?)` |
| **params** | ref: `DatabaseReference\|Query`, options?: `{ events?: ListenEvent[] }` |
| **return** | `Observable<QueryChange[]>` |

### `listVal`

The `listVal()` function creates an observable that emits an object mapped to its value, and optionally its key.
The `listVal()` function creates an observable that emits an array of child values, optionally with each item's key mapped to `keyField`.

| | |
|-----------------|-------------------------------------------------------|
| **function** | `listVal(query, options?)` |
| **params** | ref: `Reference\|Query`, options?: { keyField?: `string` } |
| **return** | `Observable<T \| null>` |
| | |
|-----------------|----------------------------------------------------------------------|
| **function** | `listVal(query, options?)` |
| **params** | query: `DatabaseReference\|Query`, options?: `{ keyField?: string }` |
| **return** | `Observable<T[]>` |

### `stateChanges`

The `stateChanges()` function creates an observable that emits each time a change occurs at the reference or query passed. This is useful for tracking the changes in your list. The optional `events` parameter will filter which child events populate the array.

It emits only on child events, which an empty list never produces, so it does not hold the application unstable and a server render does not wait for it. Use `list()` when the render should wait for a list's initial contents.

| | |
|-----------------|------------------------------------------------------|
| **function** | `stateChanges(ref, options?)` |
| **params** | ref: `Reference\|Query`, options:? { events?: `ListenEvent[]` } |
| **return** | `Observable<QueryChange>` |
| | |
|-----------------|-------------------------------------------------------------------------|
| **function** | `stateChanges(ref, options?)` |
| **params** | ref: `DatabaseReference\|Query`, options?: `{ events?: ListenEvent[] }` |
| **return** | `Observable<QueryChange>` |

### `auditTrail`

The `auditTrail()` function creates an observable that emits the entire state trail. This is useful for debugging or replaying the state of a list in your app. The optional `events` parameter will filter which child events populate the array.

Like `stateChanges()`, it waits for child events, so it does not hold the application unstable and a server render does not wait for it.

| | |
|-----------------|------------------------------------------------------|
| **function** | `auditTrail(ref, options?)` |
| **params** | ref: `Reference\|Query`, options?: { events?: `ListenEvent[]` } |
| **return** | `Observable<QueryChange[]>` |
| | |
|-----------------|-------------------------------------------------------------------------|
| **function** | `auditTrail(ref, options?)` |
| **params** | ref: `DatabaseReference\|Query`, options?: `{ events?: ListenEvent[] }` |
| **return** | `Observable<QueryChange[]>` |

### `fromRef`

The `fromRef()` function creates an observable that emits reference changes.

With `ListenEvent.value` it holds the application unstable until the first value is emitted, so a server render waits for the data. With a child event it does not, because it may never emit.

| | |
|-----------------|------------------------------------------|
| **function** | `fromRef(ref, event)` |
| **params** | ref: `Reference\|Query`, event: `ListenEvent` |
| **return** | `Observable<QueryChange>` |
| | |
|-----------------|-------------------------------------------------------|
| **function** | `fromRef(ref, event)` |
| **params** | ref: `DatabaseReference\|Query`, event: `ListenEvent` |
| **return** | `Observable<QueryChange>` |

## Connecting to the emulator suite

Expand All @@ -154,8 +154,8 @@ export const appConfig: ApplicationConfig = {
## Working with multiple instances

```ts
import { ApplicationConfig } from '@angular/core';
import { provideFirebaseApp, FirebaseApp, initializeApp } from '@angular/fire/app';
import { ApplicationConfig, inject } from '@angular/core';
import { FirebaseApp, initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { getDatabase, provideDatabase } from '@angular/fire/database';

const DATABASE_SHARD_URLS = [
Expand All @@ -167,11 +167,11 @@ const DATABASE_SHARD_URLS = [
export const appConfig: ApplicationConfig = {
providers: [
provideFirebaseApp(() => initializeApp({ ... })),
provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[0])),
provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[1])),
provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[2])),
]
}
provideDatabase(() => getDatabase(inject(FirebaseApp), DATABASE_SHARD_URLS[0])),
provideDatabase(() => getDatabase(inject(FirebaseApp), DATABASE_SHARD_URLS[1])),
provideDatabase(() => getDatabase(inject(FirebaseApp), DATABASE_SHARD_URLS[2])),
],
};
```

```ts
Expand Down