From 40637fe99fe24cbd6d26e2d586687831c65ade04 Mon Sep 17 00:00:00 2001 From: Isiah Meadows Date: Mon, 27 Mar 2017 12:41:45 -0400 Subject: [PATCH] Update components.md [ci skip] --- docs/components.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/components.md b/docs/components.md index 940b7444..3d958aad 100644 --- a/docs/components.md +++ b/docs/components.md @@ -114,7 +114,7 @@ class ES6ClassComponent { this.kind = "ES6 class" } view() { - return m("div", "Hello from an " + this.kind) + return m("div", `Hello from an ${this.kind}`) } oncreate() { console.log(`A ${this.kind} component was created`) @@ -122,7 +122,7 @@ class ES6ClassComponent { } ``` -Component classes must define a `view()` method. +Component classes must define a `view()` method, detected via `.prototype.view`, to get the tree to render. They can be consumed in the same way regular components can. @@ -148,8 +148,6 @@ class AnotherES6ClassComponent { } ``` -More generally, a constructible function whose `.prototype.view` is a function will be treated as a class. - #### Closure components Functionally minded developers may prefer using the "closure component" syntax: @@ -170,7 +168,7 @@ function closureComponent(vnode) { } ``` -The returned object must hold a `view` function. +The returned object must hold a `view` function, used to get the tree to render. They can be consumed in the same way regular components can. @@ -230,9 +228,9 @@ m(ComponentWithInitialState) //
Initial content
``` -For class components, the state is an instance of the class. +For class components, the state is an instance of the class, set right after the constructor is called. -For closure components, the state is the object returned by the closure. The state object is mostly redundant for closure components (since variables defined in the closure scope can be used instead). +For closure components, the state is the object returned by the closure, set right after the closure returns. The state object is mostly redundant for closure components (since variables defined in the closure scope can be used instead). #### Via vnode.state