Skip to content

Commit

Permalink
refactor onceWhen internals
Browse files Browse the repository at this point in the history
  • Loading branch information
staltz committed Mar 3, 2021
1 parent 3a4f89e commit 0f6273f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ function onceWhen(obv, filter, cb) {
remove = obv((x) => {
if (!filter(x)) return
if (answered) {
if (remove) remove(), (remove = null)
if (remove) {
remove()
remove = null
}
} else {
answered = true
if (remove) remove(), (remove = null)
if (remove) {
remove()
remove = null
}
cb()
}
})
Expand Down

0 comments on commit 0f6273f

Please sign in to comment.