diff --git a/render/tests/test-onremove.js b/render/tests/test-onremove.js index f509e704..cc242a25 100644 --- a/render/tests/test-onremove.js +++ b/render/tests/test-onremove.js @@ -101,6 +101,7 @@ o.spec("onremove", function() { render(root, temp) render(root, updated) + o(vnodes[0].dom).equals(updated[0].dom) o(remove.callCount).equals(1) }) o("does not recycle when there's an onremove", function() { @@ -132,7 +133,7 @@ o.spec("onremove", function() { }) render(root, {tag: comp}) render(root, null) - + o(spy.callCount).equals(1) }) o("calls onremove on nested component child", function() { @@ -148,7 +149,7 @@ o.spec("onremove", function() { }) render(root, {tag: comp}) render(root, null) - + o(spy.callCount).equals(1) }) o("doesn't call onremove on children when the corresponding view returns null (after removing the parent)", function() { @@ -191,6 +192,28 @@ o.spec("onremove", function() { o(spy.callCount).equals(0) o(threw).equals(false) }) + o("onremove doesn't fire on nodes that go from pool to pool (#1990)", function() { + var onremove = o.spy(); + + render(root, [m("div", m("div")), m("div", m("div", {onremove: onremove}))]); + render(root, [m("div", m("div"))]); + render(root, []); + + o(onremove.callCount).equals(1) + }) + o("doesn't fire when removing the children of a node that's brought back from the pool (#1991 part 2)", function() { + var onremove = o.spy() + var vnode = {tag: "div", key: 1, children: [{tag: "div", attrs: {onremove: onremove}}]} + var temp = {tag: "div", key: 2} + var updated = {tag: "div", key: 1, children: [{tag: "p"}]} + + render(root, [vnode]) + render(root, [temp]) + render(root, [updated]) + + o(vnode.dom).equals(updated.dom) + o(onremove.callCount).equals(1) + }) }) }) }) \ No newline at end of file diff --git a/render/tests/test-updateNodes.js b/render/tests/test-updateNodes.js index 5f82281b..65d81916 100644 --- a/render/tests/test-updateNodes.js +++ b/render/tests/test-updateNodes.js @@ -870,7 +870,7 @@ o.spec("updateNodes", function() { o(onupdate.callCount).equals(0) }) - o("keyed cached elements are re-initialized when brought back from the pool", function () { + o("keyed cached elements are re-initialized when brought back from the pool (#2003)", function () { var onupdate = o.spy() var oncreate = o.spy() var cached = { @@ -886,7 +886,7 @@ o.spec("updateNodes", function() { o(onupdate.callCount).equals(0) }) - o("uneyed cached elements are re-initialized when brought back from the pool", function () { + o("unkeyed cached elements are re-initialized when brought back from the pool (#2003)", function () { var onupdate = o.spy() var oncreate = o.spy() var cached = { @@ -902,7 +902,7 @@ o.spec("updateNodes", function() { o(onupdate.callCount).equals(0) }) - o("keyed cached elements are re-initialized when brought back from nested pools", function () { + o("keyed cached elements are re-initialized when brought back from nested pools (#2003)", function () { var onupdate = o.spy() var oncreate = o.spy() var cached = { @@ -919,7 +919,7 @@ o.spec("updateNodes", function() { o(onupdate.callCount).equals(0) }) - o("unkeyed cached elements are re-initialized when brought back from nested pools", function () { + o("unkeyed cached elements are re-initialized when brought back from nested pools (#2003)", function () { var onupdate = o.spy() var oncreate = o.spy() var cached = { @@ -983,6 +983,62 @@ o.spec("updateNodes", function() { o(vnode.dom).notEquals(updated.dom) }) + o("don't add back elements from fragments that are restored from the pool #1991", function() { + render(root, [ + {tag: "[", children: []}, + {tag: "[", children: []} + ]) + render(root, [ + {tag: "[", children: []}, + {tag: "[", children: [{tag: "div"}]} + ]) + render(root, [ + {tag: "[", children: [null]} + ]) + render(root, [ + {tag: "[", children: []}, + {tag: "[", children: []} + ]) + + o(root.childNodes.length).equals(0) + }) + o("don't add back elements from fragments that are being removed #1991", function() { + render(root, [ + {tag: "[", children: []}, + {tag: "p"}, + ]) + render(root, [ + {tag: "[", children: [{tag: "div", text: 5}]} + ]) + render(root, [ + {tag: "[", children: []}, + {tag: "[", children: []} + ]) + + o(root.childNodes.length).equals(0) + }) + o("handles null values in unkeyed lists of different length (#2003)", function() { + var oncreate = o.spy(); + var onremove = o.spy(); + var onupdate = o.spy(); + function attrs() { + return {oncreate: oncreate, onremove: onremove, onupdate: onupdate} + } + + render(root, [{tag: "div", attrs: attrs()}, null]); + render(root, [null, {tag: "div", attrs: attrs()}, null]); + + o(oncreate.callCount).equals(2) + o(onremove.callCount).equals(1) + o(onupdate.callCount).equals(0) + }) + o("don't fetch the nextSibling from the pool", function() { + render(root, [{tag: "[", children: [{tag: "div", key: 1}, {tag: "div", key: 2}]}, {tag: "p"}]) + render(root, [{tag: "[", children: []}, {tag: "p"}]) + render(root, [{tag: "[", children: [{tag: "div", key: 2}, {tag: "div", key: 1}]}, {tag: "p"}]) + + o([].map.call(root.childNodes, function(el) {return el.nodeName})).deepEquals(["DIV", "DIV", "P"]) + }) components.forEach(function(cmp){ o.spec(cmp.kind, function(){ var createComponent = cmp.create