File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 2
2
// well as nesting subscriptions of descendant components, so that we can ensure the
3
3
// ancestor components re-render before descendants
4
4
5
- function initListeners ( ) {
5
+ const CLEARED = null
6
+
7
+ function createListenerCollection ( ) {
8
+ // the current/next pattern is copied from redux's createStore code.
9
+ // TODO: refactor+expose that code to be reusable here?
6
10
let current = [ ]
7
11
let next = [ ]
8
12
9
13
return {
10
14
clear ( ) {
11
- next = null
12
- current = null
15
+ next = CLEARED
16
+ current = CLEARED
13
17
} ,
14
18
15
19
notify ( ) {
@@ -25,7 +29,7 @@ function initListeners() {
25
29
next . push ( listener )
26
30
27
31
return function unsubscribe ( ) {
28
- if ( ! isSubscribed || ! current ) return
32
+ if ( ! isSubscribed || current === CLEARED ) return
29
33
isSubscribed = false
30
34
31
35
if ( next === current ) next = current . slice ( )
@@ -42,7 +46,7 @@ export default class Subscription {
42
46
: store . subscribe . bind ( store )
43
47
44
48
this . unsubscribe = null
45
- this . listeners = initListeners ( )
49
+ this . listeners = createListenerCollection ( )
46
50
}
47
51
48
52
addNestedSub ( listener ) {
You can’t perform that action at this time.
0 commit comments