more tests

This commit is contained in:
Leo Horie 2016-05-24 23:16:43 -04:00
parent a2c01d1d96
commit e7420e72e1
14 changed files with 596 additions and 215 deletions

View file

@ -4,6 +4,7 @@ var Node = require("../render/node")
module.exports = function($window) {
var $doc = $window.document
var $emptyFragment = $doc.createDocumentFragment()
var onevent
function setEventCallback(callback) {return onevent = callback}
@ -91,10 +92,13 @@ module.exports = function($window) {
initLifecycle(vnode.tag, vnode, hooks)
vnode.instance = Node.normalize(vnode.tag.view.call(vnode.state, vnode))
var element = createNode(vnode.instance, hooks)
vnode.dom = vnode.instance.dom
vnode.domSize = vnode.instance.domSize
return element
if (vnode.instance != null) {
var element = createNode(vnode.instance, hooks)
vnode.dom = vnode.instance.dom
vnode.domSize = vnode.instance.domSize
return element
}
else return $emptyFragment
}
//update
@ -231,9 +235,11 @@ module.exports = function($window) {
function updateComponent(parent, old, vnode, hooks, nextSibling, recycling) {
vnode.instance = Node.normalize(vnode.tag.view.call(vnode.state, vnode))
updateLifecycle(vnode.tag, vnode, hooks, recycling)
updateNode(parent, old.instance, vnode.instance, hooks, nextSibling, recycling)
vnode.dom = vnode.instance.dom
vnode.domSize = vnode.instance.domSize
if (vnode.instance != null) {
updateNode(parent, old.instance, vnode.instance, hooks, nextSibling, recycling)
vnode.dom = vnode.instance.dom
vnode.domSize = vnode.instance.domSize
}
}
function isRecyclable(old, vnodes) {
if (old.pool != null && Math.abs(old.pool.length - vnodes.length) <= Math.abs(old.length - vnodes.length)) {

View file

@ -150,6 +150,26 @@ o.spec("component", function() {
o(root.firstChild.nodeType).equals(3)
o(root.firstChild.nodeValue).equals("false")
})
o("can return null", function() {
var component = {
view: function(vnode) {
return null
}
}
render(root, [{tag: component}])
o(root.childNodes.length).equals(0)
})
o("can return undefined", function() {
var component = {
view: function(vnode) {
return undefined
}
}
render(root, [{tag: component}])
o(root.childNodes.length).equals(0)
})
o("can update when returning fragments", function() {
var component = {
view: function(vnode) {
@ -178,6 +198,17 @@ o.spec("component", function() {
o(root.firstChild.nodeType).equals(3)
o(root.firstChild.nodeValue).equals("a")
})
o("can update when returning null", function() {
var component = {
view: function(vnode) {
return null
}
}
render(root, [{tag: component}])
render(root, [{tag: component}])
o(root.childNodes.length).equals(0)
})
o("can remove when returning fragments", function() {
var component = {
view: function(vnode) {
@ -507,4 +538,22 @@ o.spec("component", function() {
o(root.childNodes.length).equals(0)
})
})
o.spec("state", function() {
o("deep copies state", function() {
var called = 0
var component = {
data: [{a: 1}],
oninit: init,
view: function() {
return ""
}
}
render(root, [{tag: component}])
function init(vnode) {
o(vnode.state.data).deepEquals([{a: 1}])
}
})
})
})