@@ -16,7 +16,7 @@ import ReduxFirestoreContext from './ReduxFirestoreContext'
1616 * Firebase state (state.firebase)
1717 * @return {Function } - HOC that accepts a watchArray and wraps a component
1818 * @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
2020 * import { createFirestoreConnect } from 'react-redux-firebase'
2121 * // create firebase connect that uses another redux store
2222 * const firestoreConnect = createFirestoreConnect('anotherStore')
@@ -28,7 +28,10 @@ export const createFirestoreConnect = (storeKey = 'store') => (
2828) => WrappedComponent => {
2929 class FirestoreConnectWrapped extends Component {
3030 static wrappedComponent = WrappedComponent
31- static displayName = wrapDisplayName ( WrappedComponent , 'FirestoreConnect' )
31+ static displayName = wrapDisplayName (
32+ WrappedComponent ,
33+ 'FirestoreConnectWrapped'
34+ )
3235
3336 prevData = null
3437
@@ -37,20 +40,18 @@ export const createFirestoreConnect = (storeKey = 'store') => (
3740 }
3841
3942 componentDidMount ( ) {
40- const { firestore } = this . store
4143 if ( this . firestoreIsEnabled ) {
42- // Allow function to be passed
44+ // Listener configs as object (handling function being passed)
4345 const inputAsFunc = createCallable ( dataOrFn )
4446 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 )
4749 }
4850 }
4951
50- componentDidUnmount ( ) {
51- const { firestore } = this . store
52+ componentWillUnmount ( ) {
5253 if ( this . firestoreIsEnabled && this . prevData ) {
53- firestore . unsetListeners ( this . prevData )
54+ this . props . firestore . unsetListeners ( this . prevData )
5455 }
5556 }
5657
@@ -59,7 +60,7 @@ export const createFirestoreConnect = (storeKey = 'store') => (
5960 const inputAsFunc = createCallable ( dataOrFn )
6061 const data = inputAsFunc ( np , this . props )
6162
62- // Handle changes to data
63+ // Check for changes in the listener configs
6364 if ( this . firestoreIsEnabled && ! isEqual ( data , this . prevData ) ) {
6465 const changes = this . getChanges ( data , this . prevData )
6566
@@ -86,7 +87,7 @@ export const createFirestoreConnect = (storeKey = 'store') => (
8687 }
8788
8889 FirestoreConnectWrapped . propTypes = {
89- dispatch : PropTypes . func . isRequired ,
90+ dispatch : PropTypes . func ,
9091 firebase : PropTypes . object ,
9192 firestore : PropTypes . object
9293 }
@@ -98,6 +99,10 @@ export const createFirestoreConnect = (storeKey = 'store') => (
9899 { firestore => < HoistedComp firestore = { firestore } { ...props } /> }
99100 </ ReduxFirestoreContext . Consumer >
100101 )
102+ FirestoreConnect . displayName = wrapDisplayName (
103+ WrappedComponent ,
104+ 'FirestoreConnect'
105+ )
101106
102107 FirestoreConnect . propTypes = {
103108 dispatch : PropTypes . func . isRequired
@@ -118,20 +123,18 @@ export const createFirestoreConnect = (storeKey = 'store') => (
118123 * is passed the current props and the firebase object.
119124 * @return {Function } - that accepts a component to wrap and returns the wrapped component
120125 * @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
122127 * import { firestoreConnect } from 'react-redux-firebase'
123128 * export default firestoreConnect()(SomeComponent)
124129 * @example <caption>Basic</caption>
125130 * import { connect } from 'react-redux'
126131 * import { firestoreConnect } from 'react-redux-firebase'
127132 *
128- * // pass todos list from redux as this. props.todosList
133+ * // pass todos list from redux as props.todosList
129134 * export default compose(
130- * firestoreConnect(['todos']), // sync todos collection from Firestore into redux
135+ * firestoreConnect(() => ['todos']), // sync todos collection from Firestore into redux
131136 * 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
135138 * })
136139 * )(SomeComponent)
137140 */
0 commit comments