Skip to content

Commit

Permalink
Fix unsubscribe bug
Browse files Browse the repository at this point in the history
Fixes a bug that allowed a listener to still be called if it was
unregistered in another listener.
  • Loading branch information
mjackson committed Jan 9, 2017
1 parent 5f63459 commit 817af44
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions modules/createTransitionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,25 @@ const createTransitionManager = () => {

let listeners = []

const appendListener = (listener) => {
const appendListener = (fn) => {
let isActive = true

const listener = (...args) => {
if (isActive)
fn(...args)
}

listeners.push(listener)

return () => {
isActive = false
listeners = listeners.filter(item => item !== listener)
}
}

const notifyListeners = (...args) =>
const notifyListeners = (...args) => {
listeners.forEach(listener => listener(...args))
}

return {
setPrompt,
Expand Down

0 comments on commit 817af44

Please sign in to comment.