From 7288afc18ecb3d5cd6d599f67409b80b730d5caa Mon Sep 17 00:00:00 2001 From: Brendon Murphy Date: Fri, 8 May 2015 20:16:12 -0700 Subject: [PATCH 1/6] Fix conversion in component stateless example --- docs/mithril.component.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/mithril.component.md b/docs/mithril.component.md index 4995a880..0766de56 100644 --- a/docs/mithril.component.md +++ b/docs/mithril.component.md @@ -280,7 +280,7 @@ var TemperatureConverter = { return value - 273.15 }, kelvinToFahrenheit: function(value) { - return (value 9 / 5 * (v - 273.15)) + 32 + return (9 / 5 * (value - 273.15)) + 32 } } }, From d89810234a7e4a9fda1106ddcffead061ecb26f0 Mon Sep 17 00:00:00 2001 From: Jason Staten Date: Mon, 1 Jun 2015 15:11:44 -0600 Subject: [PATCH 2/6] accept component as first argument to m() --- mithril.js | 1 + tests/mithril-tests.js | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index 869c114d..20ca227b 100644 --- a/mithril.js +++ b/mithril.js @@ -34,6 +34,7 @@ var m = (function app(window, undefined) { */ function m() { var args = [].slice.call(arguments); + if (type.call(args[0]) == OBJECT) return parameterize(args[0], args.slice(1)); var hasAttrs = args[1] != null && type.call(args[1]) === OBJECT && !("tag" in args[1] || "view" in args[1]) && !("subtree" in args[1]); var attrs = hasAttrs ? args[1] : {}; var classAttrName = "class" in attrs ? "class" : "className"; diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index cd49fef0..041b5331 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -47,7 +47,23 @@ function testMithril(mock) { var v2 = m(".foo", {class: "bar", onclick: function() {}}) return Object.keys(v1.attrs).join() === Object.keys(v2.attrs).join() }) - + test(function() { + //m should proxy object first arg to m.component + var component = { + controller: function(args) { + this.args = args + }, + view: function(ctrl) { + return m("div", "testing") + } + } + var args = {age: 12} + var c1 = m(component, args).controller() + var c2 = m.component(component, args).controller() + + return c1.args === args && c1.args == c2.args + }) + //m.mount test(function() { var root = mock.document.createElement("div") From 3883d029f22614a1c235211bd938655eaa0d3b2a Mon Sep 17 00:00:00 2001 From: pelonpelon Date: Mon, 1 Jun 2015 20:27:04 -0500 Subject: [PATCH 3/6] Minor corrections to getting-started.md --- docs/getting-started.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index b0f0db02..0b2814ce 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -37,7 +37,7 @@ In Mithril, an application typically lives in a namespace and contains component For simplicity, our application will have only one component, and we're going to use it as the namespace for our application. -In Mithril, a *component* is an object that contains two functions: `controller` and `view`. +In Mithril, a *component* is an object that contains a `view` function and optionally a `controller` function. ``` //an empty Mithril component @@ -149,7 +149,7 @@ todo.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. +The code above defines a view-model object called `vm`. It is simply a javascript object that has an `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. Later in this guide, we'll pass the `description` property as the parameter to this function. When we get there, I'll explain why we're passing description as an argument instead of simply using OOP-style member association. From a406de408a2426a13cf726dd4d8cbc9638531b84 Mon Sep 17 00:00:00 2001 From: Jason Staten Date: Tue, 2 Jun 2015 06:44:42 -0600 Subject: [PATCH 4/6] Triple equals --- mithril.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index 20ca227b..87b16e43 100644 --- a/mithril.js +++ b/mithril.js @@ -34,7 +34,7 @@ var m = (function app(window, undefined) { */ function m() { var args = [].slice.call(arguments); - if (type.call(args[0]) == OBJECT) return parameterize(args[0], args.slice(1)); + if (type.call(args[0]) === OBJECT) return parameterize(args[0], args.slice(1)); var hasAttrs = args[1] != null && type.call(args[1]) === OBJECT && !("tag" in args[1] || "view" in args[1]) && !("subtree" in args[1]); var attrs = hasAttrs ? args[1] : {}; var classAttrName = "class" in attrs ? "class" : "className"; From 25cbdbbad5c186975b05cbd8cc258ba7c816e95a Mon Sep 17 00:00:00 2001 From: pelonpelon Date: Wed, 3 Jun 2015 13:11:47 -0500 Subject: [PATCH 5/6] community.md -- link to github wiki --- docs/community.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/community.md b/docs/community.md index e658106e..fe3dc714 100644 --- a/docs/community.md +++ b/docs/community.md @@ -38,14 +38,14 @@ Join the #mithriljs IRC channel on [Freenode](http://webchat.freenode.net). --- -### Projects and Snippets +### Github Wiki -A collection of projects and snippets created by Mithril users. A great place to find useful tools. +A collection of community projects, tutorials, starter kits and snippets created by Mithril users. A great place to find useful tools. -Go to the [Mithril wiki](https://github.com/lhorie/mithril.js/wiki/Community-Projects-and-Snippets) +Go to the [Mithril wiki](https://github.com/lhorie/mithril.js/wiki) --- ### Bug Tracker -You can file bugs in the [issues page on Github](https://github.com/lhorie/mithril.js/issues?state=open) \ No newline at end of file +You can file bugs in the [issues page on Github](https://github.com/lhorie/mithril.js/issues?state=open) From 756cbb19247eac1299db0f7a13590fa452894928 Mon Sep 17 00:00:00 2001 From: nasitra Date: Sun, 7 Jun 2015 20:38:08 +0900 Subject: [PATCH 6/6] Remove unused variables --- mithril.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mithril.js b/mithril.js index 87b16e43..145d615e 100644 --- a/mithril.js +++ b/mithril.js @@ -548,7 +548,7 @@ var m = (function app(window, undefined) { return gettersetter(store) }; - var roots = [], components = [], controllers = [], lastRedrawId = null, lastRedrawCallTime = 0, computePreRedrawHook = null, computePostRedrawHook = null, prevented = false, topComponent, unloaders = []; + var roots = [], components = [], controllers = [], lastRedrawId = null, lastRedrawCallTime = 0, computePreRedrawHook = null, computePostRedrawHook = null, topComponent, unloaders = []; var FRAME_BUDGET = 16; //60 frames per second = 1 call per 16 ms function parameterize(component, args) { var controller = function() { @@ -704,8 +704,6 @@ var m = (function app(window, undefined) { //config: m.route else if (arguments[0].addEventListener || arguments[0].attachEvent) { var element = arguments[0]; - var isInitialized = arguments[1]; - var context = arguments[2]; var vdom = arguments[3]; element.href = (m.route.mode !== 'pathname' ? $location.pathname : '') + modes[m.route.mode] + vdom.attrs.href; if (element.addEventListener) {