Skip to content

Commit 395bf7b

Browse files
authored
Merge branch 'main' into node-16-in-codespaces
2 parents b6b7b17 + 91529fc commit 395bf7b

27 files changed

Lines changed: 10451 additions & 8631 deletions

.eslintrc.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"plugins": ["github"],
44
"extends": ["plugin:github/recommended", "plugin:github/typescript", "plugin:github/browser"],
55
"rules": {
6-
"no-invalid-this": "off",
7-
"@typescript-eslint/no-invalid-this": ["error"],
6+
"import/no-unresolved": "off",
7+
"github/no-inner-html": "off",
8+
"i18n-text/no-en": "off",
89
"import/extensions": ["error", "ignorePackages"],
910
"@typescript-eslint/consistent-type-imports": ["error", {"prefer": "type-imports"}]
1011
},
@@ -24,6 +25,9 @@
2425
},
2526
{
2627
"files": "*.cjs",
28+
"rules": {
29+
"import/no-commonjs": "off"
30+
},
2731
"env": {
2832
"node": true
2933
}

.github/workflows/nodejs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ jobs:
2626
node-version: 13.11.0
2727
- name: Install dependencies
2828
run: npm i
29+
- name: Lint Codebase
30+
run: npm run lint
2931
- name: Run Node.js Tests
3032
run: npm run test
33+
- name: Check Bundle Size
34+
run: npm run size

.github/workflows/publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
publish-npm:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-node@v3
13+
with:
14+
node-version: 14
15+
registry-url: https://registry.npmjs.org/
16+
cache: npm
17+
- run: npm ci
18+
- run: npm test
19+
- run: npm version ${TAG_NAME} --git-tag-version=false
20+
env:
21+
TAG_NAME: ${{ github.event.release.tag_name }}
22+
- run: npm whoami; npm --ignore-scripts publish
23+
env:
24+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @github/ui-frameworks-reviewers
1+
* @github/web-systems-reviewers

docs/_guide/patterns.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@ class FuzzySearchElement extends HTMLElement {
2929
}
3030
```
3131

32+
Alternatively, if you'd like more precise control over the exact way debouncing happens (for example you'd like to make the debounce timeout dynamic, or sometimes call _without_ debouncing), you can have two methods following the pattern of `foo`/`fooNow` or `foo`/`fooSync`, where the non-suffixed method dispatches asynchronously to the `Now`/`Sync` suffixed method, a little like this:
33+
34+
```typescript
35+
import {controller} from '@github/catalyst'
36+
37+
@controller
38+
class FuzzySearchElement extends HTMLElement {
39+
40+
#searchAnimationFrame = 0
41+
search(event: Event) {
42+
clearAnimationFrame(this.#searchAnimationFrame)
43+
this.#searchAnimationFrame = requestAnimationFrame(() => this.searchNow(event: Event))
44+
}
45+
46+
searchNow(event: Event) {
47+
const value = event.currentTarget.value
48+
// This function is very computationally intensive, so we should run it as little as possible
49+
this.filterAllItemsWithValue(value)
50+
}
51+
52+
}
53+
```
54+
3255
### Aborting Network Requests
3356

3457
When making network requests using `fetch`, based on user input, you can cancel old requests as new ones come in. This is useful for performance as well as UI responsiveness, as old requests that aren't cancelled might complete later than newer ones, and causing the UI to jump around. Aborting network requests requires you to use [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) (a web platform feature).
@@ -70,3 +93,37 @@ class RemoveSearchElement extends HTMLElement {
7093
}
7194
}
7295
```
96+
97+
### Registering global or many event listeners
98+
99+
Generally speaking, you'll want to use ["Actions"]({{ site.baseurl }}/guide/actions) to register event listeners with your Controller, but Actions only work for components nested within your Controller. It may also be necessary to listen for events on the Document, Window, or across well-known adjacent elements. We can manually call `addEventListener` for these types, including during the `connectedCallback` phase. Cleanup for `addEventListener` can be a bit error prone, but [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) can be useful here to pass a signal that the element is cleaning up. AbortControllers should be created once per `connectedCallback`, as they are not re-usable, while Controllers _can_ be reused.
100+
101+
102+
```typescript
103+
@controller
104+
class UnsavedChangesElement extends HTMLElement {
105+
106+
#eventAbortController: AbortController|null = null
107+
108+
connectedCallback(event: Event) {
109+
// Create the new AbortController and get the new signal
110+
const {signal} = (this.#eventAbortController = new AbortController())
111+
112+
// You can `signal` as an option to any `addEventListener` call:
113+
window.addEventListener('hashchange', this, { signal })
114+
window.addEventListener('blur', this, { signal })
115+
window.addEventListener('popstate', this, { signal })
116+
window.addEventListener('pagehide', this, { signal })
117+
}
118+
119+
disconnectedCallback() {
120+
// This will clean up any `addEventListener` calls which were given the `signal`
121+
this.#eventAbortController?.abort()
122+
}
123+
124+
handleEvent(event) {
125+
// `handleEvent` will be called when each one of the event listeners
126+
// defined in `connectedCallback` is dispatched.
127+
}
128+
}
129+
```

docs/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function storeColorSchemePreference() {
22
// Get color scheme preference from URL
3-
const url = new URL(window.location.href)
3+
const url = new URL(window.location.href, window.location.origin)
44
const params = new URLSearchParams(url.search)
55

66
// Return early if there’s nothing to store

0 commit comments

Comments
 (0)