@@ -16,7 +16,7 @@ import ReduxFirestoreContext from './ReduxFirestoreContext'
16
16
* Firebase state (state.firebase)
17
17
* @return {Function } - HOC that accepts a watchArray and wraps a component
18
18
* @example <caption>Basic</caption>
19
- * // this. props.firebase set on App component as firebase object with helpers
19
+ * // props.firebase set on App component as firebase object with helpers
20
20
* import { createFirestoreConnect } from 'react-redux-firebase'
21
21
* // create firebase connect that uses another redux store
22
22
* const firestoreConnect = createFirestoreConnect('anotherStore')
@@ -28,7 +28,10 @@ export const createFirestoreConnect = (storeKey = 'store') => (
28
28
) => WrappedComponent => {
29
29
class FirestoreConnectWrapped extends Component {
30
30
static wrappedComponent = WrappedComponent
31
- static displayName = wrapDisplayName ( WrappedComponent , 'FirestoreConnect' )
31
+ static displayName = wrapDisplayName (
32
+ WrappedComponent ,
33
+ 'FirestoreConnectWrapped'
34
+ )
32
35
33
36
prevData = null
34
37
@@ -37,20 +40,18 @@ export const createFirestoreConnect = (storeKey = 'store') => (
37
40
}
38
41
39
42
componentDidMount ( ) {
40
- const { firestore } = this . store
41
43
if ( this . firestoreIsEnabled ) {
42
- // Allow function to be passed
44
+ // Listener configs as object (handling function being passed)
43
45
const inputAsFunc = createCallable ( dataOrFn )
44
46
this . prevData = inputAsFunc ( this . props , this . props )
45
-
46
- firestore . setListeners ( this . prevData )
47
+ // Attach listeners based on listener config
48
+ this . props . firestore . setListeners ( this . prevData )
47
49
}
48
50
}
49
51
50
- componentDidUnmount ( ) {
51
- const { firestore } = this . store
52
+ componentWillUnmount ( ) {
52
53
if ( this . firestoreIsEnabled && this . prevData ) {
53
- firestore . unsetListeners ( this . prevData )
54
+ this . props . firestore . unsetListeners ( this . prevData )
54
55
}
55
56
}
56
57
@@ -59,7 +60,7 @@ export const createFirestoreConnect = (storeKey = 'store') => (
59
60
const inputAsFunc = createCallable ( dataOrFn )
60
61
const data = inputAsFunc ( np , this . props )
61
62
62
- // Handle changes to data
63
+ // Check for changes in the listener configs
63
64
if ( this . firestoreIsEnabled && ! isEqual ( data , this . prevData ) ) {
64
65
const changes = this . getChanges ( data , this . prevData )
65
66
@@ -86,7 +87,7 @@ export const createFirestoreConnect = (storeKey = 'store') => (
86
87
}
87
88
88
89
FirestoreConnectWrapped . propTypes = {
89
- dispatch : PropTypes . func . isRequired ,
90
+ dispatch : PropTypes . func ,
90
91
firebase : PropTypes . object ,
91
92
firestore : PropTypes . object
92
93
}
@@ -98,6 +99,10 @@ export const createFirestoreConnect = (storeKey = 'store') => (
98
99
{ firestore => < HoistedComp firestore = { firestore } { ...props } /> }
99
100
</ ReduxFirestoreContext . Consumer >
100
101
)
102
+ FirestoreConnect . displayName = wrapDisplayName (
103
+ WrappedComponent ,
104
+ 'FirestoreConnect'
105
+ )
101
106
102
107
FirestoreConnect . propTypes = {
103
108
dispatch : PropTypes . func . isRequired
@@ -118,20 +123,18 @@ export const createFirestoreConnect = (storeKey = 'store') => (
118
123
* is passed the current props and the firebase object.
119
124
* @return {Function } - that accepts a component to wrap and returns the wrapped component
120
125
* @example <caption>Basic</caption>
121
- * // this. props.firebase set on App component as firebase object with helpers
126
+ * // props.firebase set on App component as firebase object with helpers
122
127
* import { firestoreConnect } from 'react-redux-firebase'
123
128
* export default firestoreConnect()(SomeComponent)
124
129
* @example <caption>Basic</caption>
125
130
* import { connect } from 'react-redux'
126
131
* import { firestoreConnect } from 'react-redux-firebase'
127
132
*
128
- * // pass todos list from redux as this. props.todosList
133
+ * // pass todos list from redux as props.todosList
129
134
* export default compose(
130
- * firestoreConnect(['todos']), // sync todos collection from Firestore into redux
135
+ * firestoreConnect(() => ['todos']), // sync todos collection from Firestore into redux
131
136
* connect((state) => ({
132
- * todosList: state.firestore.data.todos,
133
- * profile: state.firestore.profile, // pass profile data as this.props.profile
134
- * auth: state.firestore.auth // pass auth data as this.props.auth
137
+ * todosList: state.firestore.data.todos
135
138
* })
136
139
* )(SomeComponent)
137
140
*/
0 commit comments