Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store normalized vnodes in the dom element. Add render tests. #2266

Merged
merged 2 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions render/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,8 @@ module.exports = function($window) {
// First time rendering into a node clears it out
if (dom.vnodes == null) dom.textContent = ""

if (!Array.isArray(vnodes)) vnodes = [vnodes]
updateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), hooks, null, namespace === "http://www.w3.org/1999/xhtml" ? undefined : namespace)
vnodes = Vnode.normalizeChildren(Array.isArray(vnodes) ? vnodes : [vnodes])
updateNodes(dom, dom.vnodes, vnodes, hooks, null, namespace === "http://www.w3.org/1999/xhtml" ? undefined : namespace)
dom.vnodes = vnodes
// document.activeElement can return null in IE https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
if (active != null && $doc.activeElement !== active && typeof active.focus === "function") active.focus()
Expand Down
26 changes: 26 additions & 0 deletions render/tests/test-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ o.spec("render", function() {
render = vdom($window).render
})

o("renders plain text", function() {
render(root, "a")
o(root.childNodes.length).equals(1)
o(root.childNodes[0].nodeValue).equals("a")
})

o("updates plain text", function() {
render(root, "a")
render(root, "b")
o(root.childNodes.length).equals(1)
o(root.childNodes[0].nodeValue).equals("b")
})

o("renders a number", function() {
render(root, 1)
o(root.childNodes.length).equals(1)
o(root.childNodes[0].nodeValue).equals("1")
})

o("updates a number", function() {
render(root, 1)
render(root, 2)
o(root.childNodes.length).equals(1)
o(root.childNodes[0].nodeValue).equals("2")
})

o("overwrites existing content", function() {
var vnodes = []

Expand Down