Skip to content

Commit 081f523

Browse files
committed
docs: Update "What does @controller do" section
1 parent d9c1fff commit 081f523

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

docs/_guide/your-first-component.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,33 @@ Remember! A class name _must_ include at least two CamelCased words (not includi
4141

4242
### What does `@controller` do?
4343

44-
The `@controller` decorator doesn't do all that much. Catalyst components are just "Custom Elements" under the hood, and the `@controller` decorator saves you writing some boilerplate that you'd otherwise have to write by hand. Specifically the `@controller` decorator:
44+
The `@controller` decorator ties together the various other decorators within Catalyst, plus a few extra conveniences such as automatically registering the element, which saves you writing some boilerplate that you'd otherwise have to write by hand. Specifically the `@controller` decorator:
4545

4646
- Derives a tag name based on your class name, removing the trailing `Element` suffix and lowercasing all capital letters, separating them with a dash.
4747
- Calls `window.customElements.register` with the newly derived tag name and your class.
48-
- Injects a call to `bind(this)` inside of the `connectedCallback()` of your class; this ensures that as your element connects it picks up any `data-action` handlers. See [actions]({{ site.baseurl }}/guide/actions) for more on this.
48+
- Calls `defineObservedAttributes` with the class to add map any `@attr` decorators. See [attrs]({{ site.baseurl }}/guide/attrs) for more on this.
49+
- Injects the following code inside of the `connectedCallback()` function of your class:
50+
- `bind(this)`; ensures that as your element connects it picks up any `data-action` handlers. See [actions]({{ site.baseurl }}/guide/actions) for more on this.
51+
- `autoShadowRoot(this)`; ensures that your element loads any `data-shadowroot` templates. See [rendering]({{ site.baseurl }}/guide/rendering) for more on this.
52+
- `initializeAttrs(this)`; ensures that your element binds any `data-*` attributes to props. See [attrs]({{ site.baseurl }}/guide/attrs) for more on this.
4953

5054
You can do all of this manually; for example here's the above `HelloWorldElement`, written without the `@controller` annotation:
5155

5256
```js
53-
import {bind} from '@github/catalyst'
57+
import {bind, autoShadowRoot, initializeAttrs, defineObservedAttributes} from '@github/catalyst'
5458
class HelloWorldElement extends HTMLElement {
5559
connectedCallback() {
56-
bind(this)
60+
autoShadowRoot(this)
61+
initializeAttrs(this)
5762
this.innerHTML = 'Hello World!'
63+
bind(this)
5864
}
5965
}
66+
defineObservedAttributes(HelloWorldElement)
6067
window.customElements.register('hello-world', HelloWorldElement)
6168
```
6269

63-
The Catalyst version isn't all that different, it's just that we have the `@controller` decorator to save on some of the boilerplate.
70+
Using the `@controller` decorator saves on having to write this boilerplate for each element.
6471

6572
### What about without TypeScript Decorators?
6673

0 commit comments

Comments
 (0)