diff --git a/docs/getting-started.md b/docs/getting-started.md index 9816a024..2c3c6193 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -286,12 +286,14 @@ The difference, aside from avoiding an anonymous function, is that the `m.withAt In addition to bi-directional data binding, we can also bind parameterized functions to events: ```javascript -m("button", {onclick: todo.vm.add.bind(todo.vm, todo.vm.description)}, "Add") +var vm = todo.vm + +m("button", {onclick: vm.add.bind(vm, vm.description)}, "Add") ``` In the code above, we are simply using the native Javascript `Function::bind` method. This creates a new function with the parameter already set. In functional programming, this is called [*partial application*](http://en.wikipedia.org/wiki/Partial_application). -The `todo.vm.add.bind(todo.vm, todo.vm.description)` expression above returns a function that is equivalent to this code: +The `vm.add.bind(vm, vm.description)` expression above returns a function that is equivalent to this code: ```javascript onclick: function(e) { diff --git a/docs/mithril.module.md b/docs/mithril.module.md index f1470f50..1fe005b3 100644 --- a/docs/mithril.module.md +++ b/docs/mithril.module.md @@ -29,14 +29,20 @@ Modules and namespaces are often used interchangeably, but namespaces that do no You can make anonymous modules out of existing classes ```javascript -//controller class -var dashboardController = function() { +//model object +var dashboardViewModel = {}; +dashboardViewModel.init = function() { this.greeting = "Hello"; }; +//controller class +var dashboardController = function() { + dashboardViewModel.init(); +}; + //view class -var dashboardView = function(ctrl) { - return m("h1", ctrl.greeting); +var dashboardView = function() { + return m("h1", dashboardViewModel.greeting); }; //initialize an anonymous module diff --git a/docs/mithril.render.md b/docs/mithril.render.md index bec3ecbe..c2e11752 100644 --- a/docs/mithril.render.md +++ b/docs/mithril.render.md @@ -77,7 +77,7 @@ app.bindOnce = new function() { } //here's the view -app.view = function(ctrl) { +app.view = function() { m(".layout", [ app.bindOnce(function() { //this only runs once in order to boost performance diff --git a/docs/practices.md b/docs/practices.md index 069debee..ffdef551 100644 --- a/docs/practices.md +++ b/docs/practices.md @@ -33,19 +33,24 @@ var app = {}; app.PageList = function() { return m.request({method: "GET", url: "pages.json"}); }; -``` -```javascript -//app.controller.js -app.controller = function() { +app.vm = {}; +app.vm.init = function() { this.pages = new app.PageList(); }; ``` +```javascript +//app.controller.js +app.controller = function() { + app.vm.init(); +}; +``` + ```javascript //app.view.js -app.view = function(ctrl) { - return ctrl.pages().map(function(page) { +app.view = function() { + return app.vm.pages().map(function(page) { return m("a", {href: page.url}, page.title); }); }; diff --git a/docs/tools.md b/docs/tools.md index 076a1ecb..b001f5ec 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -17,11 +17,11 @@ It is useful for teams where styling and functionality are done by different peo The tool allows you to write code like this: ```javascript -todo.view = function(ctrl) { +todo.view = function() { return
- - + + };