Skip to content

Commit

Permalink
Simplify, pretty up, and remove vars
Browse files Browse the repository at this point in the history
  • Loading branch information
timdorr authored Nov 6, 2019
1 parent 2f57bcc commit 58a4b27
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/utils/Subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ import { getBatch } from './batch'
const nullListeners = { notify() {} }

function createListenerCollection() {
var batch = getBatch()
// the current/next pattern is copied from redux's createStore code.
// TODO: refactor+expose that code to be reusable here?
const batch = getBatch()
let listeners = {}
let id = 0

var current = {}
var id = 0
return {
clear() {
current = {}
listeners = {}
},

notify() {
var listeners = current
batch(() => {
for (const id in listeners) {
listeners[id]()
Expand All @@ -27,14 +25,15 @@ function createListenerCollection() {
},

get() {
return current
return listeners
},

subscribe(listener) {
var currentId = id++
current[currentId] = listener
const currentId = id++
listeners[currentId] = listener

return function unsubscribe() {
delete current[currentId]
delete listeners[currentId]
}
}
}
Expand Down

0 comments on commit 58a4b27

Please sign in to comment.