Skip to content

Commit

Permalink
Tweaks to #18
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbianca committed May 7, 2019
1 parent ee43cb1 commit eaecf9c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion database/index.js.flow
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { FirebaseError } from 'firebase';
import typeof { FirebaseError } from 'firebase';
import type { DataSnapshot, Query } from 'firebase/database';

export type ListHook = {
Expand Down
11 changes: 10 additions & 1 deletion firestore/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { firestore } from 'firebase';
import { firestore, FirebaseError } from 'firebase';

export const snapshotToData = (
snapshot: firestore.DocumentSnapshot,
Expand All @@ -10,3 +10,12 @@ export const snapshotToData = (
...(idField ? { [idField]: snapshot.id } : null),
};
};

export const transformError = (error: Error): FirebaseError => {
return {
message: error.message,
stack: error.stack,
name: error.name,
code: '',
};
};
2 changes: 1 addition & 1 deletion firestore/index.js.flow
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { FirebaseError } from 'firebase';
import typeof { FirebaseError } from 'firebase';
import type {
DocumentReference,
DocumentSnapshot,
Expand Down
10 changes: 7 additions & 3 deletions firestore/useCollection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { firestore, FirebaseError } from 'firebase';
import { useEffect } from 'react';
import { transformError } from './helpers';
import { useIsEqualRef, useLoadingValue } from '../util';
import { transformError } from '../util/transformError';

export type CollectionHook = {
error?: FirebaseError;
Expand All @@ -25,8 +25,12 @@ export default (
return;
}
const listener = options
? ref.current.onSnapshot(options, setValue, (error: Error) => setError(transformError(error)))
: ref.current.onSnapshot(setValue, (error: Error) => setError(transformError(error)));
? ref.current.onSnapshot(options, setValue, (error: Error) =>
setError(transformError(error))
)
: ref.current.onSnapshot(setValue, (error: Error) =>
setError(transformError(error))
);

return () => {
listener();
Expand Down
10 changes: 7 additions & 3 deletions firestore/useDocument.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { firestore, FirebaseError } from 'firebase';
import { useEffect } from 'react';
import { transformError } from './helpers';
import { useIsEqualRef, useLoadingValue } from '../util';
import { transformError } from '../util/transformError';

export type DocumentHook = {
error?: FirebaseError;
Expand All @@ -25,8 +25,12 @@ export default (
return;
}
const listener = options
? ref.current.onSnapshot(options, setValue, (error: Error) => setError(transformError(error)))
: ref.current.onSnapshot(setValue, (error: Error) => setError(transformError(error)));
? ref.current.onSnapshot(options, setValue, (error: Error) =>
setError(transformError(error))
)
: ref.current.onSnapshot(setValue, (error: Error) =>
setError(transformError(error))
);

return () => {
listener();
Expand Down
2 changes: 1 addition & 1 deletion storage/index.js.flow
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { FirebaseError } from 'firebase';
import typeof { FirebaseError } from 'firebase';
import type { Reference } from 'firebase/storage';

export type DownloadURLHook = {
Expand Down
10 changes: 0 additions & 10 deletions util/transformError.ts

This file was deleted.

0 comments on commit eaecf9c

Please sign in to comment.