diff --git a/docs/change-log.md b/docs/change-log.md index 1627c459..d889581a 100644 --- a/docs/change-log.md +++ b/docs/change-log.md @@ -18,6 +18,7 @@ - fix dom element ownership bug when mixing keyed elements and third party plugin elements [#463](https://github.com/lhorie/mithril.js/issues/463) - fix edge case in flatten algorithm [#448](https://github.com/lhorie/mithril.js/issues/448) - prevent unnecessary DOM move operation when mixing keyed and unkeyed elements [#398](https://github.com/lhorie/mithril.js/issues/398) +- revert [#382](https://github.com/lhorie/mithril.js/issues/382) due to diff regression [#512](https://github.com/lhorie/mithril.js/issues/512) --- diff --git a/docs/getting-started.md b/docs/getting-started.md index 796312aa..6eef1858 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -130,25 +130,23 @@ In the case of our todo application, the view-model needs a few things: it needs ```javascript //define the view-model -todo.vm = (function() { - var vm = {} - vm.init = function() { +todo.vm = { + init: function() { //a running list of todos - vm.list = new todo.TodoList(); + todo.vm.list = new todo.TodoList(); //a slot to store the name of a new todo before it is created - vm.description = m.prop(""); + todo.vm.description = m.prop(''); //adds a todo to the list, and clears the description field for user convenience - vm.add = function(description) { + todo.vm.add = function(description) { if (description()) { - vm.list.push(new todo.Todo({description: description()})); - vm.description(""); + todo.vm.list.push(new todo.Todo({description: description()})); + todo.vm.description(""); } }; } - return vm -}()) +}; ``` The code above defines a view-model object called `vm`. It is simply a javascript object that has a `init` function. This function initializes the `vm` object with three members: `list`, which is simply an array, `description`, which is an `m.prop` getter-setter function with an empty string as the initial value, and `add`, which is a method that adds a new Todo instance to `list` if an input description getter-setter is not an empty string. diff --git a/mithril.js b/mithril.js index 1a2742df..8d93e603 100644 --- a/mithril.js +++ b/mithril.js @@ -61,7 +61,8 @@ var m = (function app(window, undefined) { for (var attrName in attrs) { if (attrName === classAttrName) { - if (attrs[attrName] !== "") cell.attrs[attrName] = (cell.attrs[attrName] || "") + " " + attrs[attrName]; + var className = cell.attrs[attrName] + cell.attrs[attrName] = (className && attrs[attrName] ? className + " " : className || "") + attrs[attrName]; } else cell.attrs[attrName] = attrs[attrName] } diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 703a3605..3c24e130 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -29,10 +29,10 @@ function testMithril(mock) { test(function() {return m(".foo", {"class": "bar"}).attrs["class"] == "foo bar"}) test(function() {return m(".foo", {className: "bar"}).attrs.className == "foo bar"}) test(function() {return m(".foo", {className: ""}).attrs.className == "foo"}) - test(function() {return m("div", {className: ""}).attrs.className === undefined}) //https://github.com/lhorie/mithril.js/issues/382 + test(function() {return m("div", {className: ""}).attrs.className === ""}) //https://github.com/lhorie/mithril.js/issues/382 and 512 test(function() {return m("div", {class: ""}).attrs.className === undefined}) test(function() {return m("div", {className: ""}).attrs.class === undefined}) - test(function() {return m("div", {class: ""}).attrs.class === undefined}) + test(function() {return m("div", {class: ""}).attrs.class === ""}) test(function() {return m("div", [1, 2, 3], 4).children.length === 2}) test(function() {return m("div", [1, 2, 3], 4).children[0].length === 3}) test(function() {return m("div", [1, 2, 3], 4).children[1] === 4})