diff --git a/mithril.js b/mithril.js index 52529047..60bf31e5 100644 --- a/mithril.js +++ b/mithril.js @@ -61,6 +61,7 @@ var m = (function app(window, undefined) { if (attrs.hasOwnProperty(attrName)) { if (attrName === classAttrName && attrs[attrName] != null && attrs[attrName] !== "") { classes.push(attrs[attrName]) + cell.attrs[attrName] = "" //create key in correct iteration order } else cell.attrs[attrName] = attrs[attrName] } @@ -259,7 +260,7 @@ var m = (function app(window, undefined) { var dataAttrKeys = Object.keys(data.attrs) var hasKeys = dataAttrKeys.length > ("key" in data.attrs ? 1 : 0) //if an element is different enough from the one in cache, recreate it - if (data.tag != cached.tag || dataAttrKeys.join() != Object.keys(cached.attrs).join() || data.attrs.id != cached.attrs.id || data.attrs.key != cached.attrs.key || (m.redraw.strategy() == "all" && cached.configContext && cached.configContext.retain !== true) || (m.redraw.strategy() == "diff" && cached.configContext && cached.configContext.retain === false)) { + if (data.tag != cached.tag || dataAttrKeys.sort().join() != Object.keys(cached.attrs).sort().join() || data.attrs.id != cached.attrs.id || data.attrs.key != cached.attrs.key || (m.redraw.strategy() == "all" && cached.configContext && cached.configContext.retain !== true) || (m.redraw.strategy() == "diff" && cached.configContext && cached.configContext.retain === false)) { if (cached.nodes.length) clear(cached.nodes); if (cached.configContext && typeof cached.configContext.onunload === FUNCTION) cached.configContext.onunload() if (cached.controllers) { diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 71968fbf..1b11e502 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -41,6 +41,12 @@ function testMithril(mock) { test(function() {return m("div", [1, 2, 3], [4, 5, 6, 7]).children[0].length === 3}) test(function() {return m("div", [1, 2, 3], [4, 5, 6, 7]).children[1].length === 4}) test(function() {return m("div", [1], [2], [3]).children.length === 3}) + test(function() { + //class changes shouldn't trigger dom recreation + var v1 = m(".foo", {class: "", onclick: function() {}}) + var v2 = m(".foo", {class: "bar", onclick: function() {}}) + return Object.keys(v1.attrs).join() === Object.keys(v2.attrs).join() + }) //m.mount test(function() {