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:
parent
4ac33fa483
commit
a147023f4e
6 changed files with 213 additions and 101 deletions
18
docs/prop.md
18
docs/prop.md
|
|
@ -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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue