You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -65,6 +73,10 @@ The actions syntax follows a pattern of `event:controller#method`.
65
73
66
74
Multiple actions can be bound to multiple events, methods, and controllers. For example:
67
75
76
+
<!-- annotations
77
+
data-action: Fires all of these methods depending on the event
78
+
-->
79
+
68
80
```html
69
81
<analytics-tracking>
70
82
<hello-world>
@@ -95,6 +107,10 @@ Multiple actions can be bound to multiple events, methods, and controllers. For
95
107
96
108
A Controller may emit custom events, which may be listened to by other Controllers using the same Actions Syntax. There is no extra syntax needed for this. For example a `lazy-loader` Controller might dispatch a `loaded` event, once its contents are loaded, and other controllers can listen to this event:
97
109
110
+
<!-- annotations
111
+
data-action "loaded: Calls enable() on the `loaded` custom event
@@ -66,6 +70,10 @@ Below is a handy reference for the small differences, this is all explained in m
66
70
67
71
If an attribute is first set to a `string`, then it can only ever be a `string` during the lifetime of an element. The property will return an empty string (`''`) if the attribute doesn't exist, and trying to set it to something that isn't a string will turn it into one before assignment.
@@ -87,6 +95,10 @@ class HelloWorldElement extends HTMLElement {
87
95
88
96
If an attribute is first set to a boolean, then it can only ever be a boolean during the lifetime of an element. Boolean properties check for _presence_ of an attribute, sort of like how [`required`, `disabled` & `readonly` attributes work on forms](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes#boolean_attributes) The property will return `false` if the attribute doesn't exist, and `true` if it does, regardless of the value. If the property is set to `false` then `removeAttribute` is called, whereas `setAttribute(name, '')` is called when setting to a truthy value.
@@ -108,6 +120,10 @@ class HelloWorldElement extends HTMLElement {
108
120
109
121
If an attribute is first set to a number, then it can only ever be a number during the lifetime of an element. This is sort of like the [`maxlength` attribute on inputs](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/maxlength). The property will return `0` if the attribute doesn't exist, and will be coerced to `Number` if it does - this means it is _possible_ to get back `NaN`. Negative numbers and floats are also valid.
Copy file name to clipboardExpand all lines: docs/_guide/your-first-component.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,15 @@ chapter: 3
7
7
8
8
Catalyst's `@controller` decorator lets you create Custom Elements with virtually no boilerplate, by automatically calling `customElements.register`, and by adding ["Actions"]({{ site.baseurl }}/guide/actions) and ["Targets"]({{ site.baseurl }}/guide/targets) features described later. Using TypeScript (with `decorators` support enabled), simply add `@controller` to the top of your class:
9
9
10
+
<!-- annotations
11
+
controller: This must be added to all Catalyst controllers.
12
+
extends HTMLElement: This must be added to all Catalyst controllers.
13
+
connectedCallback: This runs when the element is added to the DOM | {{ site.baseurl }}/guide/lifecycle-hooks/#codeconnectedcallbackcode
14
+
-->
15
+
10
16
```js
11
17
import {controller} from'@github/catalyst'
18
+
12
19
@controller
13
20
classHelloWorldElementextendsHTMLElement {
14
21
connectedCallback() {
@@ -62,6 +69,8 @@ Using the `@controller` decorator saves on having to write this boilerplate for
62
69
If you don't want to use TypeScript decorators, you can use `controller` as a regular function, and just pass it your class:
0 commit comments