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 22// well as nesting subscriptions of descendant components, so that we can ensure the
33// ancestor components re-render before descendants
44
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?
610 let current = [ ]
711 let next = [ ]
812
913 return {
1014 clear ( ) {
11- next = null
12- current = null
15+ next = CLEARED
16+ current = CLEARED
1317 } ,
1418
1519 notify ( ) {
@@ -25,7 +29,7 @@ function initListeners() {
2529 next . push ( listener )
2630
2731 return function unsubscribe ( ) {
28- if ( ! isSubscribed || ! current ) return
32+ if ( ! isSubscribed || current === CLEARED ) return
2933 isSubscribed = false
3034
3135 if ( next === current ) next = current . slice ( )
@@ -42,7 +46,7 @@ export default class Subscription {
4246 : store . subscribe . bind ( store )
4347
4448 this . unsubscribe = null
45- this . listeners = initListeners ( )
49+ this . listeners = createListenerCollection ( )
4650 }
4751
4852 addNestedSub ( listener ) {
You can’t perform that action at this time.
0 commit comments