Skip to content

Commit 3cebaa9

Browse files
authored
Refactoring use/preload and more (#215)
* Drop `initPerformance` (closes #207) * Cleaning up the use/preload types * Use my good friend `Proxy` to allow access to both the `serviceProps` and the initialized instance without double calling (e.g, `useAuth()()`) * More checks against double initializing * Added binding to the initialize call (closes #213) * `SuspenseWithPerf` now lazy loads performance monitoring and uses the user timing API * Fixed the CJS build with a better external test (closes #214)
1 parent aa0f822 commit 3cebaa9

File tree

16 files changed

+262
-388
lines changed

16 files changed

+262
-388
lines changed

reactfire/.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
cjs/index.esm-*
21
**/*.test.d.ts
32
**/*.test.js

reactfire/auth/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { from } from 'rxjs';
1313
export function preloadUser(firebaseApp: firebase.app.App) {
1414
return preloadAuth(firebaseApp).then(auth => {
1515
const result = preloadObservable(
16-
user(auth() as firebase.auth.Auth),
16+
user(auth()),
1717
`auth:user:${firebaseApp.name}`
1818
);
1919
return result.toPromise();
@@ -30,7 +30,7 @@ export function useUser<T = unknown>(
3030
auth?: auth.Auth,
3131
options?: ReactFireOptions<T>
3232
): User | T {
33-
auth = auth || useAuth()();
33+
auth = auth || useAuth();
3434
const currentUser = auth.currentUser || options?.startWithValue;
3535
return useObservable(user(auth), `auth:user:${auth.app.name}`, currentUser);
3636
}

reactfire/firebaseApp/firebaseApp.test.tsx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,6 @@ describe('FirebaseAppProvider', () => {
2929
spy.mockRestore();
3030
});
3131

32-
it('initializes fireperf if specified', async () => {
33-
const mockPerf = jest.fn();
34-
firebase['performance' as any] = mockPerf;
35-
const app: firebase.app.App = { performance: mockPerf } as any;
36-
37-
render(<FirebaseAppProvider firebaseApp={app} initPerformance />);
38-
39-
expect(mockPerf).toBeCalled();
40-
});
41-
42-
it('does not initialize fireperf if not specified', async () => {
43-
const mockPerf = jest.fn();
44-
firebase['performance' as any] = mockPerf;
45-
const app: firebase.app.App = { performance: mockPerf } as any;
46-
47-
render(<FirebaseAppProvider firebaseApp={app} />);
48-
49-
expect(mockPerf).not.toBeCalled();
50-
});
5132
});
5233

5334
describe('useFirebaseApp', () => {

reactfire/firebaseApp/index.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ export * from './sdk';
66
type FirebaseAppContextValue = firebase.app.App;
77

88
// INVESTIGATE I don't like magic strings, can we have export this in js-sdk?
9-
const DEFAULT_APP_NAME = '[DEFAULT]';
9+
export const DEFAULT_APP_NAME = '[DEFAULT]';
1010

1111
const FirebaseAppContext = React.createContext<
1212
FirebaseAppContextValue | undefined
1313
>(undefined);
1414

1515
type Props = {
16-
initPerformance?: boolean;
1716
firebaseApp?: firebase.app.App;
1817
firebaseConfig?: Object;
1918
appName?: string;
@@ -24,7 +23,7 @@ const shallowEq = (a: Object, b: Object) =>
2423
[...Object.keys(a), ...Object.keys(b)].every(key => a[key] == b[key]);
2524

2625
export function FirebaseAppProvider(props: Props & { [key: string]: unknown }) {
27-
const { firebaseConfig, appName, initPerformance = false } = props;
26+
const { firebaseConfig, appName } = props;
2827
const firebaseApp: firebase.app.App =
2928
props.firebaseApp ||
3029
React.useMemo(() => {
@@ -43,19 +42,6 @@ export function FirebaseAppProvider(props: Props & { [key: string]: unknown }) {
4342
}
4443
}, [firebaseConfig, appName]);
4544

46-
React.useMemo(() => {
47-
if (initPerformance === true) {
48-
if (firebaseApp.performance) {
49-
// initialize Performance Monitoring
50-
firebaseApp.performance();
51-
} else {
52-
throw new Error(
53-
'firebase.performance not found. Did you forget to import it?'
54-
);
55-
}
56-
}
57-
}, [initPerformance, firebaseApp]);
58-
5945
return <FirebaseAppContext.Provider value={firebaseApp} {...props} />;
6046
}
6147

0 commit comments

Comments
 (0)