handle HALT as a value correctly
This commit is contained in:
parent
9d38c12630
commit
701e2d8e31
2 changed files with 17 additions and 3 deletions
|
|
@ -3,12 +3,12 @@
|
||||||
var guid = 0, noop = function() {}, HALT = {}
|
var guid = 0, noop = function() {}, HALT = {}
|
||||||
function createStream() {
|
function createStream() {
|
||||||
function stream() {
|
function stream() {
|
||||||
if (arguments.length > 0) updateStream(stream, arguments[0], undefined)
|
if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, arguments[0], undefined)
|
||||||
return stream._state.value
|
return stream._state.value
|
||||||
}
|
}
|
||||||
initStream(stream, arguments)
|
initStream(stream, arguments)
|
||||||
|
|
||||||
if (arguments.length > 0) updateStream(stream, arguments[0], undefined)
|
if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, arguments[0], undefined)
|
||||||
|
|
||||||
return stream
|
return stream
|
||||||
}
|
}
|
||||||
|
|
@ -23,7 +23,7 @@ function initStream(stream, args) {
|
||||||
error: {get: function() {
|
error: {get: function() {
|
||||||
if (!stream._state.errorStream) {
|
if (!stream._state.errorStream) {
|
||||||
var errorStream = function() {
|
var errorStream = function() {
|
||||||
if (arguments.length > 0) updateStream(stream, undefined, arguments[0])
|
if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, undefined, arguments[0])
|
||||||
return stream._state.error
|
return stream._state.error
|
||||||
}
|
}
|
||||||
initStream(errorStream, [])
|
initStream(errorStream, [])
|
||||||
|
|
|
||||||
|
|
@ -458,6 +458,20 @@ o.spec("stream", function() {
|
||||||
|
|
||||||
o(mapped()).equals("undefined")
|
o(mapped()).equals("undefined")
|
||||||
})
|
})
|
||||||
|
o("does not run when initialized w/ HALT", function() {
|
||||||
|
var stream = Stream.stream(Stream.HALT)
|
||||||
|
var mapped = stream.run(function(value) {return 123})
|
||||||
|
|
||||||
|
o(mapped()).equals(undefined)
|
||||||
|
})
|
||||||
|
o("does not run when set to HALT", function() {
|
||||||
|
var stream = Stream.stream()
|
||||||
|
var mapped = stream.run(function(value) {return 123})
|
||||||
|
|
||||||
|
stream(Stream.HALT)
|
||||||
|
|
||||||
|
o(mapped()).equals(undefined)
|
||||||
|
})
|
||||||
o("works with default undefined value", function() {
|
o("works with default undefined value", function() {
|
||||||
var stream = Stream.stream(undefined)
|
var stream = Stream.stream(undefined)
|
||||||
var mapped = stream.run(function(value) {return String(value)})
|
var mapped = stream.run(function(value) {return String(value)})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue