diff --git a/docs/components.md b/docs/components.md index da76aa66..3153beb3 100644 --- a/docs/components.md +++ b/docs/components.md @@ -22,9 +22,9 @@ Let's create a simple model entity which we'll use in a simple application, to i ```javascript var Contact = function(data) { data = data || {} - this.id = m.prop(data.id) - this.name = m.prop(data.name) - this.email = m.prop(data.email) + this.id = m.prop(data.id || "") + this.name = m.prop(data.name || "") + this.email = m.prop(data.email || "") } Contact.list = function(data) { return m.request({method: "GET", url: "/api/contact", type: Contact}) @@ -293,7 +293,7 @@ var Observable = function() { } }, trigger: function(channel, args) { - console.log(channel) + console.log("triggered: " + channel) channels[channel].map(function(callback) { callback(args) }) @@ -386,7 +386,9 @@ var ContactsWidget = { view: function(ctrl) { return [ m.component(ContactForm), - m.component(ContactList, {contacts: ctrl.contacts}) + ctrl.contacts() === undefined + ? m("div", "loading contacts...") //waiting for promise to resolve + : m.component(ContactList, {contacts: ctrl.contacts}) ] } } @@ -394,10 +396,13 @@ var ContactsWidget = { //ContactList no longer calls `Contact.save` var ContactForm = { controller: function(args) { - this.contact = m.prop(new Contact()) - this.save = function(contact) { + ctrl = this + ctrl.contact = m.prop(new Contact()) + ctrl.save = function(contact) { Observable.trigger("saveContact", {contact: contact}) + ctrl.contact = m.prop(new Contact()) //reset to empty contact } + return ctrl }, view: function(ctrl, args) { var contact = ctrl.contact() diff --git a/docs/mithril.component.md b/docs/mithril.component.md index 4e26d0b0..3aa7cdd6 100644 --- a/docs/mithril.component.md +++ b/docs/mithril.component.md @@ -13,7 +13,7 @@ - [Stateful components](#stateful-components) - [Parameterized initial state](#parameterized-initial-state) - [Data-driven component identity](#data-driven-component-identity) -- [Unloading components](#unloading-components) +- [Unloading/Unmounting components](#unloading-components) - [Nested asynchronous components](#nested-asynchronous-components) - [Limitations and caveats](#limitations-and-caveats) - [Opting out of the auto redrawing system](#opting-out-of-the-auto-redrawing-system) @@ -385,7 +385,7 @@ If a component's controller contains the function `onunload`, it will be called - when a new call to `m.mount` updates the root DOM element of the component in question - when a route changes (if you are using [`m.route`](mithril.route.md)) -To unload a component without loading another component, you can simply call `m.mount` with a `null` as the component parameter: +To unload/unmount a component without loading another component, you can simply call `m.mount` with a `null` as the component parameter: ```javascript m.mount(rootElement, null);