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

This commit is contained in:
Leo Horie 2015-07-07 13:19:00 -04:00
commit 9da3adaf3d
2 changed files with 14 additions and 9 deletions

View file

@ -22,9 +22,9 @@ Let's create a simple model entity which we'll use in a simple application, to i
```javascript ```javascript
var Contact = function(data) { var Contact = function(data) {
data = data || {} data = data || {}
this.id = m.prop(data.id) this.id = m.prop(data.id || "")
this.name = m.prop(data.name) this.name = m.prop(data.name || "")
this.email = m.prop(data.email) this.email = m.prop(data.email || "")
} }
Contact.list = function(data) { Contact.list = function(data) {
return m.request({method: "GET", url: "/api/contact", type: Contact}) return m.request({method: "GET", url: "/api/contact", type: Contact})
@ -293,7 +293,7 @@ var Observable = function() {
} }
}, },
trigger: function(channel, args) { trigger: function(channel, args) {
console.log(channel) console.log("triggered: " + channel)
channels[channel].map(function(callback) { channels[channel].map(function(callback) {
callback(args) callback(args)
}) })
@ -386,7 +386,9 @@ var ContactsWidget = {
view: function(ctrl) { view: function(ctrl) {
return [ return [
m.component(ContactForm), 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` //ContactList no longer calls `Contact.save`
var ContactForm = { var ContactForm = {
controller: function(args) { controller: function(args) {
this.contact = m.prop(new Contact()) ctrl = this
this.save = function(contact) { ctrl.contact = m.prop(new Contact())
ctrl.save = function(contact) {
Observable.trigger("saveContact", {contact: contact}) Observable.trigger("saveContact", {contact: contact})
ctrl.contact = m.prop(new Contact()) //reset to empty contact
} }
return ctrl
}, },
view: function(ctrl, args) { view: function(ctrl, args) {
var contact = ctrl.contact() var contact = ctrl.contact()

View file

@ -13,7 +13,7 @@
- [Stateful components](#stateful-components) - [Stateful components](#stateful-components)
- [Parameterized initial state](#parameterized-initial-state) - [Parameterized initial state](#parameterized-initial-state)
- [Data-driven component identity](#data-driven-component-identity) - [Data-driven component identity](#data-driven-component-identity)
- [Unloading components](#unloading-components) - [Unloading/Unmounting components](#unloading-components)
- [Nested asynchronous components](#nested-asynchronous-components) - [Nested asynchronous components](#nested-asynchronous-components)
- [Limitations and caveats](#limitations-and-caveats) - [Limitations and caveats](#limitations-and-caveats)
- [Opting out of the auto redrawing system](#opting-out-of-the-auto-redrawing-system) - [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 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)) - 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 ```javascript
m.mount(rootElement, null); m.mount(rootElement, null);