From c267114f069fb70e7bdb31107f552c94949ed797 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Sun, 22 Mar 2015 18:06:31 -0400 Subject: [PATCH 1/3] Correction to "Aggregation of resp." example --- docs/components.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/components.md b/docs/components.md index e23d00bd..3faaf0eb 100644 --- a/docs/components.md +++ b/docs/components.md @@ -329,7 +329,7 @@ var ContactsWidget = { view: function(ctrl) { return [ m.module(ContactForm, {onsave: ctrl.save}), - m.module(ContactList, {contacts: contacts}) + m.module(ContactList, {contacts: ctrl.contacts}) ] } } From 3b012187c03de8f3e2c9d7b827d6767de08eb6d7 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Sun, 22 Mar 2015 18:07:46 -0400 Subject: [PATCH 2/3] Consistently use `args` for arguments passed to a module --- docs/components.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/components.md b/docs/components.md index 3faaf0eb..5c9806ba 100644 --- a/docs/components.md +++ b/docs/components.md @@ -61,12 +61,12 @@ Modules can have arguments "preloaded" into them. Calling `m.module` without a D ```javascript //declare a component var MyModule = {} -MyModule.controller = function(options, extras) { +MyModule.controller = function(args, extras) { this.greeting = "Hello" - console.log(options.name, extras) + console.log(args.name, extras) } -MyModule.view = function(ctrl, options, extras) { - return m("h1", ctrl.greeting + " " + options.name + " " + extras) +MyModule.view = function(ctrl, args, extras) { + return m("h1", ctrl.greeting + " " + args.name + " " + extras) } @@ -148,11 +148,11 @@ var TemperatureConverter = { return (value 9 / 5 * (v - 273.15)) + 32 } }, - view: function(ctrl, options) { + view: function(ctrl, args) { return m('div', [ - "celsius:", ctrl.kelvinToCelsius(options.value), + "celsius:", ctrl.kelvinToCelsius(args.value), m("br"), - "fahrenheit:", ctrl.kelvinToFahrenheit(options.value), + "fahrenheit:", ctrl.kelvinToFahrenheit(args.value), ]); } }; From 946ebeeb4255d9cd46c91ee4d015d82cec04f106 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Sun, 22 Mar 2015 18:31:16 -0400 Subject: [PATCH 3/3] Add missing ctrl argument --- docs/components.md | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/docs/components.md b/docs/components.md index 5c9806ba..fdaab2df 100644 --- a/docs/components.md +++ b/docs/components.md @@ -88,7 +88,7 @@ var MyApp = { view: function() { return m("div", [ m("h1", "My app"), - + //a parameterized module m.module(MyModule, {name: "users"}, "from component"), ]) @@ -139,7 +139,7 @@ var MyApp = { var TemperatureConverter = { controller: function() { //note how the controller does not handle the input arguments - + //define some helper functions to be called from the view this.kelvinToCelsius = function(value) { return value - 273.15 @@ -340,14 +340,14 @@ var ContactForm = { }, view: function(ctrl, args) { var contact = ctrl.contact() - + return m("form", [ m("label", "Name"), m("input", {oninput: m.withAttr("value", contact.name), value: contact.name()}), - + m("label", "Email"), m("input", {oninput: m.withAttr("value", contact.email), value: contact.email()}), - + m("button[type=button]", {onclick: args.onsave.bind(this, contact)}, "Save") ]) } @@ -408,16 +408,16 @@ var ContactForm = { Contact.save(contact) } }, - view: function() { + view: function(ctrl) { var contact = ctrl.contact() - + return m("form", [ m("label", "Name"), m("input", {oninput: m.withAttr("value", contact.name), value: contact.name()}), - + m("label", "Email"), m("input", {oninput: m.withAttr("value", contact.email), value: contact.email()}), - + m("button[type=button]", {onclick: ctrl.save.bind(this, contact)}, "Save") ]) } @@ -494,16 +494,16 @@ var ContactForm = { Contact.save(contact).then(Observable.trigger) } }, - view: function() { + view: function(ctrl) { var contact = ctrl.contact() - + return m("form", [ m("label", "Name"), m("input", {oninput: m.withAttr("value", contact.name), value: contact.name()}), - + m("label", "Email"), m("input", {oninput: m.withAttr("value", contact.email), value: contact.email()}), - + m("button[type=button]", {onclick: ctrl.save.bind(this, contact)}, "Save") ]) } @@ -610,14 +610,14 @@ var ContactForm = { }, view: function(ctrl, args) { var contact = ctrl.contact() - + return m("form", [ m("label", "Name"), m("input", {oninput: m.withAttr("value", contact.name), value: contact.name()}), - + m("label", "Email"), m("input", {oninput: m.withAttr("value", contact.email), value: contact.email()}), - + m("button[type=button]", {onclick: ctrl.save.bind(this, contact)}, "Save") ]) } @@ -679,14 +679,14 @@ var ContactForm = { }, view: function(ctrl, args) { var contact = ctrl.contact() - + return m("form", [ m("label", "Name"), m("input", {oninput: m.withAttr("value", contact.name), value: contact.name()}), - + m("label", "Email"), m("input", {oninput: m.withAttr("value", contact.email), value: contact.email()}), - + m("button[type=button]", {onclick: ctrl.save.bind(this, contact)}, "Save") ]) } @@ -731,7 +731,7 @@ var Uploader = { formData.append(key, files[i]) } } - + //simply pass the FormData object intact to the underlying XMLHttpRequest, instead of JSON.stringify'ing it options.serialize = function(value) {return value} options.data = formData @@ -741,7 +741,7 @@ var Uploader = { serialize: function(files) { var promises = Array.prototype.slice.call(files).map(function(file) { var deferred = m.deferred() - + var reader = new FileReader reader.readAsDataURL() reader.onloadend = function(e) { @@ -752,7 +752,7 @@ var Uploader = { }) return m.sync(promises) }, - + controller: function(args) { this.noop = function(e) { e.preventDefault() @@ -795,7 +795,7 @@ var Demo2 = { return m.request({method: "POST", url: "/api/assets", data: data}) } }, - + controller: function() { this.files = m.prop([]) this.save = function() {