* 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]
200 lines
5.6 KiB
JavaScript
200 lines
5.6 KiB
JavaScript
"use strict"
|
|
|
|
var o = require("../../ospec/ospec")
|
|
var domMock = require("../../test-utils/domMock")
|
|
var vdom = require("../../render/render")
|
|
|
|
o.spec("textContent", function() {
|
|
var $window, root, render
|
|
o.beforeEach(function() {
|
|
$window = domMock()
|
|
root = $window.document.createElement("div")
|
|
render = vdom($window)
|
|
})
|
|
|
|
o("ignores null", function() {
|
|
var vnodes = [{tag: "a", text: null}]
|
|
|
|
render(root, vnodes)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(0)
|
|
o(vnodes[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("ignores undefined", function() {
|
|
var vnodes = [{tag: "a", text: undefined}]
|
|
|
|
render(root, vnodes)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(0)
|
|
o(vnodes[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("creates string", function() {
|
|
var vnodes = [{tag: "a", text: "a"}]
|
|
|
|
render(root, vnodes)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("a")
|
|
o(vnodes[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("creates falsy string", function() {
|
|
var vnodes = [{tag: "a", text: ""}]
|
|
|
|
render(root, vnodes)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("")
|
|
o(vnodes[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("creates number", function() {
|
|
var vnodes = [{tag: "a", text: 1}]
|
|
|
|
render(root, vnodes)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
|
o(vnodes[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("creates falsy number", function() {
|
|
var vnodes = [{tag: "a", text: 0}]
|
|
|
|
render(root, vnodes)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("0")
|
|
o(vnodes[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("creates boolean", function() {
|
|
var vnodes = [{tag: "a", text: true}]
|
|
|
|
render(root, vnodes)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("true")
|
|
o(vnodes[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("creates falsy boolean", function() {
|
|
var vnodes = [{tag: "a", text: false}]
|
|
|
|
render(root, vnodes)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("false")
|
|
o(vnodes[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("updates to string", function() {
|
|
var vnodes = [{tag: "a", text: "a"}]
|
|
var updated = [{tag: "a", text: "b"}]
|
|
|
|
render(root, vnodes)
|
|
render(root, updated)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("b")
|
|
o(updated[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("updates to falsy string", function() {
|
|
var vnodes = [{tag: "a", text: "a"}]
|
|
var updated = [{tag: "a", text: ""}]
|
|
|
|
render(root, vnodes)
|
|
render(root, updated)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("")
|
|
o(updated[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("updates to number", function() {
|
|
var vnodes = [{tag: "a", text: "a"}]
|
|
var updated = [{tag: "a", text: 1}]
|
|
|
|
render(root, vnodes)
|
|
render(root, updated)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
|
o(updated[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("updates to falsy number", function() {
|
|
var vnodes = [{tag: "a", text: "a"}]
|
|
var updated = [{tag: "a", text: 0}]
|
|
|
|
render(root, vnodes)
|
|
render(root, updated)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("0")
|
|
o(updated[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("updates to boolean", function() {
|
|
var vnodes = [{tag: "a", text: "a"}]
|
|
var updated = [{tag: "a", text: true}]
|
|
|
|
render(root, vnodes)
|
|
render(root, updated)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("true")
|
|
o(updated[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("updates to falsy boolean", function() {
|
|
var vnodes = [{tag: "a", text: "a"}]
|
|
var updated = [{tag: "a", text: false}]
|
|
|
|
render(root, vnodes)
|
|
render(root, updated)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("false")
|
|
o(updated[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("updates with typecasting", function() {
|
|
var vnodes = [{tag: "a", text: "1"}]
|
|
var updated = [{tag: "a", text: 1}]
|
|
|
|
render(root, vnodes)
|
|
render(root, updated)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
|
o(updated[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("updates from without text to with text", function() {
|
|
var vnodes = [{tag: "a"}]
|
|
var updated = [{tag: "a", text: "b"}]
|
|
|
|
render(root, vnodes)
|
|
render(root, updated)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("b")
|
|
o(updated[0].dom).equals(root.childNodes[0])
|
|
})
|
|
o("updates from with text to without text", function() {
|
|
var vnodes = [{tag: "a", text: "a"}]
|
|
var updated = [{tag: "a"}]
|
|
|
|
render(root, vnodes)
|
|
render(root, updated)
|
|
|
|
o(root.childNodes.length).equals(1)
|
|
o(vnodes[0].dom.childNodes.length).equals(0)
|
|
o(updated[0].dom).equals(root.childNodes[0])
|
|
})
|
|
})
|