Skip to content

Commit

Permalink
Fix MithrilJS#2197 end all in chain when calling end(true)
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Aug 8, 2018
1 parent d64e0a9 commit 7cf72f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion stream/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ function registerDependency(stream, parents) {
}
}
function unregisterStream(stream) {
for (var i = 0; i < stream._state.parents.length; i++) {
var i = stream._state.parents.length
while (i--) {
var parent = stream._state.parents[i]
delete parent._state.deps[stream._state.id]
stream._state.parents.splice(i, 1)
}

for (var id in stream._state.deps) {
var dependent = stream._state.deps[id]
var index = dependent._state.parents.indexOf(stream)
Expand Down
11 changes: 11 additions & 0 deletions stream/tests/test-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,17 @@ o.spec("stream", function() {

o(doubled()).equals(undefined)
})
o("end stops all dependant streams", function() {
var stream = Stream()
var stream2 = stream.map(function(v) { return v })
var stream3 = stream2.map(function(v) { return v })

stream3.end(true)

stream(3)

o(stream3()).equals(undefined)
})
o("end stream works with default value", function() {
var stream = Stream(2)
var doubled = Stream.combine(function(stream) {return stream() * 2}, [stream])
Expand Down

0 comments on commit 7cf72f1

Please sign in to comment.