Skip to content

Commit b7d4821

Browse files
author
Scott Prue
committed
fix(hooks): remove create functions for createWithFirebase and createWithFirestore
* fix(tests): remove old tests for createUseFirestore and createUseFirebase
1 parent f632250 commit b7d4821

File tree

9 files changed

+43
-116
lines changed

9 files changed

+43
-116
lines changed

src/firebaseConnect.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import ReactReduxFirebaseContext from './ReactReduxFirebaseContext'
1212
* React's Lifecycle hooks.
1313
* **WARNING!!** This is an advanced feature, and should only be used when
1414
* needing to access a firebase instance created under a different store key.
15-
* @param {String} [storeKey='store'] - Name of redux store which contains
16-
* Firebase state (state.firebase)
1715
* @return {Function} - HOC that accepts a watchArray and wraps a component
1816
* @example <caption>Basic</caption>
1917
* // props.firebase set on App component as firebase object with helpers
@@ -23,7 +21,7 @@ import ReactReduxFirebaseContext from './ReactReduxFirebaseContext'
2321
* // use the firebaseConnect to wrap a component
2422
* export default firebaseConnect()(SomeComponent)
2523
*/
26-
export const createFirebaseConnect = (storeKey = 'store') => (
24+
export const createFirebaseConnect = () => (
2725
dataOrFn = []
2826
) => WrappedComponent => {
2927
class FirebaseConnectWrapped extends Component {

src/firestoreConnect.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import ReactReduxFirebaseContext from './ReactReduxFirebaseContext'
1212
* React's Lifecycle hooks.
1313
* **WARNING!!** This is an advanced feature, and should only be used when
1414
* needing to access a firebase instance created under a different store key.
15-
* @param {String} [storeKey='store'] - Name of redux store which contains
16-
* Firebase state (state.firebase)
1715
* @return {Function} - HOC that accepts a watchArray and wraps a component
1816
* @example <caption>Basic</caption>
1917
* // props.firebase set on App component as firebase object with helpers
@@ -23,7 +21,7 @@ import ReactReduxFirebaseContext from './ReactReduxFirebaseContext'
2321
* // use the firebaseConnect to wrap a component
2422
* export default firestoreConnect()(SomeComponent)
2523
*/
26-
export const createFirestoreConnect = (storeKey = 'store') => (
24+
export const createFirestoreConnect = () => (
2725
dataOrFn = []
2826
) => WrappedComponent => {
2927
class FirestoreConnectWrapped extends Component {

src/useFirestoreConnect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import useFirestore from './useFirestore'
99
* firestore paths.
1010
* **WARNING!!** This is an advanced feature, and should only be used when
1111
* needing to access a firebase instance created under a different store key.
12-
* Firebase state (state.firestore)
12+
* Firestore state (state.firestore)
1313
* @return {Function} - React hook that accepts watch query
1414
* @example <caption>Basic</caption>
1515
* // props.firestore set on App component as firestore object with helpers

src/withFirebase.js

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,6 @@ import hoistStatics from 'hoist-non-react-statics'
44
import { wrapDisplayName } from './utils'
55
import useFirebase from './useFirebase'
66

7-
/**
8-
* @name createWithFirebase
9-
* @description Function that creates a Higher Order Component that
10-
* which provides `firebase` and `dispatch` as a props to React Components.
11-
*
12-
* **WARNING!!** This is an advanced feature, and should only be used when
13-
* needing to access a firebase instance created under a different store key.
14-
* @param {String} [storeKey='store'] - Name of redux store which contains
15-
* Firebase state (`state.firebase`)
16-
* @return {Function} - Higher Order Component which accepts an array of
17-
* watchers config and wraps a React Component
18-
* @example <caption>Basic</caption>
19-
* // props.firebase set on App component as firebase object with helpers
20-
* import { createWithFirebase } from 'react-redux-firebase'
21-
*
22-
* // create withFirebase that uses another redux store
23-
* const withFirebase = createWithFirebase('anotherStore')
24-
*
25-
* // use the withFirebase to wrap a component
26-
* export default withFirebase(SomeComponent)
27-
*/
28-
export const createWithFirebase = (storeKey = 'store') => WrappedComponent => {
29-
const WithFirebase = function WithFirebase(props) {
30-
const firebase = useFirebase()
31-
return (
32-
<WrappedComponent
33-
firebase={firebase}
34-
dispatch={get(firebase, 'dispatch')}
35-
{...props}
36-
/>
37-
)
38-
}
39-
40-
WithFirebase.displayName = wrapDisplayName(WrappedComponent, 'withFirebase')
41-
WithFirebase.wrappedComponent = WrappedComponent
42-
43-
return hoistStatics(WithFirebase, WrappedComponent)
44-
}
45-
467
/**
478
* @name withFirebase
489
* @extends React.Component
@@ -99,4 +60,20 @@ export const createWithFirebase = (storeKey = 'store') => WrappedComponent => {
9960
*
10061
* export default enhance(AddTodo)
10162
*/
102-
export default createWithFirebase()
63+
export default function withFirebase(WrappedComponent) {
64+
const WithFirebase = function WithFirebase(props) {
65+
const firebase = useFirebase()
66+
return (
67+
<WrappedComponent
68+
firebase={firebase}
69+
dispatch={get(firebase, 'dispatch')}
70+
{...props}
71+
/>
72+
)
73+
}
74+
75+
WithFirebase.displayName = wrapDisplayName(WrappedComponent, 'withFirebase')
76+
WithFirebase.wrappedComponent = WrappedComponent
77+
78+
return hoistStatics(WithFirebase, WrappedComponent)
79+
}

src/withFirestore.js

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,6 @@ import { wrapDisplayName } from './utils'
55
import useFirebase from './useFirebase'
66
import useFirestore from './useFirestore'
77

8-
/**
9-
* @name createWithFirestore
10-
* @description Function that creates a Higher Order Component that
11-
* which provides `firebase`, `firestore`, and `dispatch` to React Components.
12-
*
13-
* **WARNING!!** This is an advanced feature, and should only be used when
14-
* needing to access a firebase instance created under a different store key.
15-
* @param {String} [storeKey='store'] - Name of redux store which contains
16-
* Firestore state (`state.firestore`)
17-
* @return {Function} - Higher Order Component which accepts an array of
18-
* watchers config and wraps a React Component
19-
* @example <caption>Basic</caption>
20-
* import { createWithFirestore } from 'react-redux-firebase'
21-
*
22-
* // create withFirestore that uses another redux store
23-
* const withFirestore = createWithFirestore('anotherStore')
24-
*
25-
* // use the withFirestore to wrap a component
26-
* export default withFirestore(SomeComponent)
27-
*/
28-
export const createWithFirestore = (storeKey = 'store') => WrappedComponent => {
29-
const WithFirestore = function WithFirestore(props) {
30-
const firebase = useFirebase()
31-
const firestore = useFirestore()
32-
return (
33-
<WrappedComponent
34-
firebase={firebase}
35-
dispatch={get(firebase, 'dispatch')}
36-
firestore={firestore}
37-
{...props}
38-
/>
39-
)
40-
}
41-
42-
WithFirestore.displayName = wrapDisplayName(WrappedComponent, 'withFirestore')
43-
WithFirestore.wrappedComponent = WrappedComponent
44-
45-
return hoistStatics(WithFirestore, WrappedComponent)
46-
}
47-
488
/**
499
* @name withFirestore
5010
* @extends React.Component
@@ -98,4 +58,22 @@ export const createWithFirestore = (storeKey = 'store') => WrappedComponent => {
9858
*
9959
* export default enhance(AddTodo)
10060
*/
101-
export default createWithFirestore()
61+
export default function withFirestore(WrappedComponent) {
62+
function WithFirestore(props) {
63+
const firebase = useFirebase()
64+
const firestore = useFirestore()
65+
return (
66+
<WrappedComponent
67+
firebase={firebase}
68+
dispatch={get(firebase, 'dispatch')}
69+
firestore={firestore}
70+
{...props}
71+
/>
72+
)
73+
}
74+
75+
WithFirestore.displayName = wrapDisplayName(WrappedComponent, 'withFirestore')
76+
WithFirestore.wrappedComponent = WrappedComponent
77+
78+
return hoistStatics(WithFirestore, WrappedComponent)
79+
}

test/unit/useFirebase.spec.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import TestUtils from 'react-dom/test-utils'
33
import { firebaseWithConfig } from '../utils'
44
import ReactReduxFirebaseProvider from '../../src/ReactReduxFirebaseProvider'
5-
import useFirebase, { createUseFirebase } from '../../src/useFirebase'
5+
import useFirebase from '../../src/useFirebase'
66

77
describe('useFirebase', () => {
88
it('return firebase object', () => {
@@ -25,9 +25,3 @@ describe('useFirebase', () => {
2525
expect(spy.lastCall.args[0]).to.respondTo('push')
2626
})
2727
})
28-
29-
describe('createUseFirebase', () => {
30-
it('return hook', () => {
31-
expect(createUseFirebase()).to.be.a('function')
32-
})
33-
})

test/unit/useFirestore.spec.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import TestUtils from 'react-dom/test-utils'
33
import { firebaseWithConfig } from '../utils'
44
import ReactReduxFirebaseProvider from '../../src/ReactReduxFirebaseProvider'
5-
import useFirestore, { createUseFirestore } from '../../src/useFirestore'
5+
import useFirestore from '../../src/useFirestore'
66
import { createFirestoreInstance } from 'redux-firestore'
77

88
describe('useFirestore', () => {
@@ -27,9 +27,3 @@ describe('useFirestore', () => {
2727
expect(spy.lastCall.args[0]).to.respondTo('add')
2828
})
2929
})
30-
31-
describe('createUseFirestore', () => {
32-
it('return hook', () => {
33-
expect(createUseFirestore()).to.be.a('function')
34-
})
35-
})

test/unit/withFirebase.spec.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import { createContainer, TestLeaf } from '../utils'
3-
import withFirebase, { createWithFirebase } from '../../src/withFirebase'
3+
import withFirebase from '../../src/withFirebase'
44

55
let wrapper
66
let leaf
@@ -48,9 +48,3 @@ describe('withFirebase', () => {
4848
expect(leaf).to.match(TestLeaf)
4949
})
5050
})
51-
52-
describe('createwithFirebase', () => {
53-
it('accepts a different store key', () => {
54-
createWithFirebase('store2')
55-
})
56-
})

test/unit/withFirestore.spec.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import { createContainer, TestLeaf } from '../utils'
3-
import withFirestore, { createWithFirestore } from '../../src/withFirestore'
3+
import withFirestore from '../../src/withFirestore'
44

55
let wrapper
66
let leaf
@@ -53,9 +53,3 @@ describe('withFirestore', () => {
5353
expect(leaf).to.match(TestLeaf)
5454
})
5555
})
56-
57-
describe('createwithFirestore', () => {
58-
it('accepts a store key', () => {
59-
createWithFirestore('store2')
60-
})
61-
})

0 commit comments

Comments
 (0)