From 144fe7e59ac3adaa547218d55d44a0d9496bba6d Mon Sep 17 00:00:00 2001 From: Philip Kamenarsky Date: Thu, 26 Nov 2015 14:44:14 +0100 Subject: [PATCH] Let property patches be applied last (fixes #338) --- test/non-string.js | 2 +- vdom/patch.js | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/test/non-string.js b/test/non-string.js index 0f81accb..0fa263ed 100644 --- a/test/non-string.js +++ b/test/non-string.js @@ -9,6 +9,6 @@ test("coerce numbers to strings in children array", function (assert) { var rightNode = h("div", [ "clicked ", 1337, " times" ]) var rootNode = createElement(leftNode) var newRoot = patch(rootNode, diff(leftNode, rightNode)) - assert.equal(newRoot.toString(), '
clicked 1337 times
') + assert.equal(newRoot.outerHTML || newRoot.toString(), '
clicked 1337 times
') assert.end() }) diff --git a/vdom/patch.js b/vdom/patch.js index 6e552102..851d18ce 100644 --- a/vdom/patch.js +++ b/vdom/patch.js @@ -4,6 +4,7 @@ var isArray = require("x-is-array") var render = require("./create-element") var domIndex = require("./dom-index") var patchOp = require("./patch-op") +var VPatch = require("../vnode/vpatch.js") module.exports = patch function patch(rootNode, patches, renderOptions) { @@ -49,8 +50,25 @@ function applyPatch(rootNode, domNode, patchList, renderOptions) { var newNode if (isArray(patchList)) { + var propsPatchList = []; + for (var i = 0; i < patchList.length; i++) { - newNode = patchOp(patchList[i], domNode, renderOptions) + if (patchList[i].type != VPatch.PROPS) { + newNode = patchOp(patchList[i], domNode, renderOptions) + + if (domNode === rootNode) { + rootNode = newNode + } + } + else { + propsPatchList.push(patchList[i]); + } + } + + // Properties like scrollTop should be set after all children have been + // patched, otherwise they wouldn't take effect. + for (var i = 0; i < propsPatchList.length; i++) { + newNode = patchOp(propsPatchList[i], domNode, renderOptions) if (domNode === rootNode) { rootNode = newNode