Skip to content

Commit def0a9c

Browse files
jimbollatimdorr
authored andcommitted
Fixes HMR error #513 (#567)
1 parent 7d4a2ae commit def0a9c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/utils/Subscription.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// ancestor components re-render before descendants
44

55
const CLEARED = null
6+
const nullListeners = { notify() {} }
67

78
function createListenerCollection() {
89
// the current/next pattern is copied from redux's createStore code.
@@ -41,12 +42,10 @@ function createListenerCollection() {
4142

4243
export default class Subscription {
4344
constructor(store, parentSub) {
44-
this.subscribe = parentSub
45-
? parentSub.addNestedSub.bind(parentSub)
46-
: store.subscribe.bind(store)
47-
45+
this.store = store
46+
this.parentSub = parentSub
4847
this.unsubscribe = null
49-
this.listeners = createListenerCollection()
48+
this.listeners = nullListeners
5049
}
5150

5251
addNestedSub(listener) {
@@ -64,17 +63,21 @@ export default class Subscription {
6463

6564
trySubscribe() {
6665
if (!this.unsubscribe) {
67-
this.unsubscribe = this.subscribe(this.onStateChange)
66+
// this.onStateChange is set by connectAdvanced.initSubscription()
67+
this.unsubscribe = this.parentSub
68+
? this.parentSub.addNestedSub(this.onStateChange)
69+
: this.store.subscribe(this.onStateChange)
70+
71+
this.listeners = createListenerCollection()
6872
}
6973
}
7074

7175
tryUnsubscribe() {
7276
if (this.unsubscribe) {
7377
this.unsubscribe()
78+
this.unsubscribe = null
7479
this.listeners.clear()
80+
this.listeners = nullListeners
7581
}
76-
this.unsubscribe = null
77-
this.subscribe = null
78-
this.listeners = { notify() {} }
7982
}
8083
}

0 commit comments

Comments
 (0)