From d517baf7e3c935e71748e0046446d09289e8f4e7 Mon Sep 17 00:00:00 2001 From: AdamBoczula Date: Wed, 2 Dec 2026 06:41:37 +0100 Subject: [PATCH] docs(database): fix objectVal/listVal docs and multiple instances example - Swap the reversed descriptions of objectVal() and listVal(), and fix listVal() return type (Observable) and parameter name (query) - Update Reference to DatabaseReference in the convenience observable tables - Fix options:? typo in the stateChanges table - Use inject(FirebaseApp) in provideDatabase() in the Working with multiple instances example --- docs/database.md | 88 ++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/docs/database.md b/docs/database.md index dcc1f39ea..9ba16029d 100644 --- a/docs/database.md +++ b/docs/database.md @@ -60,41 +60,41 @@ 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` | +| | | +|-----------------|-----------------------------------| +| **function** | `object(query)` | +| **params** | query: `DatabaseReference\|Query` | +| **return** | `Observable` | ### `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` | +| | | +|-----------------|----------------------------------------------------------------------| +| **function** | `objectVal(query, options?)` | +| **params** | query: `DatabaseReference\|Query`, options?: `{ keyField?: string }` | +| **return** | `Observable` | ### `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` | +| | | +|-----------------|-------------------------------------------------------------------------| +| **function** | `list(ref, options?)` | +| **params** | ref: `DatabaseReference\|Query`, options?: `{ events?: ListenEvent[] }` | +| **return** | `Observable` | ### `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` | +| | | +|-----------------|----------------------------------------------------------------------| +| **function** | `listVal(query, options?)` | +| **params** | query: `DatabaseReference\|Query`, options?: `{ keyField?: string }` | +| **return** | `Observable` | ### `stateChanges` @@ -102,11 +102,11 @@ The `stateChanges()` function creates an observable that emits each time a chang 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` | +| | | +|-----------------|-------------------------------------------------------------------------| +| **function** | `stateChanges(ref, options?)` | +| **params** | ref: `DatabaseReference\|Query`, options?: `{ events?: ListenEvent[] }` | +| **return** | `Observable` | ### `auditTrail` @@ -114,11 +114,11 @@ The `auditTrail()` function creates an observable that emits the entire state tr 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` | +| | | +|-----------------|-------------------------------------------------------------------------| +| **function** | `auditTrail(ref, options?)` | +| **params** | ref: `DatabaseReference\|Query`, options?: `{ events?: ListenEvent[] }` | +| **return** | `Observable` | ### `fromRef` @@ -126,11 +126,11 @@ 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` | +| | | +|-----------------|-------------------------------------------------------| +| **function** | `fromRef(ref, event)` | +| **params** | ref: `DatabaseReference\|Query`, event: `ListenEvent` | +| **return** | `Observable` | ## Connecting to the emulator suite @@ -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 = [ @@ -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