diff --git a/docs/reference/modules/database.md b/docs/reference/modules/database.md index 7024785e..ea520325 100644 --- a/docs/reference/modules/database.md +++ b/docs/reference/modules/database.md @@ -38,7 +38,7 @@ Subscribe to a Realtime Database list #### Defined in -[src/database.tsx:74](https://github.com/FirebaseExtended/reactfire/blob/main/src/database.tsx#L74) +[src/database.tsx:48](https://github.com/FirebaseExtended/reactfire/blob/main/src/database.tsx#L48) ___ @@ -65,7 +65,7 @@ ___ #### Defined in -[src/database.tsx:84](https://github.com/FirebaseExtended/reactfire/blob/main/src/database.tsx#L84) +[src/database.tsx:58](https://github.com/FirebaseExtended/reactfire/blob/main/src/database.tsx#L58) ___ @@ -94,7 +94,7 @@ Subscribe to a Realtime Database object #### Defined in -[src/database.tsx:30](https://github.com/FirebaseExtended/reactfire/blob/main/src/database.tsx#L30) +[src/database.tsx:27](https://github.com/FirebaseExtended/reactfire/blob/main/src/database.tsx#L27) ___ @@ -121,4 +121,4 @@ ___ #### Defined in -[src/database.tsx:60](https://github.com/FirebaseExtended/reactfire/blob/main/src/database.tsx#L60) +[src/database.tsx:34](https://github.com/FirebaseExtended/reactfire/blob/main/src/database.tsx#L34) diff --git a/package.json b/package.json index 8743b6f0..ee957c0f 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "typescript": "^4.2.4" }, "dependencies": { - "rxfire": "6.0.0-rc.1", + "rxfire": "6.0.0-rc.2", "rxjs": "^6.6.3 || ^7.0.1" }, "resolutions": { diff --git a/src/database.tsx b/src/database.tsx index 593152ba..ede4f4a5 100644 --- a/src/database.tsx +++ b/src/database.tsx @@ -1,9 +1,6 @@ -import { list, object, QueryChange, listVal } from 'rxfire/database'; +import { list, object, QueryChange, listVal, objectVal } from 'rxfire/database'; import { ReactFireOptions, useObservable, checkIdField, ObservableStatus, ReactFireGlobals } from './'; -import { Observable } from 'rxjs'; -import { map } from 'rxjs/operators'; - import type { Query as DatabaseQuery, DatabaseReference } from 'firebase/database'; // Since we're side-effect free, we need to ensure our observableId cache is global @@ -34,33 +31,10 @@ export function useDatabaseObject(ref: DatabaseReference, options?: return useObservable(observableId, observable$, options); } -// ============================================================================ -// TODO: switch to rxfire's objectVal once this PR is merged: -// https://github.com/firebase/firebase-js-sdk/pull/2352 - -function objectVal(query: DatabaseQuery, keyField?: string): Observable { - return object(query).pipe(map((change) => changeToData(change, keyField) as T)); -} - -function changeToData(change: QueryChange, keyField?: string): {} { - const val = change.snapshot.val(); - - // don't worry about setting IDs if the value is a primitive type - if (typeof val !== 'object') { - return val; - } - - return { - ...change.snapshot.val(), - ...(keyField ? { [keyField]: change.snapshot.key } : null), - }; -} -// ============================================================================ - export function useDatabaseObjectData(ref: DatabaseReference, options?: ReactFireOptions): ObservableStatus { const idField = options ? checkIdField(options) : 'NO_ID_FIELD'; const observableId = `database:objectVal:${ref.toString()}:idField=${idField}`; - const observable$ = objectVal(ref, idField); + const observable$ = objectVal(ref, { keyField: idField }); return useObservable(observableId, observable$, options); } @@ -87,6 +61,6 @@ export function useDatabaseListData( ): ObservableStatus { const idField = options ? checkIdField(options) : 'NO_ID_FIELD'; const observableId = `database:listVal:${getUniqueIdForDatabaseQuery(ref)}:idField=${idField}`; - const observable$ = listVal(ref, idField); + const observable$ = listVal(ref, { keyField: idField }); return useObservable(observableId, observable$, options); } diff --git a/src/firestore.tsx b/src/firestore.tsx index fa2b33d3..02f36b68 100644 --- a/src/firestore.tsx +++ b/src/firestore.tsx @@ -63,7 +63,7 @@ export function useFirestoreDocData(ref: DocumentReference, opti const idField = options ? checkIdField(options) : 'NO_ID_FIELD'; const observableId = `firestore:docData:${ref.firestore.app.name}:${ref.path}:idField=${idField}`; - const observable = docData(ref, idField); + const observable = docData(ref, { idField }); return useObservable(observableId, observable, options); } @@ -75,7 +75,7 @@ export function useFirestoreDocDataOnce(ref: DocumentReference, const idField = options ? checkIdField(options) : 'NO_ID_FIELD'; const observableId = `firestore:docDataOnce:${ref.firestore.app.name}:${ref.path}:idField=${idField}`; - const observable$ = docData(ref, idField).pipe(first()); + const observable$ = docData(ref, { idField }).pipe(first()); return useObservable(observableId, observable$, options); } @@ -96,7 +96,7 @@ export function useFirestoreCollection(query: FirestoreQuery(query: FirestoreQuery, options?: ReactFireOptions): ObservableStatus { const idField = options ? checkIdField(options) : 'NO_ID_FIELD'; const observableId = `firestore:collectionData:${getUniqueIdForFirestoreQuery(query)}:idField=${idField}`; - const observable$ = collectionData(query, idField); + const observable$ = collectionData(query, { idField }); return useObservable(observableId, observable$, options); } diff --git a/yarn.lock b/yarn.lock index 9711a007..9e9fd4f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10554,10 +10554,10 @@ run-queue@^1.0.0, run-queue@^1.0.3: dependencies: aproba "^1.1.1" -rxfire@6.0.0-rc.1: - version "6.0.0-rc.1" - resolved "https://registry.yarnpkg.com/rxfire/-/rxfire-6.0.0-rc.1.tgz#a3c95cdcecf5bd26823377d9836ecb5005156ea1" - integrity sha512-2wGzy/iMkYcBnTCwk1JNnX0tL0h/MXh9dki1bR+/rsxzr4S6T6uhLYAknp7lsPvbxSpvpis4io3k1yWXnUMjsQ== +rxfire@6.0.0-rc.2: + version "6.0.0-rc.2" + resolved "https://registry.yarnpkg.com/rxfire/-/rxfire-6.0.0-rc.2.tgz#fde8f18341ec0362a07c2bc99499b5d01f5f0abf" + integrity sha512-iiDOSTwY9j1v0CKedkReOLywbEzOutP+Xc9Vl5kFp+wHBCEWStlbCk1VulQQwyOdPb/lAiQYRMKM5gQrs0ipTQ== dependencies: tslib "^1.9.0 || ~2.1.0"