prevent recycling for vnodes w/ integration methods
This commit is contained in:
parent
73cfe3dd7a
commit
b4903538f3
6 changed files with 35 additions and 16 deletions
|
|
@ -27,7 +27,7 @@
|
|||
<script src="../../render/render.js"></script>
|
||||
<script>
|
||||
var m = require("../../render/hyperscript")
|
||||
var render = require("../../render/render")(window, run).render
|
||||
var renderer = require("../../render/render")(window)
|
||||
var root = document.getElementById("root")
|
||||
|
||||
var empty = []
|
||||
|
|
@ -47,16 +47,13 @@ function view() {
|
|||
|
||||
function exit(vnode, done) {
|
||||
vnode.dom.classList.add("exit")
|
||||
setTimeout(function() {
|
||||
vnode.dom.classList.remove("exit")
|
||||
done()
|
||||
}, 1000)
|
||||
setTimeout(done, 1000)
|
||||
}
|
||||
|
||||
function run() {
|
||||
cells = cells === full ? empty : full
|
||||
|
||||
render(root, [view()])
|
||||
renderer.render(root, [view()])
|
||||
|
||||
setTimeout(run, 2000)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -319,7 +319,7 @@ module.exports = function($window) {
|
|||
}
|
||||
}
|
||||
if (vnode.dom.parentNode != null) parent.removeChild(vnode.dom)
|
||||
if (context != null && vnode.domSize == null) { //TODO test custom elements
|
||||
if (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode)) { //TODO test custom elements
|
||||
if (!context.pool) context.pool = [vnode]
|
||||
else context.pool.push(vnode)
|
||||
}
|
||||
|
|
@ -393,6 +393,9 @@ module.exports = function($window) {
|
|||
function isAttribute(attr) {
|
||||
return attr === "href" || attr === "list" || attr === "form"// || attr === "type" || attr === "width" || attr === "height"
|
||||
}
|
||||
function hasIntegrationMethods(vnode) {
|
||||
return vnode.attrs != null && (vnode.attrs.oncreate || vnode.attrs.onupdate || vnode.attrs.onbeforeremove || vnode.attrs.onremove)
|
||||
}
|
||||
|
||||
//style
|
||||
function updateStyle(element, old, style) {
|
||||
|
|
|
|||
|
|
@ -156,4 +156,15 @@ o.spec("onbeforeremove", function() {
|
|||
o(vnode.dom.onbeforeremove).equals(undefined)
|
||||
o(vnode.dom.attributes["onbeforeremove"]).equals(undefined)
|
||||
})
|
||||
o("does not recycle when there's an onbeforeremove", function() {
|
||||
var remove = function(vnode, done) {done()}
|
||||
var vnode = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
||||
var updated = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
render(root, [updated])
|
||||
|
||||
o(vnode.dom).notEquals(updated.dom)
|
||||
})
|
||||
})
|
||||
|
|
@ -138,7 +138,7 @@ o.spec("oncreate", function() {
|
|||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
})
|
||||
o("calls oncreate when recycling", function() {
|
||||
o("does not recycle when there's an oncreate", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {oncreate: create}, state: {}}
|
||||
|
|
@ -148,12 +148,12 @@ o.spec("oncreate", function() {
|
|||
render(root, [])
|
||||
render(root, [updated])
|
||||
|
||||
o(vnode.dom).equals(updated.dom)
|
||||
o(vnode.dom).notEquals(updated.dom)
|
||||
o(create.callCount).equals(1)
|
||||
o(create.this).equals(vnode.state)
|
||||
o(create.args[0]).equals(vnode)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.this).equals(updated.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("calls oncreate at the same step as onupdate", function() {
|
||||
|
|
|
|||
|
|
@ -100,4 +100,15 @@ o.spec("onremove", function() {
|
|||
|
||||
o(remove.callCount).equals(1)
|
||||
})
|
||||
o("does not recycle when there's an onremove", function() {
|
||||
var remove = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {onremove: remove}}
|
||||
var updated = {tag: "div", key: 1, attrs: {onremove: remove}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
render(root, [updated])
|
||||
|
||||
o(vnode.dom).notEquals(updated.dom)
|
||||
})
|
||||
})
|
||||
|
|
@ -46,19 +46,16 @@ o.spec("onupdate", function() {
|
|||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("does not call onupdate when recycling", function() {
|
||||
var create = o.spy()
|
||||
o("does not recycle when there's an onupdate", function() {
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {onupdate: create}}
|
||||
var vnode = {tag: "div", key: 1, attrs: {onupdate: update}}
|
||||
var updated = {tag: "div", key: 1, attrs: {onupdate: update}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [])
|
||||
render(root, [updated])
|
||||
|
||||
o(vnode.dom).equals(updated.dom)
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(0)
|
||||
o(vnode.dom).notEquals(updated.dom)
|
||||
})
|
||||
o("does not call old onupdate when removing the onupdate property in new vnode", function() {
|
||||
var create = o.spy()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue