* De-servicify router (mostly) Still uses the redraw service, but it no longer has an intermediate service of its own. Also, did a *lot* of test deduplication in this. About 30-40% of the router service tests were already tested on the main router API instance itself. Bundle size decreased from 9560 to 9548 bytes min+gzip. * Merge `m.mount` + `m.redraw`, update router Simplifies the router and redraw mechanism, and makes it much easier to keep predictable. Bundle size down to 9433 bytes min+gzip, docs updated accordingly. * Make `mithril/render` just return the `m.render` function directly. * Deservicify `m.render`, revise `m.route` - You now have to use `mithril/render/render` directly if you want an implicit redraw function. (This will likely be going away in v3.) - Revise `m.route` to only `key` components * Add `redraw` to `m.render`, deservicify requests * Test error logging * Update docs + changelog [skip ci]
114 lines
2.9 KiB
JavaScript
114 lines
2.9 KiB
JavaScript
"use strict"
|
|
|
|
var o = require("../../ospec/ospec")
|
|
var domMock = require("../../test-utils/domMock")
|
|
var vdom = require("../../render/render")
|
|
|
|
o.spec("updateText", function() {
|
|
var $window, root, render
|
|
o.beforeEach(function() {
|
|
$window = domMock()
|
|
root = $window.document.createElement("div")
|
|
render = vdom($window)
|
|
})
|
|
|
|
o("updates to string", function() {
|
|
var vnode = {tag: "#", children: "a"}
|
|
var updated = {tag: "#", children: "b"}
|
|
|
|
render(root, [vnode])
|
|
render(root, [updated])
|
|
|
|
o(updated.dom).equals(vnode.dom)
|
|
o(updated.dom).equals(root.firstChild)
|
|
o(updated.dom.nodeValue).equals("b")
|
|
})
|
|
o("updates to falsy string", function() {
|
|
var vnode = {tag: "#", children: "a"}
|
|
var updated = {tag: "#", children: ""}
|
|
|
|
render(root, [vnode])
|
|
render(root, [updated])
|
|
|
|
o(updated.dom).equals(vnode.dom)
|
|
o(updated.dom).equals(root.firstChild)
|
|
o(updated.dom.nodeValue).equals("")
|
|
})
|
|
o("updates from falsy string", function() {
|
|
var vnode = {tag: "#", children: ""}
|
|
var updated = {tag: "#", children: "b"}
|
|
|
|
render(root, [vnode])
|
|
render(root, [updated])
|
|
|
|
o(updated.dom).equals(vnode.dom)
|
|
o(updated.dom).equals(root.firstChild)
|
|
o(updated.dom.nodeValue).equals("b")
|
|
})
|
|
o("updates to number", function() {
|
|
var vnode = {tag: "#", children: "a"}
|
|
var updated = {tag: "#", children: 1}
|
|
|
|
render(root, [vnode])
|
|
render(root, [updated])
|
|
|
|
o(updated.dom).equals(vnode.dom)
|
|
o(updated.dom).equals(root.firstChild)
|
|
o(updated.dom.nodeValue).equals("1")
|
|
})
|
|
o("updates to falsy number", function() {
|
|
var vnode = {tag: "#", children: "a"}
|
|
var updated = {tag: "#", children: 0}
|
|
|
|
render(root, [vnode])
|
|
render(root, [updated])
|
|
|
|
o(updated.dom).equals(vnode.dom)
|
|
o(updated.dom).equals(root.firstChild)
|
|
o(updated.dom.nodeValue).equals("0")
|
|
})
|
|
o("updates from falsy number", function() {
|
|
var vnode = {tag: "#", children: 0}
|
|
var updated = {tag: "#", children: "b"}
|
|
|
|
render(root, [vnode])
|
|
render(root, [updated])
|
|
|
|
o(updated.dom).equals(vnode.dom)
|
|
o(updated.dom).equals(root.firstChild)
|
|
o(updated.dom.nodeValue).equals("b")
|
|
})
|
|
o("updates to boolean", function() {
|
|
var vnode = {tag: "#", children: "a"}
|
|
var updated = {tag: "#", children: true}
|
|
|
|
render(root, [vnode])
|
|
render(root, [updated])
|
|
|
|
o(updated.dom).equals(vnode.dom)
|
|
o(updated.dom).equals(root.firstChild)
|
|
o(updated.dom.nodeValue).equals("true")
|
|
})
|
|
o("updates to falsy boolean", function() {
|
|
var vnode = {tag: "#", children: "a"}
|
|
var updated = {tag: "#", children: false}
|
|
|
|
render(root, [vnode])
|
|
render(root, [updated])
|
|
|
|
o(updated.dom).equals(vnode.dom)
|
|
o(updated.dom).equals(root.firstChild)
|
|
o(updated.dom.nodeValue).equals("false")
|
|
})
|
|
o("updates from falsy boolean", function() {
|
|
var vnode = {tag: "#", children: false}
|
|
var updated = {tag: "#", children: "b"}
|
|
|
|
render(root, [vnode])
|
|
render(root, [updated])
|
|
|
|
o(updated.dom).equals(vnode.dom)
|
|
o(updated.dom).equals(root.firstChild)
|
|
o(updated.dom.nodeValue).equals("b")
|
|
})
|
|
})
|