From fe62be3c86cf7f1cb208dff606d1e41eb6b4d655 Mon Sep 17 00:00:00 2001 From: 0x8890 <0x8890@airmail.cc> Date: Mon, 23 Nov 2015 14:59:45 +0100 Subject: [PATCH] fix ordering of array not being preserved --- README.md | 2 +- lib/define_properties.js | 9 ++++----- package.json | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 405959d..e8fb6b7 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ On initialization, Simulacra.js removes bound elements from the document and rep ## Caveats -The DOM will update if there is an assignment on the object, since it uses a property setter under the hood. This means that using the `delete` keyword will not trigger a DOM update. Also, arrays need to be assigned after a mutation, even if it is mutated in place. +The DOM will update if there is an assignment on the object, since it uses a property setter under the hood. This means that using the `delete` keyword will not trigger a DOM update. Also, arrays need to be assigned after a mutation, even if it is mutated in place. This is a conscious decision based on performance, replacing the prototype of an object causes performance problems in every JavaScript engine. ## Under the Hood diff --git a/lib/define_properties.js b/lib/define_properties.js index 47a60cf..931b6ed 100644 --- a/lib/define_properties.js +++ b/lib/define_properties.js @@ -79,16 +79,15 @@ function defineProperties (obj, def) { if (mount) { node = branch.node.cloneNode(true) node = mount(node, value, previousValue, i) || node - activeNodes[i] = parentNode.insertBefore(node, branch.marker) - continue } - if (definition) { + else if (definition) { node = processNodes(branch.node.cloneNode(true), definition) defineProperties(value, definition) - activeNodes[i] = parentNode.insertBefore(node, branch.marker) - continue } + + activeNodes[i] = parentNode.insertBefore(node, + activeNodes[i + 1] || branch.marker) } // Reset length to current values. diff --git a/package.json b/package.json index ee1df9c..18ad34d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "simulacra", "description": "One-way data binding for web applications.", - "version": "0.0.6", + "version": "0.0.7", "license": "MIT", "author": { "email": "0x8890@airmail.cc",