From 65941d1416c063bf3b64506d42b7cf1d14d009a7 Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 19 Feb 2017 08:29:35 -0500 Subject: [PATCH] document classes --- docs/change-log.md | 7 +++++++ docs/components.md | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/docs/change-log.md b/docs/change-log.md index 014f6c23..5a9b75a3 100644 --- a/docs/change-log.md +++ b/docs/change-log.md @@ -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) --- diff --git a/docs/components.md b/docs/components.md index 6134ccc1..db5c0b0f 100644 --- a/docs/components.md +++ b/docs/components.md @@ -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: