File tree 2 files changed +8
-5
lines changed
2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ export default function createConnect(React) {
54
54
55
55
shouldComponentUpdate ( nextProps , nextState ) {
56
56
return (
57
- this . subscribed &&
57
+ this . isSubscribed ( ) &&
58
58
! areStatePropsEqual ( this . state . stateProps , nextState . stateProps )
59
59
) || ! shallowEqualScalar ( this . props , nextProps ) ;
60
60
}
@@ -68,15 +68,18 @@ export default function createConnect(React) {
68
68
} ;
69
69
}
70
70
71
+ isSubscribed ( ) {
72
+ return typeof this . unsubscribe === 'function' ;
73
+ }
74
+
71
75
componentDidMount ( ) {
72
76
if ( shouldSubscribe ) {
73
- this . subscribed = true ;
74
77
this . unsubscribe = this . context . store . subscribe ( ::this . handleChange ) ;
75
78
}
76
79
}
77
80
78
81
componentWillUnmount ( ) {
79
- if ( shouldSubscribe ) {
82
+ if ( this . isSubscribed ( ) ) {
80
83
this . unsubscribe ( ) ;
81
84
}
82
85
}
Original file line number Diff line number Diff line change @@ -241,7 +241,7 @@ describe('React', () => {
241
241
TestUtils . findRenderedComponentWithType ( container , Container )
242
242
) . toNotThrow ( ) ;
243
243
const decorated = TestUtils . findRenderedComponentWithType ( container , Container ) ;
244
- expect ( decorated . subscribed ) . toBe ( true ) ;
244
+ expect ( decorated . isSubscribed ( ) ) . toBe ( true ) ;
245
245
} ) ;
246
246
247
247
it ( 'should not subscribe to stores if mapState argument is falsy' , ( ) => {
@@ -268,7 +268,7 @@ describe('React', () => {
268
268
TestUtils . findRenderedComponentWithType ( container , Container )
269
269
) . toNotThrow ( ) ;
270
270
const decorated = TestUtils . findRenderedComponentWithType ( container , Container ) ;
271
- expect ( decorated . subscribed ) . toNotBe ( true ) ;
271
+ expect ( decorated . isSubscribed ( ) ) . toNotBe ( true ) ;
272
272
} ) ;
273
273
274
274
it ( 'should unsubscribe before unmounting' , ( ) => {
You can’t perform that action at this time.
0 commit comments