recycling => shouldRecycle, Fix #1992 (#1993)

* Fix #1992

* doc in changelog

* add test for #1992
This commit is contained in:
valtron 2017-10-16 00:38:44 -06:00 committed by Pierre-Yves Gérardy
parent 0691662fd4
commit 622e009811
3 changed files with 25 additions and 1 deletions

View file

@ -40,6 +40,7 @@
- API: Event handlers, when set to literally `undefined` (or any non-function), are now correctly removed.
- core: `xlink:href` attributes are now correctly removed
- core: render() function can no longer prevent from changing `document.activeElement` in lifecycle hooks
- render: fixed an ommission that caused `oninit` to be called unnecessarily in some cases [#1992](https://github.com/MithrilJS/mithril.js/issues/1992)
---

View file

@ -235,7 +235,7 @@ module.exports = function($window) {
if (oldIndex != null) {
var movable = old[oldIndex]
var shouldRecycle = (pool != null && oldIndex >= old.length - pool.length) || ((pool == null) && recycling)
updateNode(parent, movable, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
updateNode(parent, movable, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)
insertNode(parent, toFragment(movable), nextSibling)
old[oldIndex].skip = true
if (movable.dom != null) nextSibling = movable.dom

View file

@ -199,4 +199,27 @@ o.spec("oninit", function() {
o(vnode.dom.oninit).equals(undefined)
o(vnode.dom.attributes["oninit"]).equals(undefined)
})
o("No spurious oninit calls in mapped keyed diff when the pool is involved (#1992)", function () {
var oninit1 = o.spy()
var oninit2 = o.spy()
var oninit3 = o.spy()
render(root, [
{tag: "p", key: 1, attrs: {oninit: oninit1}},
{tag: "p", key: 2, attrs: {oninit: oninit2}},
{tag: "p", key: 3, attrs: {oninit: oninit3}},
])
render(root, [
{tag: "p", key: 1, attrs: {oninit: oninit1}},
{tag: "p", key: 3, attrs: {oninit: oninit3}},
])
render(root, [
{tag: "p", key: 3, attrs: {oninit: oninit3}},
])
o(oninit1.callCount).equals(1)
o(oninit2.callCount).equals(1)
o(oninit3.callCount).equals(1)
})
})