Skip to content

Commit 8bba8d9

Browse files
authored
Merge pull request #259 from github/v2-doc-improvements
V2 doc improvements
2 parents 6aa2516 + f637cc1 commit 8bba8d9

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

docs/_guide/targets.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,32 @@ Important to note here is that nodes from the `shadowRoot` get returned _first_.
136136

137137
### What about without Decorators?
138138

139-
If you're using decorators, then the `@target` and `@targets` decorators will turn the decorated properties into getters.
139+
If you're not using decorators, then the `@target` and `@targets` decorators have an escape hatch: you can define a static class field using the `[target.static]` computed property, as an array of key names. Like so:
140140

141-
If you're not using decorators, then you'll need to make a `getter`, and call `findTarget(this, key)` or `findTargets(this, key)` in the getter, for example:
141+
```js
142+
import {controller, target, targets} from '@github/catalyst'
143+
144+
controller(class HelloWorldElement extends HTMLElement {
145+
// The same as `@target output`
146+
[target.static] = ['output']
147+
148+
// The same as `@targets pages; @targets links`
149+
[targets.static] = ['pages', 'links']
150+
151+
})
152+
```
153+
154+
This is functionally identical to:
142155

143156
```js
144-
import {findTarget, findTargets} from '@github/catalyst'
145-
class HelloWorldElement extends HTMLElement {
157+
import {controller} from '@github/catalyst'
146158

147-
get output() {
148-
return findTarget(this, 'output')
149-
}
159+
@controller
160+
class HelloWorldElement extends HTMLElement {
161+
@target output
150162

151-
get pages() {
152-
return findTargets(this, 'pages')
153-
}
163+
@targets pages
164+
@targets links
154165

155166
}
156-
```
167+
```

docs/_guide/your-first-component.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,21 @@ The `@controller` decorator ties together the various other decorators within Ca
4040

4141
- Derives a tag name based on your class name, removing the trailing `Element` suffix and lowercasing all capital letters, separating them with a dash.
4242
- Calls `window.customElements.define` with the newly derived tag name and your class.
43-
- Calls `defineObservedAttributes` with the class to add map any `@attr` decorators. See [attrs]({{ site.baseurl }}/guide/attrs) for more on this.
44-
- Injects the following code inside of the `connectedCallback()` function of your class:
45-
- `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.
46-
- `initializeAttrs(this)`; ensures that your element binds any `data-*` attributes to props. See [attrs]({{ site.baseurl }}/guide/attrs) for more on this.
43+
- Loads the `attrable` decorator, which provides the ability to define `@attr` decorators. See [attrs]({{ site.baseurl }}/guide/attrs) for more on this.
44+
- Loads the `actionable` decorator, which provides the ability to bind actions. See [actions]({{ site.baseurl }}/guide/actions) for more on this.
45+
- Loads the `targetable` decorator, which provides Target querying. See [targets]({{ site.baseurl }}/guide/targets) for more on this.
4746

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

5049
```js
51-
import {bind, initializeAttrs, defineObservedAttributes} from '@github/catalyst'
50+
import {attrable, targetable, actionable} from '@github/catalyst'
51+
52+
@register
53+
@actionable
54+
@attrable
55+
@targetable
5256
class HelloWorldElement extends HTMLElement {
53-
connectedCallback() {
54-
initializeAttrs(this)
55-
this.innerHTML = 'Hello World!'
56-
bind(this)
57-
}
5857
}
59-
defineObservedAttributes(HelloWorldElement)
60-
window.customElements.define('hello-world', HelloWorldElement)
6158
```
6259

6360
The `@controller` decorator saves on having to write this boilerplate for each element.

0 commit comments

Comments
 (0)