File tree 1 file changed +12
-3
lines changed
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import Context , { createHashFunction } from './Context'
4
+ import shallowEqual from '../utils/shallowEqual'
4
5
5
6
const ContextProvider = Context . Provider
6
7
@@ -32,13 +33,21 @@ class Provider extends Component {
32
33
}
33
34
34
35
componentDidUpdate ( lastProps ) {
35
- if ( lastProps . store !== this . props . store ) {
36
+ const state = this . props . store . getState ( )
37
+ const storesEqual = lastProps . store === this . props . store
38
+ if ( ! storesEqual ) {
36
39
if ( this . unsubscribe ) this . unsubscribe ( )
37
40
this . unsubscribe = this . props . store . subscribe ( this . triggerUpdateOnStoreStateChange . bind ( this ) )
38
- const state = this . props . store . getState ( )
39
41
this . setState ( {
40
42
state,
41
- store : this . props . store ,
43
+ store : this . props . store
44
+ } )
45
+ }
46
+ if (
47
+ ! storesEqual ||
48
+ ! shallowEqual ( Object . keys ( state ) , Object . keys ( lastProps . store . getState ( ) ) )
49
+ ) {
50
+ this . setState ( {
42
51
hashFunction : createHashFunction ( state )
43
52
} )
44
53
}
You can’t perform that action at this time.
0 commit comments