Merge remote-tracking branch 'origin/next' into next

This commit is contained in:
Leo Horie 2015-06-09 16:22:20 -05:00
commit e6d6db6123
5 changed files with 26 additions and 11 deletions

View file

@ -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)
You can file bugs in the [issues page on Github](https://github.com/lhorie/mithril.js/issues?state=open)

View file

@ -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.

View file

@ -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
}
}
},

View file

@ -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";
@ -547,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() {
@ -703,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) {

View file

@ -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")