Bundled output for commit 7eea1b1e62 [skip ci]

This commit is contained in:
Gandalf-the-Bot 2019-02-07 08:46:35 +00:00
parent 7eea1b1e62
commit b33f10d29b

View file

@ -21,11 +21,13 @@ function Stream(value) {
var dependentFns = [] var dependentFns = []
function stream(v) { function stream(v) {
if (arguments.length && v !== Stream.SKIP && open(stream)) { if (arguments.length && v !== Stream.SKIP) {
value = v value = v
stream.changing() if (open(stream)) {
stream.state = "active" stream.changing()
dependentStreams.forEach(function(s, i) { s(dependentFns[i](value)) }) stream.state = "active"
dependentStreams.forEach(function(s, i) { s(dependentFns[i](value)) })
}
} }
return value return value
@ -33,11 +35,11 @@ function Stream(value) {
stream.constructor = Stream stream.constructor = Stream
stream.state = arguments.length && value !== Stream.SKIP ? "active" : "pending" stream.state = arguments.length && value !== Stream.SKIP ? "active" : "pending"
stream.parents = []
stream.changing = function() { stream.changing = function() {
open(stream) && (stream.state = "changing") open(stream) && (stream.state = "changing")
dependentStreams.forEach(function(s) { dependentStreams.forEach(function(s) {
s.dependent && s.dependent.changing()
s.changing() s.changing()
}) })
} }
@ -46,6 +48,7 @@ function Stream(value) {
var target = stream.state === "active" && ignoreInitial !== Stream.SKIP var target = stream.state === "active" && ignoreInitial !== Stream.SKIP
? Stream(fn(value)) ? Stream(fn(value))
: Stream() : Stream()
target.parents.push(stream)
dependentStreams.push(target) dependentStreams.push(target)
dependentFns.push(fn) dependentFns.push(fn)
@ -57,8 +60,9 @@ function Stream(value) {
end = Stream() end = Stream()
end.map(function(value) { end.map(function(value) {
if (value === true) { if (value === true) {
stream.parents.forEach(function (p) {p.unregisterChild(stream)})
stream.state = "ended" stream.state = "ended"
dependentStreams.length = dependentFns.length = 0 stream.parents.length = dependentStreams.length = dependentFns.length = 0
} }
return value return value
}) })
@ -70,6 +74,14 @@ function Stream(value) {
stream["fantasy-land/map"] = stream.map stream["fantasy-land/map"] = stream.map
stream["fantasy-land/ap"] = function(x) { return combine(function(s1, s2) { return s1()(s2()) }, [x, stream]) } stream["fantasy-land/ap"] = function(x) { return combine(function(s1, s2) { return s1()(s2()) }, [x, stream]) }
stream.unregisterChild = function(child) {
var childIndex = dependentStreams.indexOf(child)
if (childIndex !== -1) {
dependentStreams.splice(childIndex, 1)
dependentFns.splice(childIndex, 1)
}
}
Object.defineProperty(stream, "end", { Object.defineProperty(stream, "end", {
get: function() { return end || createEnd() } get: function() { return end || createEnd() }
}) })
@ -89,8 +101,8 @@ function combine(fn, streams) {
var changed = [] var changed = []
streams.forEach(function(s) { var mappers = streams.map(function(s) {
s.map(function(value) { return s.map(function(value) {
changed.push(s) changed.push(s)
if (ready || streams.every(function(s) { return s.state !== "pending" })) { if (ready || streams.every(function(s) { return s.state !== "pending" })) {
ready = true ready = true
@ -98,7 +110,15 @@ function combine(fn, streams) {
changed = [] changed = []
} }
return value return value
}, Stream.SKIP).parent = stream }, Stream.SKIP)
})
var endStream = stream.end.map(function(value) {
if (value === true) {
mappers.forEach(function(mapper) { mapper.end(true) })
endStream.end(true)
}
return undefined
}) })
return stream return stream