-
Notifications
You must be signed in to change notification settings - Fork 403
fix: remove NO_ID_FIELD sentinel from data hooks when idField is not provided #738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,8 +32,8 @@ export function useDatabaseObject<T = unknown>(ref: DatabaseReference, options?: | |||||
| } | ||||||
|
|
||||||
| export function useDatabaseObjectData<T>(ref: DatabaseReference, options?: ReactFireOptions<T>): ObservableStatus<T> { | ||||||
| const idField = options ? checkIdField(options) : 'NO_ID_FIELD'; | ||||||
| const observableId = `database:objectVal:${ref.toString()}:idField=${idField}`; | ||||||
| const idField = options ? checkIdField(options) : undefined; | ||||||
| const observableId = `database:objectVal:${ref.toString()}:idField=${idField ?? 'none'}`; | ||||||
| const observable$ = objectVal<T>(ref, { keyField: idField }); | ||||||
|
|
||||||
| return useObservable(observableId, observable$, options); | ||||||
|
|
@@ -59,8 +59,8 @@ export function useDatabaseListData<T = { [key: string]: unknown }>( | |||||
| ref: DatabaseReference | DatabaseQuery, | ||||||
| options?: ReactFireOptions<T[]> | ||||||
| ): ObservableStatus<T[] | null> { | ||||||
| const idField = options ? checkIdField(options) : 'NO_ID_FIELD'; | ||||||
| const observableId = `database:listVal:${getUniqueIdForDatabaseQuery(ref)}:idField=${idField}`; | ||||||
| const idField = options ? checkIdField(options) : undefined; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ternary expression is redundant. The
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declining: the ternary guard at the call site is intentional. |
||||||
| const observableId = `database:listVal:${getUniqueIdForDatabaseQuery(ref)}:idField=${idField ?? 'none'}`; | ||||||
| const observable$ = listVal<T>(ref, { keyField: idField }); | ||||||
| return useObservable(observableId, observable$, options); | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -60,9 +60,9 @@ export function useFirestoreDocOnce<T = DocumentData>(ref: DocumentReference<T>, | |||||
| * Subscribe to Firestore Document changes and unwrap the document into a plain object | ||||||
| */ | ||||||
| export function useFirestoreDocData<T = unknown>(ref: DocumentReference<T>, options?: ReactFireOptions<T>): ObservableStatus<T | undefined> { | ||||||
| const idField = options ? checkIdField(options) : 'NO_ID_FIELD'; | ||||||
| const idField = options ? checkIdField(options) : undefined; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ternary expression is redundant. The
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declining: the ternary guard at the call site is intentional. |
||||||
|
|
||||||
| const observableId = `firestore:docData:${ref.firestore.app.name}:${ref.path}:idField=${idField}`; | ||||||
| const observableId = `firestore:docData:${ref.firestore.app.name}:${ref.path}:idField=${idField ?? 'none'}`; | ||||||
| const observable = docData(ref, { idField }); | ||||||
|
|
||||||
| return useObservable(observableId, observable, options) as ObservableStatus<T>; | ||||||
|
|
@@ -72,9 +72,9 @@ export function useFirestoreDocData<T = unknown>(ref: DocumentReference<T>, opti | |||||
| * Get a Firestore document, unwrap the document into a plain object, and don't subscribe to changes | ||||||
| */ | ||||||
| export function useFirestoreDocDataOnce<T = unknown>(ref: DocumentReference<T>, options?: ReactFireOptions<T>): ObservableStatus<T | undefined> { | ||||||
| const idField = options ? checkIdField(options) : 'NO_ID_FIELD'; | ||||||
| const idField = options ? checkIdField(options) : undefined; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ternary expression is redundant. The
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declining: the ternary guard at the call site is intentional. |
||||||
|
|
||||||
| const observableId = `firestore:docDataOnce:${ref.firestore.app.name}:${ref.path}:idField=${idField}`; | ||||||
| const observableId = `firestore:docDataOnce:${ref.firestore.app.name}:${ref.path}:idField=${idField ?? 'none'}`; | ||||||
| const observable$ = docData(ref, { idField }).pipe(first()); | ||||||
|
|
||||||
| return useObservable(observableId, observable$, options) as ObservableStatus<T>; | ||||||
|
|
@@ -94,8 +94,8 @@ export function useFirestoreCollection<T = DocumentData>(query: FirestoreQuery<T | |||||
| * Subscribe to a Firestore collection and unwrap the snapshot into an array. | ||||||
| */ | ||||||
| export function useFirestoreCollectionData<T = DocumentData>(query: FirestoreQuery<T>, options?: ReactFireOptions<T[]>): ObservableStatus<T[]> { | ||||||
| const idField = options ? checkIdField(options) : 'NO_ID_FIELD'; | ||||||
| const observableId = `firestore:collectionData:${getUniqueIdForFirestoreQuery(query)}:idField=${idField}`; | ||||||
| const idField = options ? checkIdField(options) : undefined; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ternary expression is redundant. The
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declining: the ternary guard at the call site is intentional. |
||||||
| const observableId = `firestore:collectionData:${getUniqueIdForFirestoreQuery(query)}:idField=${idField ?? 'none'}`; | ||||||
| const observable$ = collectionData(query, { idField }); | ||||||
|
|
||||||
| return useObservable(observableId, observable$, options); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ternary expression is redundant. The
checkIdFieldfunction already handles cases whereoptionsisundefinedby returningundefined. You can simplify this to a direct call tocheckIdField(options).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declining: the ternary guard at the call site is intentional.
checkIdFieldandcheckOptionsare typed to expect a realReactFireOptionsobject, and the hooks handle the no-options case before calling them. Widening the signatures to acceptundefinedwould requireoptions: ReactFireOptions | undefinedsincefieldfollows as a required parameter, which isn't a meaningful improvement. The current shape keeps the function signatures strict.