fix stream uncaught error reporting
fix stream JSON stringification rename internal render function to `use`
This commit is contained in:
parent
499a9ccc6d
commit
2ee15e3639
5 changed files with 424 additions and 382 deletions
|
|
@ -11,13 +11,13 @@ module.exports = function($window, renderer, pubsub) {
|
|||
var replay = router.defineRoutes(routes, function(payload, args, path, route) {
|
||||
if (typeof payload.view !== "function") {
|
||||
if (typeof payload.render !== "function") payload.render = function(vnode) {return vnode}
|
||||
var render = function(component) {
|
||||
var use = function(component) {
|
||||
current.path = path, current.component = component
|
||||
renderer.render(root, payload.render(Vnode(component, null, args, undefined, undefined, undefined)))
|
||||
}
|
||||
if (typeof payload.resolve !== "function") payload.resolve = function() {render(current.component)}
|
||||
if (path !== current.path) payload.resolve(render, args, path, route)
|
||||
else render(current.component)
|
||||
if (typeof payload.resolve !== "function") payload.resolve = function() {use(current.component)}
|
||||
if (path !== current.path) payload.resolve(use, args, path, route)
|
||||
else use(current.component)
|
||||
}
|
||||
else {
|
||||
renderer.render(root, Vnode(payload, null, args, undefined, undefined, undefined))
|
||||
|
|
|
|||
2
index.js
2
index.js
|
|
@ -1,6 +1,6 @@
|
|||
"use strict"
|
||||
|
||||
var Stream = require("./util/stream")
|
||||
var Stream = require("./util/stream")(console.error.bind(console))
|
||||
var m = require("./render/hyperscript")
|
||||
var renderService = require("./render/render")(window)
|
||||
var requestService = require("./request/request")(window)
|
||||
|
|
|
|||
120
mithril.js
120
mithril.js
|
|
@ -1,6 +1,7 @@
|
|||
new function() {
|
||||
var guid = 0, noop = function() {}, HALT = {}
|
||||
function createStream() {
|
||||
var Stream = function(log) {
|
||||
var guid = 0, noop = function() {}, HALT = {}
|
||||
function createStream() {
|
||||
function stream() {
|
||||
if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, arguments[0], undefined)
|
||||
return stream._state.value
|
||||
|
|
@ -8,8 +9,8 @@ function createStream() {
|
|||
initStream(stream, arguments)
|
||||
if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, arguments[0], undefined)
|
||||
return stream
|
||||
}
|
||||
function initStream(stream, args) {
|
||||
}
|
||||
function initStream(stream, args) {
|
||||
stream.constructor = createStream
|
||||
stream._state = {id: guid++, value: undefined, error: undefined, state: 0, derive: undefined, recover: undefined, deps: {}, parents: [], errorStream: undefined, endStream: undefined}
|
||||
stream.map = map, stream.ap = ap, stream.of = createStream
|
||||
|
|
@ -40,13 +41,13 @@ function initStream(stream, args) {
|
|||
return stream._state.endStream
|
||||
}}
|
||||
})
|
||||
}
|
||||
function updateStream(stream, value, error) {
|
||||
}
|
||||
function updateStream(stream, value, error) {
|
||||
updateState(stream, value, error)
|
||||
for (var id in stream._state.deps) updateDependency(stream._state.deps[id], false)
|
||||
finalize(stream)
|
||||
}
|
||||
function updateState(stream, value, error) {
|
||||
}
|
||||
function updateState(stream, value, error) {
|
||||
error = unwrapError(value, error)
|
||||
if (error !== undefined && typeof stream._state.recover === "function") {
|
||||
if (!resolve(stream, updateValues, true)) return
|
||||
|
|
@ -54,69 +55,69 @@ function updateState(stream, value, error) {
|
|||
else updateValues(stream, value, error)
|
||||
stream._state.changed = true
|
||||
if (stream._state.state !== 2) stream._state.state = 1
|
||||
}
|
||||
function updateValues(stream, value, error) {
|
||||
}
|
||||
function updateValues(stream, value, error) {
|
||||
stream._state.value = value
|
||||
stream._state.error = error
|
||||
}
|
||||
function updateDependency(stream, mustSync) {
|
||||
}
|
||||
function updateDependency(stream, mustSync) {
|
||||
var state = stream._state, parents = state.parents
|
||||
if (parents.length > 0 && parents.filter(active).length === parents.length && (mustSync || parents.filter(changed).length > 0)) {
|
||||
var failed = parents.filter(errored)
|
||||
if (failed.length > 0) updateState(stream, undefined, failed[0]._state.error)
|
||||
else resolve(stream, updateState, false)
|
||||
}
|
||||
}
|
||||
function resolve(stream, update, shouldRecover) {
|
||||
}
|
||||
function resolve(stream, update, shouldRecover) {
|
||||
try {
|
||||
var value = shouldRecover ? stream._state.recover() : stream._state.derive()
|
||||
if (value === HALT) return false
|
||||
update(stream, value, undefined)
|
||||
}
|
||||
catch (e) {
|
||||
update(stream, undefined, e)
|
||||
reportUncaughtError(stream, e)
|
||||
update(stream, undefined, e.__error != null ? e.__error : e)
|
||||
if (e.__error == null) reportUncaughtError(stream, e)
|
||||
}
|
||||
return true
|
||||
}
|
||||
function unwrapError(value, error) {
|
||||
}
|
||||
function unwrapError(value, error) {
|
||||
if (value != null && value.constructor === createStream) {
|
||||
if (value._state.error !== undefined) error = value._state.error
|
||||
else error = unwrapError(value._state.value, value._state.error)
|
||||
}
|
||||
return error
|
||||
}
|
||||
function finalize(stream) {
|
||||
}
|
||||
function finalize(stream) {
|
||||
stream._state.changed = false
|
||||
for (var id in stream._state.deps) stream._state.deps[id]._state.changed = false
|
||||
}
|
||||
function reportUncaughtError(stream, e) {
|
||||
if (Object.keys(stream._state.deps).length === 0 && stream._state.derive == null) {
|
||||
}
|
||||
function reportUncaughtError(stream, e) {
|
||||
if (Object.keys(stream._state.deps).length === 0) {
|
||||
setTimeout(function() {
|
||||
if (Object.keys(stream._state.deps).length === 0) console.error(e)
|
||||
if (Object.keys(stream._state.deps).length === 0) log(e)
|
||||
}, 0)
|
||||
}
|
||||
}
|
||||
function run(fn) {
|
||||
}
|
||||
function run(fn) {
|
||||
var self = createStream(), stream = this
|
||||
return initDependency(self, [stream], function() {
|
||||
return absorb(self, fn(stream()))
|
||||
}, undefined)
|
||||
}
|
||||
function doCatch(fn) {
|
||||
}
|
||||
function doCatch(fn) {
|
||||
var self = createStream(), stream = this
|
||||
var derive = function() {return stream._state.value}
|
||||
var recover = function() {return absorb(self, fn(stream._state.error))}
|
||||
return initDependency(self, [stream], derive, recover)
|
||||
}
|
||||
function combine(fn, streams) {
|
||||
}
|
||||
function combine(fn, streams) {
|
||||
return initDependency(createStream(), streams, function() {
|
||||
var failed = streams.filter(errored)
|
||||
if (failed.length > 0) throw failed[0]._state.error
|
||||
if (failed.length > 0) throw {__error: failed[0]._state.error}
|
||||
return fn.apply(this, streams.concat([streams.filter(changed)]))
|
||||
}, undefined)
|
||||
}
|
||||
function absorb(stream, value) {
|
||||
}
|
||||
function absorb(stream, value) {
|
||||
if (value != null && value.constructor === createStream) {
|
||||
var absorbable = value
|
||||
var update = function() {
|
||||
|
|
@ -125,16 +126,16 @@ function absorb(stream, value) {
|
|||
}
|
||||
absorbable.map(update).catch(function(e) {
|
||||
update()
|
||||
throw e
|
||||
throw {__error: e}
|
||||
})
|
||||
|
||||
if (absorbable._state.state === 0) return HALT
|
||||
if (absorbable._state.error) throw absorbable._state.error
|
||||
if (absorbable._state.error) throw {__error: absorbable._state.error}
|
||||
value = absorbable._state.value
|
||||
}
|
||||
return value
|
||||
}
|
||||
function initDependency(dep, streams, derive, recover) {
|
||||
}
|
||||
function initDependency(dep, streams, derive, recover) {
|
||||
var state = dep._state
|
||||
state.derive = derive
|
||||
state.recover = recover
|
||||
|
|
@ -142,14 +143,14 @@ function initDependency(dep, streams, derive, recover) {
|
|||
registerDependency(dep, state.parents)
|
||||
updateDependency(dep, true)
|
||||
return dep
|
||||
}
|
||||
function registerDependency(stream, parents) {
|
||||
}
|
||||
function registerDependency(stream, parents) {
|
||||
for (var i = 0; i < parents.length; i++) {
|
||||
parents[i]._state.deps[stream._state.id] = stream
|
||||
registerDependency(stream, parents[i]._state.parents)
|
||||
}
|
||||
}
|
||||
function unregisterStream(stream) {
|
||||
}
|
||||
function unregisterStream(stream) {
|
||||
for (var i = 0; i < stream._state.parents.length; i++) {
|
||||
var parent = stream._state.parents[i]
|
||||
delete parent._state.deps[stream._state.id]
|
||||
|
|
@ -161,26 +162,27 @@ function unregisterStream(stream) {
|
|||
}
|
||||
stream._state.state = 2 //ended
|
||||
stream._state.deps = {}
|
||||
}
|
||||
function map(fn) {return combine(function(stream) {return fn(stream())}, [this])}
|
||||
function ap(stream) {return combine(function(s1, s2) {return s1()(s2())}, [this, stream])}
|
||||
function valueOf() {return this._state.value}
|
||||
function toJSON() {return JSON.stringify(this._state.value)}
|
||||
function active(stream) {return stream._state.state === 1}
|
||||
function changed(stream) {return stream._state.changed}
|
||||
function notEnded(stream) {return stream._state.state !== 2}
|
||||
function errored(stream) {return stream._state.error}
|
||||
function reject(e) {
|
||||
}
|
||||
function map(fn) {return combine(function(stream) {return fn(stream())}, [this])}
|
||||
function ap(stream) {return combine(function(s1, s2) {return s1()(s2())}, [this, stream])}
|
||||
function valueOf() {return this._state.value}
|
||||
function toJSON() {return this._state.value != null && typeof this._state.value.toJSON === "function" ? this._state.value.toJSON() : this._state.value}
|
||||
function active(stream) {return stream._state.state === 1}
|
||||
function changed(stream) {return stream._state.changed}
|
||||
function notEnded(stream) {return stream._state.state !== 2}
|
||||
function errored(stream) {return stream._state.error}
|
||||
function reject(e) {
|
||||
var stream = createStream()
|
||||
stream.error(e)
|
||||
return stream
|
||||
}
|
||||
function merge(streams) {
|
||||
}
|
||||
function merge(streams) {
|
||||
return combine(function () {
|
||||
return streams.map(function(s) {return s()})
|
||||
}, streams)
|
||||
}
|
||||
var Stream = {stream: createStream, merge: merge, combine: combine, reject: reject, HALT: HALT}
|
||||
}
|
||||
return {stream: createStream, merge: merge, combine: combine, reject: reject, HALT: HALT}
|
||||
}(console.error.bind(console))
|
||||
function Vnode(tag, key, attrs, children, text, dom) {
|
||||
return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined}
|
||||
}
|
||||
|
|
@ -1087,13 +1089,13 @@ m.route = function($window, renderer, pubsub) {
|
|||
var replay = router.defineRoutes(routes, function(payload, args, path, route) {
|
||||
if (typeof payload.view !== "function") {
|
||||
if (typeof payload.render !== "function") payload.render = function(vnode) {return vnode}
|
||||
var render = function(component) {
|
||||
var use = function(component) {
|
||||
current.path = path, current.component = component
|
||||
renderer.render(root, payload.render(Vnode(component, null, args, undefined, undefined, undefined)))
|
||||
}
|
||||
if (typeof payload.resolve !== "function") payload.resolve = function() {render(current.component)}
|
||||
if (path !== current.path) payload.resolve(render, args, path, route)
|
||||
else render(current.component)
|
||||
if (typeof payload.resolve !== "function") payload.resolve = function() {use(current.component)}
|
||||
if (path !== current.path) payload.resolve(use, args, path, route)
|
||||
else use(current.component)
|
||||
}
|
||||
else {
|
||||
renderer.render(root, Vnode(payload, null, args, undefined, undefined, undefined))
|
||||
|
|
|
|||
112
util/stream.js
112
util/stream.js
|
|
@ -1,7 +1,8 @@
|
|||
"use strict"
|
||||
|
||||
var guid = 0, noop = function() {}, HALT = {}
|
||||
function createStream() {
|
||||
module.exports = function(log) {
|
||||
var guid = 0, noop = function() {}, HALT = {}
|
||||
function createStream() {
|
||||
function stream() {
|
||||
if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, arguments[0], undefined)
|
||||
return stream._state.value
|
||||
|
|
@ -11,8 +12,8 @@ function createStream() {
|
|||
if (arguments.length > 0 && arguments[0] !== HALT) updateStream(stream, arguments[0], undefined)
|
||||
|
||||
return stream
|
||||
}
|
||||
function initStream(stream, args) {
|
||||
}
|
||||
function initStream(stream, args) {
|
||||
stream.constructor = createStream
|
||||
stream._state = {id: guid++, value: undefined, error: undefined, state: 0, derive: undefined, recover: undefined, deps: {}, parents: [], errorStream: undefined, endStream: undefined}
|
||||
stream.map = map, stream.ap = ap, stream.of = createStream
|
||||
|
|
@ -44,13 +45,13 @@ function initStream(stream, args) {
|
|||
return stream._state.endStream
|
||||
}}
|
||||
})
|
||||
}
|
||||
function updateStream(stream, value, error) {
|
||||
}
|
||||
function updateStream(stream, value, error) {
|
||||
updateState(stream, value, error)
|
||||
for (var id in stream._state.deps) updateDependency(stream._state.deps[id], false)
|
||||
finalize(stream)
|
||||
}
|
||||
function updateState(stream, value, error) {
|
||||
}
|
||||
function updateState(stream, value, error) {
|
||||
error = unwrapError(value, error)
|
||||
if (error !== undefined && typeof stream._state.recover === "function") {
|
||||
if (!resolve(stream, updateValues, true)) return
|
||||
|
|
@ -58,70 +59,70 @@ function updateState(stream, value, error) {
|
|||
else updateValues(stream, value, error)
|
||||
stream._state.changed = true
|
||||
if (stream._state.state !== 2) stream._state.state = 1
|
||||
}
|
||||
function updateValues(stream, value, error) {
|
||||
}
|
||||
function updateValues(stream, value, error) {
|
||||
stream._state.value = value
|
||||
stream._state.error = error
|
||||
}
|
||||
function updateDependency(stream, mustSync) {
|
||||
}
|
||||
function updateDependency(stream, mustSync) {
|
||||
var state = stream._state, parents = state.parents
|
||||
if (parents.length > 0 && parents.filter(active).length === parents.length && (mustSync || parents.filter(changed).length > 0)) {
|
||||
var failed = parents.filter(errored)
|
||||
if (failed.length > 0) updateState(stream, undefined, failed[0]._state.error)
|
||||
else resolve(stream, updateState, false)
|
||||
}
|
||||
}
|
||||
function resolve(stream, update, shouldRecover) {
|
||||
}
|
||||
function resolve(stream, update, shouldRecover) {
|
||||
try {
|
||||
var value = shouldRecover ? stream._state.recover() : stream._state.derive()
|
||||
if (value === HALT) return false
|
||||
update(stream, value, undefined)
|
||||
}
|
||||
catch (e) {
|
||||
update(stream, undefined, e)
|
||||
reportUncaughtError(stream, e)
|
||||
update(stream, undefined, e.__error != null ? e.__error : e)
|
||||
if (e.__error == null) reportUncaughtError(stream, e)
|
||||
}
|
||||
return true
|
||||
}
|
||||
function unwrapError(value, error) {
|
||||
}
|
||||
function unwrapError(value, error) {
|
||||
if (value != null && value.constructor === createStream) {
|
||||
if (value._state.error !== undefined) error = value._state.error
|
||||
else error = unwrapError(value._state.value, value._state.error)
|
||||
}
|
||||
return error
|
||||
}
|
||||
function finalize(stream) {
|
||||
}
|
||||
function finalize(stream) {
|
||||
stream._state.changed = false
|
||||
for (var id in stream._state.deps) stream._state.deps[id]._state.changed = false
|
||||
}
|
||||
function reportUncaughtError(stream, e) {
|
||||
if (Object.keys(stream._state.deps).length === 0 && stream._state.derive == null) {
|
||||
}
|
||||
function reportUncaughtError(stream, e) {
|
||||
if (Object.keys(stream._state.deps).length === 0) {
|
||||
setTimeout(function() {
|
||||
if (Object.keys(stream._state.deps).length === 0) console.error(e)
|
||||
if (Object.keys(stream._state.deps).length === 0) log(e)
|
||||
}, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function run(fn) {
|
||||
function run(fn) {
|
||||
var self = createStream(), stream = this
|
||||
return initDependency(self, [stream], function() {
|
||||
return absorb(self, fn(stream()))
|
||||
}, undefined)
|
||||
}
|
||||
function doCatch(fn) {
|
||||
}
|
||||
function doCatch(fn) {
|
||||
var self = createStream(), stream = this
|
||||
var derive = function() {return stream._state.value}
|
||||
var recover = function() {return absorb(self, fn(stream._state.error))}
|
||||
return initDependency(self, [stream], derive, recover)
|
||||
}
|
||||
function combine(fn, streams) {
|
||||
}
|
||||
function combine(fn, streams) {
|
||||
return initDependency(createStream(), streams, function() {
|
||||
var failed = streams.filter(errored)
|
||||
if (failed.length > 0) throw failed[0]._state.error
|
||||
if (failed.length > 0) throw {__error: failed[0]._state.error}
|
||||
return fn.apply(this, streams.concat([streams.filter(changed)]))
|
||||
}, undefined)
|
||||
}
|
||||
function absorb(stream, value) {
|
||||
}
|
||||
function absorb(stream, value) {
|
||||
if (value != null && value.constructor === createStream) {
|
||||
var absorbable = value
|
||||
var update = function() {
|
||||
|
|
@ -130,17 +131,17 @@ function absorb(stream, value) {
|
|||
}
|
||||
absorbable.map(update).catch(function(e) {
|
||||
update()
|
||||
throw e
|
||||
throw {__error: e}
|
||||
})
|
||||
|
||||
if (absorbable._state.state === 0) return HALT
|
||||
if (absorbable._state.error) throw absorbable._state.error
|
||||
if (absorbable._state.error) throw {__error: absorbable._state.error}
|
||||
value = absorbable._state.value
|
||||
}
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
function initDependency(dep, streams, derive, recover) {
|
||||
function initDependency(dep, streams, derive, recover) {
|
||||
var state = dep._state
|
||||
state.derive = derive
|
||||
state.recover = recover
|
||||
|
|
@ -150,14 +151,14 @@ function initDependency(dep, streams, derive, recover) {
|
|||
updateDependency(dep, true)
|
||||
|
||||
return dep
|
||||
}
|
||||
function registerDependency(stream, parents) {
|
||||
}
|
||||
function registerDependency(stream, parents) {
|
||||
for (var i = 0; i < parents.length; i++) {
|
||||
parents[i]._state.deps[stream._state.id] = stream
|
||||
registerDependency(stream, parents[i]._state.parents)
|
||||
}
|
||||
}
|
||||
function unregisterStream(stream) {
|
||||
}
|
||||
function unregisterStream(stream) {
|
||||
for (var i = 0; i < stream._state.parents.length; i++) {
|
||||
var parent = stream._state.parents[i]
|
||||
delete parent._state.deps[stream._state.id]
|
||||
|
|
@ -169,28 +170,29 @@ function unregisterStream(stream) {
|
|||
}
|
||||
stream._state.state = 2 //ended
|
||||
stream._state.deps = {}
|
||||
}
|
||||
}
|
||||
|
||||
function map(fn) {return combine(function(stream) {return fn(stream())}, [this])}
|
||||
function ap(stream) {return combine(function(s1, s2) {return s1()(s2())}, [this, stream])}
|
||||
function valueOf() {return this._state.value}
|
||||
function toJSON() {return JSON.stringify(this._state.value)}
|
||||
function map(fn) {return combine(function(stream) {return fn(stream())}, [this])}
|
||||
function ap(stream) {return combine(function(s1, s2) {return s1()(s2())}, [this, stream])}
|
||||
function valueOf() {return this._state.value}
|
||||
function toJSON() {return this._state.value != null && typeof this._state.value.toJSON === "function" ? this._state.value.toJSON() : this._state.value}
|
||||
|
||||
function active(stream) {return stream._state.state === 1}
|
||||
function changed(stream) {return stream._state.changed}
|
||||
function notEnded(stream) {return stream._state.state !== 2}
|
||||
function errored(stream) {return stream._state.error}
|
||||
function active(stream) {return stream._state.state === 1}
|
||||
function changed(stream) {return stream._state.changed}
|
||||
function notEnded(stream) {return stream._state.state !== 2}
|
||||
function errored(stream) {return stream._state.error}
|
||||
|
||||
function reject(e) {
|
||||
function reject(e) {
|
||||
var stream = createStream()
|
||||
stream.error(e)
|
||||
return stream
|
||||
}
|
||||
}
|
||||
|
||||
function merge(streams) {
|
||||
function merge(streams) {
|
||||
return combine(function () {
|
||||
return streams.map(function(s) {return s()})
|
||||
}, streams)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {stream: createStream, merge: merge, combine: combine, reject: reject, HALT: HALT}
|
||||
return {stream: createStream, merge: merge, combine: combine, reject: reject, HALT: HALT}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,15 @@
|
|||
|
||||
var o = require("../../ospec/ospec")
|
||||
var callAsync = require("../../test-utils/callAsync")
|
||||
var Stream = require("../../util/stream")
|
||||
var StreamFactory = require("../../util/stream")
|
||||
|
||||
o.spec("stream", function() {
|
||||
var Stream, spy
|
||||
o.beforeEach(function() {
|
||||
spy = o.spy()
|
||||
Stream = StreamFactory(spy)
|
||||
})
|
||||
|
||||
o.spec("stream", function() {
|
||||
o("works as getter/setter", function() {
|
||||
var stream = Stream.stream(1)
|
||||
|
|
@ -518,10 +524,11 @@ o.spec("stream", function() {
|
|||
o(mapped()).equals(1)
|
||||
})
|
||||
o("works with errored stream", function() {
|
||||
var rejected
|
||||
var stream = Stream.stream(undefined)
|
||||
var mapped = stream.run(function(value) {return Stream.reject(new Error("error"))})
|
||||
|
||||
mapped.catch(function() {}) //silence reportUncaughtException
|
||||
var mapped = stream.run(function(value) {
|
||||
return Stream.reject(new Error("error"))
|
||||
})
|
||||
|
||||
o(mapped()).equals(undefined)
|
||||
o(mapped.error().message).equals("error")
|
||||
|
|
@ -803,14 +810,45 @@ o.spec("stream", function() {
|
|||
})
|
||||
o.spec("toJSON", function() {
|
||||
o("works", function() {
|
||||
o(Stream.stream(1).toJSON()).equals("1")
|
||||
o(Stream.stream("a").toJSON()).equals("\"a\"")
|
||||
o(Stream.stream(true).toJSON()).equals("true")
|
||||
o(Stream.stream(null).toJSON()).equals("null")
|
||||
o(Stream.stream(1).toJSON()).equals(1)
|
||||
o(Stream.stream("a").toJSON()).equals("a")
|
||||
o(Stream.stream(true).toJSON()).equals(true)
|
||||
o(Stream.stream(null).toJSON()).equals(null)
|
||||
o(Stream.stream(undefined).toJSON()).equals(undefined)
|
||||
o(Stream.stream({a: 1}).toJSON()).deepEquals("{\"a\":1}")
|
||||
o(Stream.stream([1, 2, 3]).toJSON()).deepEquals("[1,2,3]")
|
||||
o(Stream.stream({a: 1}).toJSON()).deepEquals({a: 1})
|
||||
o(Stream.stream([1, 2, 3]).toJSON()).deepEquals([1, 2, 3])
|
||||
o(Stream.stream().toJSON()).equals(undefined)
|
||||
o(Stream.stream(new Date(0)).toJSON()).equals(new Date(0).toJSON())
|
||||
})
|
||||
o("works w/ JSON.stringify", function() {
|
||||
o(JSON.stringify(Stream.stream(1))).equals(JSON.stringify(1))
|
||||
o(JSON.stringify(Stream.stream("a"))).equals(JSON.stringify("a"))
|
||||
o(JSON.stringify(Stream.stream(true))).equals(JSON.stringify(true))
|
||||
o(JSON.stringify(Stream.stream(null))).equals(JSON.stringify(null))
|
||||
o(JSON.stringify(Stream.stream(undefined))).equals(JSON.stringify(undefined))
|
||||
o(JSON.stringify(Stream.stream({a: 1}))).deepEquals(JSON.stringify({a: 1}))
|
||||
o(JSON.stringify(Stream.stream([1, 2, 3]))).deepEquals(JSON.stringify([1, 2, 3]))
|
||||
o(JSON.stringify(Stream.stream())).equals(JSON.stringify(undefined))
|
||||
o(JSON.stringify(Stream.stream(new Date(0)))).equals(JSON.stringify(new Date(0)))
|
||||
})
|
||||
})
|
||||
o.spec("uncaught exception reporting", function() {
|
||||
o("reports thrown errors", function(done) {
|
||||
Stream.stream(1).map(function() {throw new Error("error")})
|
||||
|
||||
setTimeout(function() {
|
||||
o(spy.callCount).equals(1)
|
||||
o(spy.args[0].message).equals("error")
|
||||
done()
|
||||
}, 0)
|
||||
})
|
||||
o("does not report explicit rejections", function(done) {
|
||||
Stream.reject(1)
|
||||
|
||||
setTimeout(function() {
|
||||
o(spy.callCount).equals(0)
|
||||
done()
|
||||
}, 0)
|
||||
})
|
||||
})
|
||||
o.spec("map", function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue