Skip to content

Commit fb5380b

Browse files
committed
Combine multiple optional parameters into a single options parameter
1 parent 80464a8 commit fb5380b

File tree

5 files changed

+48
-19
lines changed

5 files changed

+48
-19
lines changed

firestore/index.js.flow

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ declare export function useCollectionOnce(
4040
): CollectionHook;
4141
declare export function useCollectionData<T>(
4242
query?: Query | null,
43-
options?: SnapshotListenOptions,
44-
idField?: string
43+
options?: {
44+
idField?: string,
45+
snapshotListenOptions?: SnapshotListenOptions,
46+
}
4547
): CollectionDataHook<T>;
4648
declare export function useCollectionDataOnce<T>(
4749
query?: Query | null,
48-
options?: GetOptions,
49-
idField?: string
50+
options?: {
51+
getOptions?: GetOptions,
52+
idField?: string,
53+
}
5054
): CollectionDataHook<T>;
5155
declare export function useDocument(
5256
ref?: DocumentReference | null,
@@ -58,11 +62,15 @@ declare export function useDocumentOnce(
5862
): DocumentHook;
5963
declare export function useDocumentData<T>(
6064
ref?: DocumentReference | null,
61-
options?: SnapshotListenOptions,
62-
idField?: string
65+
options?: {
66+
idField?: string,
67+
snapshotListenOptions?: SnapshotListenOptions,
68+
}
6369
): DocumentDataHook<T>;
6470
declare export function useDocumentDataOnce<T>(
6571
ref?: DocumentReference | null,
66-
options?: GetOptions,
67-
idField?: string
72+
options?: {
73+
getOptions?: GetOptions,
74+
idField?: string,
75+
}
6876
): DocumentDataHook<T>;

firestore/useCollectionData.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ export type CollectionDataHook<T> = {
1010

1111
export default <T>(
1212
query?: firestore.Query | null,
13-
options?: firestore.SnapshotListenOptions,
14-
idField?: string
13+
options?: {
14+
idField?: string;
15+
snapshotListenOptions?: firestore.SnapshotListenOptions;
16+
}
1517
): CollectionDataHook<T> => {
16-
const { error, loading, value } = useCollection(query, options);
18+
const idField = options ? options.idField : undefined;
19+
const snapshotListenOptions = options
20+
? options.snapshotListenOptions
21+
: undefined;
22+
const { error, loading, value } = useCollection(query, snapshotListenOptions);
1723
return {
1824
error,
1925
loading,

firestore/useCollectionDataOnce.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import { CollectionDataHook } from './useCollectionData';
55

66
export default <T>(
77
query?: firestore.Query | null,
8-
options?: firestore.GetOptions,
9-
idField?: string
8+
options?: {
9+
getOptions?: firestore.GetOptions;
10+
idField?: string;
11+
}
1012
): CollectionDataHook<T> => {
11-
const { error, loading, value } = useCollectionOnce(query, options);
13+
const idField = options ? options.idField : undefined;
14+
const getOptions = options ? options.getOptions : undefined;
15+
const { error, loading, value } = useCollectionOnce(query, getOptions);
1216
return {
1317
error,
1418
loading,

firestore/useDocumentData.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ export type DocumentDataHook<T> = {
1010

1111
export default <T>(
1212
docRef?: firestore.DocumentReference | null,
13-
options?: firestore.SnapshotListenOptions,
14-
idField?: string
13+
options?: {
14+
idField?: string;
15+
snapshotListenOptions?: firestore.SnapshotListenOptions;
16+
}
1517
): DocumentDataHook<T> => {
16-
const { error, loading, value } = useDocument(docRef, options);
18+
const idField = options ? options.idField : undefined;
19+
const snapshotListenOptions = options
20+
? options.snapshotListenOptions
21+
: undefined;
22+
const { error, loading, value } = useDocument(docRef, snapshotListenOptions);
1723
return {
1824
error,
1925
loading,

firestore/useDocumentDataOnce.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ import { DocumentDataHook } from './useDocumentData';
55

66
export default <T>(
77
docRef?: firestore.DocumentReference | null,
8-
idField?: string
8+
options?: {
9+
getOptions?: firestore.GetOptions;
10+
idField?: string;
11+
}
912
): DocumentDataHook<T> => {
10-
const { error, loading, value } = useDocumentOnce(docRef);
13+
const idField = options ? options.idField : undefined;
14+
const getOptions = options ? options.getOptions : undefined;
15+
const { error, loading, value } = useDocumentOnce(docRef, getOptions);
1116
return {
1217
error,
1318
loading,

0 commit comments

Comments
 (0)