thunderous 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -44
- package/package.json +1 -1
package/README.md
CHANGED
@@ -59,35 +59,11 @@ MyElement.define('my-element');
|
|
59
59
|
|
60
60
|
### The Native Features
|
61
61
|
|
62
|
-
Everything the native class definition can do, this can do too. You'll find that these things are not far removed from the native approach, so they ought to be familiar.
|
63
|
-
|
64
|
-
#### Defining Custom Elements
|
65
|
-
|
66
|
-
The `customElement` function allows you to author the web component with the render function and it returns an `ElementResult` that has some helpful methods like `define()` and `eject()`.
|
67
|
-
|
68
|
-
- `ElementResult.define()` is a little safer than `customElements.define()` because it first checks if the component was already defined, without throwing an error. It will, however, log a warning. There's no need to pass the class since it already has that context.
|
69
|
-
|
70
|
-
```ts
|
71
|
-
const MyElement = customElement(() => html`<slot></slot>`);
|
72
|
-
|
73
|
-
MyElement.define('my-element');
|
74
|
-
```
|
75
|
-
|
76
|
-
- `ElementResult.eject()` is useful in case you need to access the underlying class for some reason; perhaps you want to extend it and/or set static properties.
|
77
|
-
|
78
|
-
```ts
|
79
|
-
const MyElementClass = MyElement.eject();
|
80
|
-
|
81
|
-
class MyOtherElement extends MyElementClass {
|
82
|
-
/* ... */
|
83
|
-
}
|
84
|
-
```
|
85
|
-
|
86
|
-
These may also be chained together, like `MyElement.define('my-element').eject()`.
|
62
|
+
Everything the native class definition can do, this function can do too. You'll find that these things are not far removed from the native approach, so they ought to be familiar.
|
87
63
|
|
88
64
|
#### Lifecycle Methods
|
89
65
|
|
90
|
-
Any lifecycle method you may need can be accessed from the params of your render function. The only difference is that these are callback registrations, so the same callback you would normally write is just passed in.
|
66
|
+
Any lifecycle method you may need can be accessed from the params of your render function. The only difference is that these are callback registrations, so the same callback you would normally write is just passed in instead.
|
91
67
|
|
92
68
|
<!-- prettier-ignore-start -->
|
93
69
|
```ts
|
@@ -120,24 +96,6 @@ const MyElement = customElement((params) => {
|
|
120
96
|
```
|
121
97
|
<!-- prettier-ignore-end -->
|
122
98
|
|
123
|
-
#### Element Internals
|
124
|
-
|
125
|
-
You can always define the internals the same as you usually would.
|
126
|
-
|
127
|
-
<!-- prettier-ignore-start -->
|
128
|
-
```ts
|
129
|
-
const MyElement = customElement((params) => {
|
130
|
-
const {
|
131
|
-
internals,
|
132
|
-
} = params;
|
133
|
-
|
134
|
-
internals.ariaRequired = 'true';
|
135
|
-
|
136
|
-
/* ... */
|
137
|
-
}, { formAssociated: true });
|
138
|
-
```
|
139
|
-
<!-- prettier-ignore-end -->
|
140
|
-
|
141
99
|
#### Roots and Element Internals
|
142
100
|
|
143
101
|
You can always define the internals the same as you usually would, and if for some reason you need access to either the element itself or the shadow root, you can do so as illustrated below.
|
@@ -292,6 +250,30 @@ MyElement.define('my-element');
|
|
292
250
|
```
|
293
251
|
<!-- prettier-ignore-end -->
|
294
252
|
|
253
|
+
### Defining Custom Elements
|
254
|
+
|
255
|
+
The `customElement()` function allows you to author a web component, returning an `ElementResult` that has some helpful methods like `define()` and `eject()`.
|
256
|
+
|
257
|
+
- `ElementResult.define()` is a little safer than `customElements.define()` because it first checks if the component was already defined, without throwing an error. It will, however, log a warning. There's no need to pass the class since it already has that context.
|
258
|
+
|
259
|
+
```ts
|
260
|
+
const MyElement = customElement(() => html`<slot></slot>`);
|
261
|
+
|
262
|
+
MyElement.define('my-element');
|
263
|
+
```
|
264
|
+
|
265
|
+
- `ElementResult.eject()` is useful in case you need to access the underlying class for some reason; perhaps you want to extend it and/or set static properties.
|
266
|
+
|
267
|
+
```ts
|
268
|
+
const MyElementClass = MyElement.eject();
|
269
|
+
|
270
|
+
class MyOtherElement extends MyElementClass {
|
271
|
+
/* ... */
|
272
|
+
}
|
273
|
+
```
|
274
|
+
|
275
|
+
These may also be chained together, like `MyElement.define('my-element').eject()`.
|
276
|
+
|
295
277
|
## Contributing
|
296
278
|
|
297
279
|
### Local Server
|