semi-working bundle
This commit is contained in:
parent
41cfda2719
commit
5265697cb2
20 changed files with 1391 additions and 123 deletions
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
var Node = require("../render/node")
|
||||
|
||||
module.exports = function($window, onevent) {
|
||||
module.exports = function($window) {
|
||||
var $doc = $window.document
|
||||
|
||||
var onevent
|
||||
function setEventCallback(callback) {return onevent = callback}
|
||||
|
||||
//create
|
||||
function createNodes(parent, vnodes, start, end, hooks, nextSibling) {
|
||||
for (var i = start; i < end; i++) {
|
||||
|
|
@ -16,10 +19,7 @@ module.exports = function($window, onevent) {
|
|||
}
|
||||
function createNode(vnode, hooks) {
|
||||
var tag = vnode.tag
|
||||
if (vnode.attrs) {
|
||||
if (vnode.attrs.oninit) vnode.attrs.oninit.call(vnode, vnode)
|
||||
if (vnode.attrs.oncreate) hooks.push(vnode.attrs.oncreate.bind(vnode, vnode))
|
||||
}
|
||||
if (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks)
|
||||
if (typeof tag === "string") {
|
||||
switch (tag) {
|
||||
case "#": return createText(vnode)
|
||||
|
|
@ -324,8 +324,8 @@ module.exports = function($window, onevent) {
|
|||
}
|
||||
}
|
||||
function onremove(vnode) {
|
||||
if (vnode.attrs && vnode.attrs.onremove) vnode.attrs.onremove.call(vnode, vnode)
|
||||
if (typeof vnode.tag !== "string" && vnode.tag.onremove) vnode.tag.onremove.call(vnode, vnode)
|
||||
if (vnode.attrs && vnode.attrs.onremove) vnode.attrs.onremove.call(vnode.state, vnode)
|
||||
if (typeof vnode.tag !== "string" && vnode.tag.onremove) vnode.tag.onremove.call(vnode.state, vnode)
|
||||
|
||||
var children = vnode.children
|
||||
if (children instanceof Array) {
|
||||
|
|
@ -429,17 +429,17 @@ module.exports = function($window, onevent) {
|
|||
|
||||
//lifecycle
|
||||
function initLifecycle(source, vnode, hooks) {
|
||||
if (source.oninit != null) source.oninit.call(vnode, vnode)
|
||||
if (source.oncreate != null) hooks.push(source.oncreate.bind(vnode, vnode))
|
||||
if (source.oninit != null) source.oninit.call(vnode.state, vnode)
|
||||
if (source.oncreate != null) hooks.push(source.oncreate.bind(vnode.state, vnode))
|
||||
}
|
||||
function updateLifecycle(source, vnode, hooks, recycling) {
|
||||
if (recycling) initLifecycle(source, vnode, hooks)
|
||||
else if (source.onupdate != null) hooks.push(source.onupdate.bind(vnode, vnode))
|
||||
else if (source.onupdate != null) hooks.push(source.onupdate.bind(vnode.state, vnode))
|
||||
}
|
||||
function shouldUpdate(vnode, old) {
|
||||
var forceVnodeUpdate, forceComponentUpdate
|
||||
if (vnode.attrs != null && typeof vnode.attrs.shouldUpdate === "function") forceVnodeUpdate = vnode.attrs.shouldUpdate(vnode, old)
|
||||
if (typeof vnode.tag !== "string" && typeof vnode.tag.shouldUpdate === "function") forceComponentUpdate = vnode.tag.shouldUpdate(vnode, old)
|
||||
if (vnode.attrs != null && typeof vnode.attrs.shouldUpdate === "function") forceVnodeUpdate = vnode.attrs.shouldUpdate.call(vnode.state, vnode, old)
|
||||
if (typeof vnode.tag !== "string" && typeof vnode.tag.shouldUpdate === "function") forceComponentUpdate = vnode.tag.shouldUpdate.call(vnode.state, vnode, old)
|
||||
if (!(forceVnodeUpdate === undefined && forceComponentUpdate === undefined) && !forceVnodeUpdate && !forceComponentUpdate) {
|
||||
vnode.dom = old.dom
|
||||
vnode.domSize = old.domSize
|
||||
|
|
@ -460,6 +460,6 @@ module.exports = function($window, onevent) {
|
|||
dom.vnodes = vnodes
|
||||
if ($doc.activeElement !== active) active.focus()
|
||||
}
|
||||
|
||||
return {render: render}
|
||||
|
||||
return {render: render, setEventCallback: setEventCallback}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ o.spec("event", function() {
|
|||
$window = domMock()
|
||||
root = $window.document.body
|
||||
onevent = o.spy()
|
||||
render = vdom($window, onevent).render
|
||||
var renderer = vdom($window)
|
||||
renderer.setEventCallback(onevent)
|
||||
render = renderer.render
|
||||
})
|
||||
|
||||
o("handles onclick", function() {
|
||||
|
|
|
|||
|
|
@ -14,135 +14,135 @@ o.spec("oncreate", function() {
|
|||
|
||||
o("calls oncreate when creating element", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oncreate: callback}}
|
||||
var vnode = {tag: "div", attrs: {oncreate: callback}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls oncreate when creating text", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "#", attrs: {oncreate: callback}, children: "a"}
|
||||
var vnode = {tag: "#", attrs: {oncreate: callback}, children: "a", state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls oncreate when creating fragment", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "[", attrs: {oncreate: callback}, children: []}
|
||||
var vnode = {tag: "[", attrs: {oncreate: callback}, children: [], state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls oncreate when creating html", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "<", attrs: {oncreate: callback}, children: "a"}
|
||||
var vnode = {tag: "<", attrs: {oncreate: callback}, children: "a", state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls oncreate when replacing keyed", function() {
|
||||
var createDiv = o.spy()
|
||||
var createA = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {oncreate: createDiv}}
|
||||
var updated = {tag: "a", key: 1, attrs: {oncreate: createA}}
|
||||
var vnode = {tag: "div", key: 1, attrs: {oncreate: createDiv}, state: {}}
|
||||
var updated = {tag: "a", key: 1, attrs: {oncreate: createA}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(createDiv.callCount).equals(1)
|
||||
o(createDiv.this).equals(vnode)
|
||||
o(createDiv.this).equals(vnode.state)
|
||||
o(createDiv.args[0]).equals(vnode)
|
||||
o(createA.callCount).equals(1)
|
||||
o(createA.this).equals(updated)
|
||||
o(createA.this).equals(updated.state)
|
||||
o(createA.args[0]).equals(updated)
|
||||
})
|
||||
o("does not call oncreate when noop", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}}
|
||||
var updated = {tag: "div", attrs: {oncreate: update}}
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {oncreate: update}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("does not call oncreate when updating attr", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}}
|
||||
var updated = {tag: "div", attrs: {oncreate: update, id: "a"}}
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {oncreate: update, id: "a"}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("does not call oncreate when updating children", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}, children: [{tag: "a"}]}
|
||||
var updated = {tag: "div", attrs: {oncreate: update}, children: [{tag: "b"}]}
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}, children: [{tag: "a"}], state: {}}
|
||||
var updated = {tag: "div", attrs: {oncreate: update}, children: [{tag: "b"}], state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("does not call oncreate when updating keyed", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {oncreate: create}}
|
||||
var vnode = {tag: "div", key: 1, attrs: {oncreate: create}, state: {}}
|
||||
var otherVnode = {tag: "a", key: 2}
|
||||
var updated = {tag: "div", key: 1, attrs: {oncreate: update}}
|
||||
var updated = {tag: "div", key: 1, attrs: {oncreate: update}, state: {}}
|
||||
var otherUpdated = {tag: "a", key: 2}
|
||||
|
||||
render(root, [vnode, otherVnode])
|
||||
render(root, [otherUpdated, updated])
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("does not call oncreate when removing", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}}
|
||||
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls oncreate when recycling", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {oncreate: create}}
|
||||
var updated = {tag: "div", key: 1, attrs: {oncreate: update}}
|
||||
var vnode = {tag: "div", key: 1, attrs: {oncreate: create}, state: {}}
|
||||
var updated = {tag: "div", key: 1, attrs: {oncreate: update}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
|
@ -150,28 +150,28 @@ o.spec("oncreate", function() {
|
|||
|
||||
o(vnode.dom).equals(updated.dom)
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(updated)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("calls oncreate at the same step as onupdate", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: []}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "a", attrs: {oncreate: callback}}]}
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: [], state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "a", attrs: {oncreate: callback}, state: {}}], state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(updated)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(updated.children[0])
|
||||
o(callback.this).equals(updated.children[0].state)
|
||||
o(callback.args[0]).equals(updated.children[0])
|
||||
})
|
||||
o("calls oncreate after full DOM creation", function() {
|
||||
|
|
|
|||
|
|
@ -14,135 +14,135 @@ o.spec("oninit", function() {
|
|||
|
||||
o("calls oninit when creating element", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oninit: callback}}
|
||||
var vnode = {tag: "div", attrs: {oninit: callback}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls oninit when creating text", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "#", attrs: {oninit: callback}, children: "a"}
|
||||
var vnode = {tag: "#", attrs: {oninit: callback}, children: "a", state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls oninit when creating fragment", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "[", attrs: {oninit: callback}, children: []}
|
||||
var vnode = {tag: "[", attrs: {oninit: callback}, children: [], state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls oninit when creating html", function() {
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "<", attrs: {oninit: callback}, children: "a"}
|
||||
var vnode = {tag: "<", attrs: {oninit: callback}, children: "a", state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(vnode)
|
||||
o(callback.this).equals(vnode.state)
|
||||
o(callback.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls oninit when replacing keyed", function() {
|
||||
var createDiv = o.spy()
|
||||
var createA = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {oninit: createDiv}}
|
||||
var updated = {tag: "a", key: 1, attrs: {oninit: createA}}
|
||||
var vnode = {tag: "div", key: 1, attrs: {oninit: createDiv}, state: {}}
|
||||
var updated = {tag: "a", key: 1, attrs: {oninit: createA}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(createDiv.callCount).equals(1)
|
||||
o(createDiv.this).equals(vnode)
|
||||
o(createDiv.this).equals(vnode.state)
|
||||
o(createDiv.args[0]).equals(vnode)
|
||||
o(createA.callCount).equals(1)
|
||||
o(createA.this).equals(updated)
|
||||
o(createA.this).equals(updated.state)
|
||||
o(createA.args[0]).equals(updated)
|
||||
})
|
||||
o("does not call oninit when noop", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oninit: create}}
|
||||
var updated = {tag: "div", attrs: {oninit: update}}
|
||||
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {oninit: update}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("does not call oninit when updating attr", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oninit: create}}
|
||||
var updated = {tag: "div", attrs: {oninit: update, id: "a"}}
|
||||
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {oninit: update, id: "a"}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("does not call oninit when updating children", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oninit: create}, children: [{tag: "a"}]}
|
||||
var updated = {tag: "div", attrs: {oninit: update}, children: [{tag: "b"}]}
|
||||
var vnode = {tag: "div", attrs: {oninit: create}, children: [{tag: "a"}], state: {}}
|
||||
var updated = {tag: "div", attrs: {oninit: update}, children: [{tag: "b"}], state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("does not call oninit when updating keyed", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {oninit: create}}
|
||||
var vnode = {tag: "div", key: 1, attrs: {oninit: create}, state: {}}
|
||||
var otherVnode = {tag: "a", key: 2}
|
||||
var updated = {tag: "div", key: 1, attrs: {oninit: update}}
|
||||
var updated = {tag: "div", key: 1, attrs: {oninit: update}, state: {}}
|
||||
var otherUpdated = {tag: "a", key: 2}
|
||||
|
||||
render(root, [vnode, otherVnode])
|
||||
render(root, [otherUpdated, updated])
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("does not call oninit when removing", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {oninit: create}}
|
||||
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls oninit when recycling", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {oninit: create}}
|
||||
var updated = {tag: "div", key: 1, attrs: {oninit: update}}
|
||||
var vnode = {tag: "div", key: 1, attrs: {oninit: create}, state: {}}
|
||||
var updated = {tag: "div", key: 1, attrs: {oninit: update}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
|
@ -150,28 +150,28 @@ o.spec("oninit", function() {
|
|||
|
||||
o(vnode.dom).equals(updated.dom)
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(updated)
|
||||
o(update.this).equals(updated.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("calls oninit at the same step as onupdate", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var callback = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: []}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "a", attrs: {oninit: callback}}]}
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: [], state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "a", attrs: {oninit: callback}, state: {}}], state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(updated)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
o(callback.callCount).equals(1)
|
||||
o(callback.this).equals(updated.children[0])
|
||||
o(callback.this).equals(updated.children[0].state)
|
||||
o(callback.args[0]).equals(updated.children[0])
|
||||
})
|
||||
o("calls oninit before full DOM creation", function() {
|
||||
|
|
|
|||
|
|
@ -37,46 +37,46 @@ o.spec("onremove", function() {
|
|||
})
|
||||
o("calls onremove when removing element", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onremove: remove}}
|
||||
var vnode = {tag: "div", attrs: {onremove: remove}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
o(remove.callCount).equals(1)
|
||||
o(remove.this).equals(vnode)
|
||||
o(remove.this).equals(vnode.state)
|
||||
o(remove.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls onremove when removing text", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "#", attrs: {onremove: remove}, children: "a"}
|
||||
var vnode = {tag: "#", attrs: {onremove: remove}, children: "a", state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
o(remove.callCount).equals(1)
|
||||
o(remove.this).equals(vnode)
|
||||
o(remove.this).equals(vnode.state)
|
||||
o(remove.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls onremove when removing fragment", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "[", attrs: {onremove: remove}, children: []}
|
||||
var vnode = {tag: "[", attrs: {onremove: remove}, children: [], state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
o(remove.callCount).equals(1)
|
||||
o(remove.this).equals(vnode)
|
||||
o(remove.this).equals(vnode.state)
|
||||
o(remove.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls onremove when removing html", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "<", attrs: {onremove: remove}, children: "a"}
|
||||
var vnode = {tag: "<", attrs: {onremove: remove}, children: "a", state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
|
||||
o(remove.callCount).equals(1)
|
||||
o(remove.this).equals(vnode)
|
||||
o(remove.this).equals(vnode.state)
|
||||
o(remove.args[0]).equals(vnode)
|
||||
})
|
||||
o("does not set onremove as an event handler", function() {
|
||||
|
|
|
|||
|
|
@ -15,15 +15,15 @@ o.spec("onupdate", function() {
|
|||
o("does not call onupdate when creating element", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}}
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(updated)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("does not call onupdate when removing element", function() {
|
||||
|
|
@ -74,85 +74,85 @@ o.spec("onupdate", function() {
|
|||
o("calls onupdate when noop", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}}
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(updated)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("calls onupdate when updating attr", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update, id: "a"}}
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update, id: "a"}, state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(updated)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("calls onupdate when updating children", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: [{tag: "a"}]}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "b"}]}
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: [{tag: "a"}], state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "b"}], state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(updated)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("calls onupdate when updating text", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "#", attrs: {onupdate: create}, children: "a"}
|
||||
var updated = {tag: "#", attrs: {onupdate: update}, children: "a"}
|
||||
var vnode = {tag: "#", attrs: {onupdate: create}, children: "a", state: {}}
|
||||
var updated = {tag: "#", attrs: {onupdate: update}, children: "a", state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(updated)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("calls onupdate when updating fragment", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "[", attrs: {onupdate: create}, children: []}
|
||||
var updated = {tag: "[", attrs: {onupdate: update}, children: []}
|
||||
var vnode = {tag: "[", attrs: {onupdate: create}, children: [], state: {}}
|
||||
var updated = {tag: "[", attrs: {onupdate: update}, children: [], state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(updated)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("calls onupdate when updating html", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "<", attrs: {onupdate: create}, children: "a"}
|
||||
var updated = {tag: "<", attrs: {onupdate: update}, children: "a"}
|
||||
var vnode = {tag: "<", attrs: {onupdate: create}, children: "a", state: {}}
|
||||
var updated = {tag: "<", attrs: {onupdate: update}, children: "a", state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(updated)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("calls onupdate after full DOM update", function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue