Unregister the end streams after their dependents have run fix #1736
This commit is contained in:
parent
3578d0ffb3
commit
f22f884b1e
3 changed files with 18 additions and 10 deletions
|
|
@ -1,6 +1,7 @@
|
|||
.vscode
|
||||
/node_modules
|
||||
/examples
|
||||
/coverage
|
||||
/docs/lib
|
||||
/examples
|
||||
/mithril.js
|
||||
/mithril.min.js
|
||||
/node_modules
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ function createStream() {
|
|||
}
|
||||
function initStream(stream) {
|
||||
stream.constructor = createStream
|
||||
stream._state = {id: guid++, value: undefined, state: 0, derive: undefined, recover: undefined, deps: {}, parents: [], endStream: undefined}
|
||||
stream._state = {id: guid++, value: undefined, state: 0, derive: undefined, recover: undefined, deps: {}, parents: [], endStream: undefined, unregister: undefined}
|
||||
stream.map = stream["fantasy-land/map"] = map, stream["fantasy-land/ap"] = ap, stream["fantasy-land/of"] = createStream
|
||||
stream.valueOf = valueOf, stream.toJSON = toJSON, stream.toString = valueOf
|
||||
|
||||
|
|
@ -25,7 +25,10 @@ function initStream(stream) {
|
|||
if (!stream._state.endStream) {
|
||||
var endStream = createStream()
|
||||
endStream.map(function(value) {
|
||||
if (value === true) unregisterStream(stream), unregisterStream(endStream)
|
||||
if (value === true) {
|
||||
unregisterStream(stream)
|
||||
endStream._state.unregister = function(){unregisterStream(endStream)}
|
||||
}
|
||||
return value
|
||||
})
|
||||
stream._state.endStream = endStream
|
||||
|
|
@ -37,6 +40,7 @@ function initStream(stream) {
|
|||
function updateStream(stream, value) {
|
||||
updateState(stream, value)
|
||||
for (var id in stream._state.deps) updateDependency(stream._state.deps[id], false)
|
||||
if (stream._state.unregister != null) stream._state.unregister()
|
||||
finalize(stream)
|
||||
}
|
||||
function updateState(stream, value) {
|
||||
|
|
|
|||
|
|
@ -264,14 +264,17 @@ o.spec("stream", function() {
|
|||
o(doubled()).equals(4)
|
||||
})
|
||||
o("end stream can be mapped to", function() {
|
||||
var stream = Stream()
|
||||
var spy = o.spy()
|
||||
var stream = Stream()
|
||||
var spy = o.spy()
|
||||
|
||||
stream.end.map(spy)
|
||||
stream.end(true)
|
||||
stream.end.map(spy)
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
o(spy.callCount).equals(0)
|
||||
|
||||
stream.end(true)
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
})
|
||||
o.spec("valueOf", function() {
|
||||
o("works", function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue