File tree 2 files changed +35
-2
lines changed
2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ export default function createConnector(React) {
44
44
45
45
componentDidMount ( ) {
46
46
this . unsubscribe = this . context . store . subscribe ( ::this . handleChange ) ;
47
+ this . handleChange ( ) ;
47
48
}
48
49
49
50
componentWillReceiveProps ( nextProps ) {
@@ -59,7 +60,9 @@ export default function createConnector(React) {
59
60
60
61
handleChange ( props = this . props ) {
61
62
const nextState = this . selectState ( props , this . context ) ;
62
- this . setState ( nextState ) ;
63
+ if ( ! this . isSliceEqual ( this . state . slice , nextState . slice ) ) {
64
+ this . setState ( nextState ) ;
65
+ }
63
66
}
64
67
65
68
selectState ( props , context ) {
Original file line number Diff line number Diff line change @@ -245,7 +245,7 @@ describe('React', () => {
245
245
}
246
246
247
247
render ( ) {
248
- return ( < div > { this . props . string } </ div > ) ;
248
+ return < div > { this . props . string } </ div > ;
249
249
}
250
250
}
251
251
@@ -261,5 +261,35 @@ describe('React', () => {
261
261
262
262
expect ( ( ) => renderToString ( el ) ) . toNotThrow ( ) ;
263
263
} ) ;
264
+
265
+ it ( 'should handle dispatch inside componentDidMount' , ( ) => {
266
+ const store = createStore ( stringBuilder ) ;
267
+
268
+ class TestComp extends Component {
269
+ componentDidMount ( ) {
270
+ store . dispatch ( {
271
+ type : 'APPEND' ,
272
+ body : 'a'
273
+ } ) ;
274
+ }
275
+
276
+ render ( ) {
277
+ return < div > { this . props . string } </ div > ;
278
+ }
279
+ }
280
+
281
+ const tree = TestUtils . renderIntoDocument (
282
+ < Provider store = { store } >
283
+ { ( ) => (
284
+ < Connector select = { string => ( { string } ) } >
285
+ { ( { string } ) => < TestComp string = { string } /> }
286
+ </ Connector >
287
+ ) }
288
+ </ Provider >
289
+ ) ;
290
+
291
+ const testComp = TestUtils . findRenderedComponentWithType ( tree , TestComp ) ;
292
+ expect ( testComp . props . string ) . toBe ( 'a' ) ;
293
+ } ) ;
264
294
} ) ;
265
295
} ) ;
You can’t perform that action at this time.
0 commit comments