Skip to content

Commit ede5362

Browse files
authored
Merge pull request #86 from mdirolf/firebase-8
Upgrade firebase and update imports to work w/ upstream changes
2 parents cf97f50 + 51359d8 commit ede5362

File tree

12 files changed

+72
-72
lines changed

12 files changed

+72
-72
lines changed

auth/useAuthState.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { auth, User } from 'firebase';
1+
import firebase from 'firebase/app';
22
import { useEffect } from 'react';
33
import { LoadingHook, useLoadingValue } from '../util';
44

5-
export type AuthStateHook = LoadingHook<User, auth.Error>;
5+
export type AuthStateHook = LoadingHook<firebase.User, firebase.auth.Error>;
66

7-
export default (auth: auth.Auth): AuthStateHook => {
7+
export default (auth: firebase.auth.Auth): AuthStateHook => {
88
const { error, loading, setError, setValue, value } = useLoadingValue<
9-
User,
10-
auth.Error
9+
firebase.User,
10+
firebase.auth.Error
1111
>(() => auth.currentUser);
1212

1313
useEffect(

database/helpers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { database } from 'firebase';
1+
import firebase from 'firebase/app';
22

33
const isObject = (val: any) =>
44
val != null && typeof val === 'object' && Array.isArray(val) === false;
55

66
export const snapshotToData = (
7-
snapshot: database.DataSnapshot,
7+
snapshot: firebase.database.DataSnapshot,
88
keyField?: string
99
) => {
1010
if (!snapshot.exists) {

database/helpers/useListReducer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
import { database, FirebaseError } from 'firebase';
1+
import firebase from 'firebase/app';
22
import { useReducer } from 'react';
33

44
type KeyValueState = {
55
keys?: string[];
6-
values?: database.DataSnapshot[];
6+
values?: firebase.database.DataSnapshot[];
77
};
88

99
type ReducerState = {
10-
error?: FirebaseError;
10+
error?: firebase.FirebaseError;
1111
loading: boolean;
1212
value: KeyValueState;
1313
};
1414

1515
type AddAction = {
1616
type: 'add';
1717
previousKey?: string | null;
18-
snapshot: database.DataSnapshot | null;
18+
snapshot: firebase.database.DataSnapshot | null;
1919
};
2020
type ChangeAction = {
2121
type: 'change';
22-
snapshot: database.DataSnapshot | null;
22+
snapshot: firebase.database.DataSnapshot | null;
2323
};
2424
type EmptyAction = { type: 'empty' };
25-
type ErrorAction = { type: 'error'; error: FirebaseError };
25+
type ErrorAction = { type: 'error'; error: firebase.FirebaseError };
2626
type MoveAction = {
2727
type: 'move';
2828
previousKey?: string | null;
29-
snapshot: database.DataSnapshot | null;
29+
snapshot: firebase.database.DataSnapshot | null;
3030
};
3131
type RemoveAction = {
3232
type: 'remove';
33-
snapshot: database.DataSnapshot | null;
33+
snapshot: firebase.database.DataSnapshot | null;
3434
};
3535
type ResetAction = { type: 'reset' };
3636
type ValueAction = { type: 'value' };

database/useList.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
import { database, FirebaseError } from 'firebase';
1+
import firebase from 'firebase';
22
import { useEffect, useMemo } from 'react';
33
import { snapshotToData } from './helpers';
44
import useListReducer from './helpers/useListReducer';
55
import { LoadingHook, useIsEqualRef } from '../util';
66

7-
export type ListHook = LoadingHook<database.DataSnapshot[], FirebaseError>;
8-
export type ListKeysHook = LoadingHook<string[], FirebaseError>;
9-
export type ListValsHook<T> = LoadingHook<T[], FirebaseError>;
7+
export type ListHook = LoadingHook<firebase.database.DataSnapshot[], firebase.FirebaseError>;
8+
export type ListKeysHook = LoadingHook<string[], firebase.FirebaseError>;
9+
export type ListValsHook<T> = LoadingHook<T[], firebase.FirebaseError>;
1010

11-
export const useList = (query?: database.Query | null): ListHook => {
11+
export const useList = (query?: firebase.database.Query | null): ListHook => {
1212
const [state, dispatch] = useListReducer();
1313

1414
const ref = useIsEqualRef(query, () => dispatch({ type: 'reset' }));
1515

1616
const onChildAdded = (
17-
snapshot: database.DataSnapshot | null,
17+
snapshot: firebase.database.DataSnapshot | null,
1818
previousKey?: string | null
1919
) => {
2020
dispatch({ type: 'add', previousKey, snapshot });
2121
};
2222

23-
const onChildChanged = (snapshot: database.DataSnapshot | null) => {
23+
const onChildChanged = (snapshot: firebase.database.DataSnapshot | null) => {
2424
dispatch({ type: 'change', snapshot });
2525
};
2626

2727
const onChildMoved = (
28-
snapshot: database.DataSnapshot | null,
28+
snapshot: firebase.database.DataSnapshot | null,
2929
previousKey?: string | null
3030
) => {
3131
dispatch({ type: 'move', previousKey, snapshot });
3232
};
3333

34-
const onChildRemoved = (snapshot: database.DataSnapshot | null) => {
34+
const onChildRemoved = (snapshot: firebase.database.DataSnapshot | null) => {
3535
dispatch({ type: 'remove', snapshot });
3636
};
3737

38-
const onError = (error: FirebaseError) => {
38+
const onError = (error: firebase.FirebaseError) => {
3939
dispatch({ type: 'error', error });
4040
};
4141

@@ -44,7 +44,7 @@ export const useList = (query?: database.Query | null): ListHook => {
4444
};
4545

4646
useEffect(() => {
47-
const query: database.Query | null | undefined = ref.current;
47+
const query: firebase.database.Query | null | undefined = ref.current;
4848
if (!query) {
4949
dispatch({ type: 'empty' });
5050
return;
@@ -67,7 +67,7 @@ export const useList = (query?: database.Query | null): ListHook => {
6767
return [state.value.values, state.loading, state.error];
6868
};
6969

70-
export const useListKeys = (query?: database.Query | null): ListKeysHook => {
70+
export const useListKeys = (query?: firebase.database.Query | null): ListKeysHook => {
7171
const [value, loading, error] = useList(query);
7272
return [
7373
value ? value.map(snapshot => snapshot.key as string) : undefined,
@@ -77,7 +77,7 @@ export const useListKeys = (query?: database.Query | null): ListKeysHook => {
7777
};
7878

7979
export const useListVals = <T>(
80-
query?: database.Query | null,
80+
query?: firebase.database.Query | null,
8181
options?: {
8282
keyField?: string;
8383
}

database/useObject.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { database, FirebaseError } from 'firebase';
1+
import firebase from 'firebase/app';
22
import { useEffect, useMemo } from 'react';
33
import { snapshotToData } from './helpers';
44
import { LoadingHook, useIsEqualRef, useLoadingValue } from '../util';
55

6-
export type ObjectHook = LoadingHook<database.DataSnapshot, FirebaseError>;
7-
export type ObjectValHook<T> = LoadingHook<T, FirebaseError>;
6+
export type ObjectHook = LoadingHook<firebase.database.DataSnapshot, firebase.FirebaseError>;
7+
export type ObjectValHook<T> = LoadingHook<T, firebase.FirebaseError>;
88

9-
export const useObject = (query?: database.Query | null): ObjectHook => {
9+
export const useObject = (query?: firebase.database.Query | null): ObjectHook => {
1010
const { error, loading, reset, setError, setValue, value } = useLoadingValue<
11-
database.DataSnapshot,
12-
FirebaseError
11+
firebase.database.DataSnapshot,
12+
firebase.FirebaseError
1313
>();
1414
const ref = useIsEqualRef(query, reset);
1515

@@ -34,7 +34,7 @@ export const useObject = (query?: database.Query | null): ObjectHook => {
3434
};
3535

3636
export const useObjectVal = <T>(
37-
query?: database.Query | null,
37+
query?: firebase.database.Query | null,
3838
options?: {
3939
keyField?: string;
4040
}

firestore/helpers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { firestore } from 'firebase';
1+
import firebase from 'firebase/app';
22

33
export const snapshotToData = (
4-
snapshot: firestore.DocumentSnapshot,
4+
snapshot: firebase.firestore.DocumentSnapshot,
55
idField?: string
66
) => {
77
if (!snapshot.exists) {

firestore/useCollection.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { firestore } from 'firebase';
1+
import firebase from 'firebase/app';
22
import { useEffect, useMemo } from 'react';
33
import { snapshotToData } from './helpers';
44
import { LoadingHook, useIsEqualRef, useLoadingValue } from '../util';
55

6-
export type CollectionHook = LoadingHook<firestore.QuerySnapshot, Error>;
6+
export type CollectionHook = LoadingHook<firebase.firestore.QuerySnapshot, Error>;
77
export type CollectionDataHook<T> = LoadingHook<T[], Error>;
88

99
export const useCollection = (
10-
query?: firestore.Query | null,
10+
query?: firebase.firestore.Query | null,
1111
options?: {
12-
snapshotListenOptions?: firestore.SnapshotListenOptions;
12+
snapshotListenOptions?: firebase.firestore.SnapshotListenOptions;
1313
}
1414
): CollectionHook => {
1515
const { error, loading, reset, setError, setValue, value } = useLoadingValue<
16-
firestore.QuerySnapshot,
16+
firebase.firestore.QuerySnapshot,
1717
Error
1818
>();
1919
const ref = useIsEqualRef(query, reset);
@@ -44,10 +44,10 @@ export const useCollection = (
4444
};
4545

4646
export const useCollectionData = <T>(
47-
query?: firestore.Query | null,
47+
query?: firebase.firestore.Query | null,
4848
options?: {
4949
idField?: string;
50-
snapshotListenOptions?: firestore.SnapshotListenOptions;
50+
snapshotListenOptions?: firebase.firestore.SnapshotListenOptions;
5151
}
5252
): CollectionDataHook<T> => {
5353
const idField = options ? options.idField : undefined;

firestore/useCollectionOnce.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { firestore } from 'firebase';
1+
import firebase from 'firebase/app';
22
import { useEffect } from 'react';
33
import { snapshotToData } from './helpers';
44
import { LoadingHook, useIsEqualRef, useLoadingValue } from '../util';
55

6-
export type CollectionOnceHook = LoadingHook<firestore.QuerySnapshot, Error>;
6+
export type CollectionOnceHook = LoadingHook<firebase.firestore.QuerySnapshot, Error>;
77
export type CollectionDataOnceHook<T> = LoadingHook<T[], Error>;
88

99
export const useCollectionOnce = (
10-
query?: firestore.Query | null,
10+
query?: firebase.firestore.Query | null,
1111
options?: {
12-
getOptions?: firestore.GetOptions;
12+
getOptions?: firebase.firestore.GetOptions;
1313
}
1414
): CollectionOnceHook => {
1515
const { error, loading, reset, setError, setValue, value } = useLoadingValue<
16-
firestore.QuerySnapshot,
16+
firebase.firestore.QuerySnapshot,
1717
Error
1818
>();
1919
const ref = useIsEqualRef(query, reset);
@@ -36,9 +36,9 @@ export const useCollectionOnce = (
3636
};
3737

3838
export const useCollectionDataOnce = <T>(
39-
query?: firestore.Query | null,
39+
query?: firebase.firestore.Query | null,
4040
options?: {
41-
getOptions?: firestore.GetOptions;
41+
getOptions?: firebase.firestore.GetOptions;
4242
idField?: string;
4343
}
4444
): CollectionDataOnceHook<T> => {

firestore/useDocument.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { firestore } from 'firebase';
1+
import firebase from 'firebase/app';
22
import { useEffect, useMemo } from 'react';
33
import { snapshotToData } from './helpers';
44
import { LoadingHook, useIsEqualRef, useLoadingValue } from '../util';
55

6-
export type DocumentHook = LoadingHook<firestore.DocumentSnapshot, Error>;
6+
export type DocumentHook = LoadingHook<firebase.firestore.DocumentSnapshot, Error>;
77
export type DocumentDataHook<T> = LoadingHook<T, Error>;
88

99
export const useDocument = (
10-
docRef?: firestore.DocumentReference | null,
10+
docRef?: firebase.firestore.DocumentReference | null,
1111
options?: {
12-
snapshotListenOptions?: firestore.SnapshotListenOptions;
12+
snapshotListenOptions?: firebase.firestore.SnapshotListenOptions;
1313
}
1414
): DocumentHook => {
1515
const { error, loading, reset, setError, setValue, value } = useLoadingValue<
16-
firestore.DocumentSnapshot,
16+
firebase.firestore.DocumentSnapshot,
1717
Error
1818
>();
1919
const ref = useIsEqualRef(docRef, reset);
@@ -44,10 +44,10 @@ export const useDocument = (
4444
};
4545

4646
export const useDocumentData = <T>(
47-
docRef?: firestore.DocumentReference | null,
47+
docRef?: firebase.firestore.DocumentReference | null,
4848
options?: {
4949
idField?: string;
50-
snapshotListenOptions?: firestore.SnapshotListenOptions;
50+
snapshotListenOptions?: firebase.firestore.SnapshotListenOptions;
5151
}
5252
): DocumentDataHook<T> => {
5353
const idField = options ? options.idField : undefined;

firestore/useDocumentOnce.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { firestore } from 'firebase';
1+
import firebase from 'firebase/app';
22
import { useEffect } from 'react';
33
import { snapshotToData } from './helpers';
44
import { LoadingHook, useIsEqualRef, useLoadingValue } from '../util';
55

6-
export type DocumentOnceHook = LoadingHook<firestore.DocumentSnapshot, Error>;
6+
export type DocumentOnceHook = LoadingHook<firebase.firestore.DocumentSnapshot, Error>;
77
export type DocumentDataOnceHook<T> = LoadingHook<T, Error>;
88

99
export const useDocumentOnce = (
10-
docRef?: firestore.DocumentReference | null,
10+
docRef?: firebase.firestore.DocumentReference | null,
1111
options?: {
12-
getOptions?: firestore.GetOptions;
12+
getOptions?: firebase.firestore.GetOptions;
1313
}
1414
): DocumentOnceHook => {
1515
const { error, loading, reset, setError, setValue, value } = useLoadingValue<
16-
firestore.DocumentSnapshot,
16+
firebase.firestore.DocumentSnapshot,
1717
Error
1818
>();
1919
const ref = useIsEqualRef(docRef, reset);
@@ -36,9 +36,9 @@ export const useDocumentOnce = (
3636
};
3737

3838
export const useDocumentDataOnce = <T>(
39-
docRef?: firestore.DocumentReference | null,
39+
docRef?: firebase.firestore.DocumentReference | null,
4040
options?: {
41-
getOptions?: firestore.GetOptions;
41+
getOptions?: firebase.firestore.GetOptions;
4242
idField?: string;
4343
}
4444
): DocumentDataOnceHook<T> => {

0 commit comments

Comments
 (0)