docs: merge docs from next to master

This commit is contained in:
Pat Cavit 2017-03-24 15:36:53 -07:00
parent 2a61e17332
commit 33aa1fa735
19 changed files with 285 additions and 72 deletions

View file

@ -3,6 +3,7 @@
- [Structure](#structure)
- [Lifecycle methods](#lifecycle-methods)
- [State](#state)
- [ES6 classes](#es6-classes)
- [Avoid-anti-patterns](#avoid-anti-patterns)
### Structure
@ -108,7 +109,7 @@ The state of a component can be accessed three ways: as a blueprint at initializ
#### At initialization
Any property attached to the component object is copied for every instance of the component. This allows simple state initialization.
The component object is the prototype of each component instance, so any property defined on the component object will be accessible as a property of `vnode.state`. This allows simple state initialization.
In the example below, `data` is a property of the `ComponentWithInitialState` component's state object.
@ -170,6 +171,44 @@ Be aware that when using ES5 functions, the value of `this` in nested anonymous
---
### ES6 classes
Components can also be written using ES6 class syntax:
```javascript
class ES6ClassComponent {
view() {
return m("div", "Hello from an ES6 class")
}
}
```
They can be consumed in the same way regular components can.
```javascript
// EXAMPLE: via m.render
m.render(document.body, m(ES6ClassComponent))
// EXAMPLE: via m.mount
m.mount(document.body, ES6ClassComponent)
// EXAMPLE: via m.route
m.route(document.body, "/", {
"/": ES6ClassComponent
})
// EXAMPLE: component composition
class AnotherES6ClassComponent {
view() {
return m("main", [
m(ES6ClassComponent)
])
}
}
```
---
### Avoid anti-patterns
Although Mithril is flexible, some code patterns are discouraged: