Skip to content

Commit ec641a7

Browse files
committed
refactors out count variable in Subscription.js
1 parent c7f0efd commit ec641a7

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/utils/Subscription.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
// ancestor components re-render before descendants
44

55
function initListeners() {
6-
let count = 0
76
let current = []
87
let next = []
98

109
return {
1110
clear() {
12-
count = 0
1311
next = null
1412
current = null
1513
},
1614

1715
notify() {
1816
current = next
19-
for (let i = 0; i < count; i++) {
17+
for (let i = 0; i < current.length; i++) {
2018
current[i]()
2119
}
2220
},
@@ -25,15 +23,13 @@ function initListeners() {
2523
let isSubscribed = true
2624
if (next === current) next = current.slice()
2725
next.push(listener)
28-
count++
2926

3027
return function unsubscribe() {
31-
if (!isSubscribed || count === 0) return
28+
if (!isSubscribed || !current) return
3229
isSubscribed = false
3330

3431
if (next === current) next = current.slice()
3532
next.splice(next.indexOf(listener), 1)
36-
count--
3733
}
3834
}
3935
}

0 commit comments

Comments
 (0)