Docs - prioritize closure components for state (#2292)

* Emphasize closure components in components.md

* Use closure components for all stateful component examples

* Add change-log entry

* Edits and separate sections for closure, class & POJO state
This commit is contained in:
spacejack 2018-11-13 01:04:04 -05:00 committed by Isiah Meadows
parent 4ac33fa483
commit a147023f4e
6 changed files with 213 additions and 101 deletions

View file

@ -54,15 +54,15 @@ The `m.prop` method creates a prop, a getter/setter object wrapping a single mut
In conjunction with [`m.withAttr`](withAttr.md), you can emulate two-way binding pretty easily.
```javascript
var Component = {
oninit: function(vnode) {
vnode.state.current = m.prop("")
},
view: function(vnode) {
return m("input", {
oninput: m.withAttr("value", vnode.state.current.set),
value: vnode.state.current.get(),
})
function Component() {
var current = m.prop("")
return {
view: function(vnode) {
return m("input", {
oninput: m.withAttr("value", current.set),
value: current.get(),
})
}
}
}
```