@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
3
3
import hoistStatics from 'hoist-non-react-statics'
4
4
import { wrapDisplayName } from 'recompose'
5
5
import { createCallable } from './utils'
6
+ import { isEqual } from 'lodash'
6
7
7
8
/**
8
9
* @name createFirestoreConnect
@@ -22,70 +23,68 @@ import { createCallable } from './utils'
22
23
* // use the firebaseConnect to wrap a component
23
24
* export default firestoreConnect()(SomeComponent)
24
25
*/
25
- export const createFirestoreConnect = ( storeKey = 'store' ) =>
26
- ( dataOrFn = [ ] ) =>
27
- WrappedComponent => {
28
- class FirestoreConnect extends Component {
29
- static wrappedComponent = WrappedComponent
30
- static displayName = wrapDisplayName ( WrappedComponent , 'FirestoreConnect' )
31
- static contextTypes = {
32
- [ storeKey ] : PropTypes . object . isRequired
33
- }
26
+ export const createFirestoreConnect = ( storeKey = 'store' ) => (
27
+ dataOrFn = [ ]
28
+ ) => WrappedComponent => {
29
+ class FirestoreConnect extends Component {
30
+ static wrappedComponent = WrappedComponent
31
+ static displayName = wrapDisplayName ( WrappedComponent , 'FirestoreConnect' )
32
+ static contextTypes = {
33
+ [ storeKey ] : PropTypes . object . isRequired
34
+ }
34
35
35
- prevData = null
36
- store = this . context [ storeKey ]
36
+ prevData = null
37
+ store = this . context [ storeKey ]
37
38
38
- componentWillMount ( ) {
39
- const { firebase, firestore } = this . store
40
- if ( firebase . firestore && firestore ) {
41
- // Allow function to be passed
42
- const inputAsFunc = createCallable ( dataOrFn )
43
- this . prevData = inputAsFunc ( this . props , this . store )
39
+ componentWillMount ( ) {
40
+ const { firebase, firestore } = this . store
41
+ if ( firebase . firestore && firestore ) {
42
+ // Allow function to be passed
43
+ const inputAsFunc = createCallable ( dataOrFn )
44
+ this . prevData = inputAsFunc ( this . props , this . store )
44
45
45
- firestore . setListeners ( this . prevData )
46
- }
47
- }
46
+ firestore . setListeners ( this . prevData )
47
+ }
48
+ }
48
49
49
- componentWillUnmount ( ) {
50
- const { firebase, firestore } = this . store
51
- if ( firebase . firestore && this . prevData ) {
52
- firestore . unsetListeners ( this . prevData )
53
- }
54
- }
50
+ componentWillUnmount ( ) {
51
+ const { firebase, firestore } = this . store
52
+ if ( firebase . firestore && this . prevData ) {
53
+ firestore . unsetListeners ( this . prevData )
54
+ }
55
+ }
55
56
56
- // TODO: Re-attach listeners on query path change
57
- // componentWillReceiveProps (np) {
58
- // const { firebase, dispatch } = this.context.store
59
- // const inputAsFunc = createCallable(dataOrFn)
60
- // const data = inputAsFunc(np, firebase)
61
- //
62
- // // Handle a data parameter having changed
63
- // if (!isEqual(data, this.prevData)) {
64
- // this.prevData = data
65
- // // UnWatch all current events
66
- // unWatchEvents(firebase, dispatch, this._firebaseEvents)
67
- // // Get watch events from new data
68
- // this._firebaseEvents = getEventsFromInput(data)
69
- // // Watch new events
70
- // watchEvents(firebase, dispatch, this._firebaseEvents)
71
- // }
72
- // }
57
+ // TODO: Re-attach listeners on query path change
58
+ componentWillReceiveProps ( np ) {
59
+ const { firebase, firestore } = this . store
60
+ const inputAsFunc = createCallable ( dataOrFn )
61
+ const data = inputAsFunc ( np , this . store )
73
62
74
- render ( ) {
75
- const { firebase, firestore } = this . store
76
- return (
77
- < WrappedComponent
78
- { ...this . props }
79
- { ...this . state }
80
- firebase = { { ...firebase , ...firebase . helpers } }
81
- firestore = { firestore }
82
- />
83
- )
84
- }
63
+ // Handle a data parameter having changed
64
+ if ( firebase . firestore && ! isEqual ( data , this . prevData ) ) {
65
+ this . prevData = data
66
+ // UnWatch all current events
67
+ firestore . unsetListeners ( this . prevData )
68
+ // Watch new events
69
+ firestore . setListeners ( this . prevData )
85
70
}
71
+ }
86
72
87
- return hoistStatics ( FirestoreConnect , WrappedComponent )
73
+ render ( ) {
74
+ const { firebase, firestore } = this . store
75
+ return (
76
+ < WrappedComponent
77
+ { ...this . props }
78
+ { ...this . state }
79
+ firebase = { { ...firebase , ...firebase . helpers } }
80
+ firestore = { firestore }
81
+ />
82
+ )
88
83
}
84
+ }
85
+
86
+ return hoistStatics ( FirestoreConnect , WrappedComponent )
87
+ }
89
88
90
89
/**
91
90
* @name firestoreConnect
0 commit comments