document classes
This commit is contained in:
parent
271ef96fef
commit
65941d1416
2 changed files with 46 additions and 0 deletions
|
|
@ -9,10 +9,17 @@
|
|||
|
||||
### v1.0.2
|
||||
|
||||
#### News
|
||||
|
||||
- support for ES6 class components
|
||||
- updated typescript definitions
|
||||
|
||||
#### Bug fixes
|
||||
|
||||
- fix IE11 input[type] error - [#1610](https://github.com/lhorie/mithril.js/issues/1610)
|
||||
- apply [#1609](https://github.com/lhorie/mithril.js/issues/1609) to unkeyed children case
|
||||
- fix abort detection [#1612](https://github.com/lhorie/mithril.js/issues/1612)
|
||||
- fix input value focus issue when value is loosely equal to old value [#1593](https://github.com/lhorie/mithril.js/issues/1593)
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
- [Structure](#structure)
|
||||
- [Lifecycle methods](#lifecycle-methods)
|
||||
- [State](#state)
|
||||
- [ES6 classes](#es6-classes)
|
||||
- [Avoid-anti-patterns](#avoid-anti-patterns)
|
||||
|
||||
### Structure
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue