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
Copy file name to clipboardExpand all lines: docs/_guide/create-ability.md
+14-2Lines changed: 14 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ This function allows you to make your own [Ability]({{ site.baseurl }}/guide/abi
21
21
22
22
The above three features of `createAbility` make it really useful when creating mixins for web components, and makes them much easier for developers as they can trust an ability to not be sensitive to these problems.
23
23
24
-
To create an ability, call the `createAbility` method and pass in a callback function which takes a `CustomElementClass` and returns a new class. You can also provide extra types if your returned class requires them. Here's an example, using TypeScript:
24
+
To create an ability, call the `createAbility` method and pass in a callback function which takes a `CustomElementClass` and returns a new class. You can also provide extra types if your returned class adds new methods or fields. Here's an example, using TypeScript:
25
25
26
26
27
27
```typescript
@@ -35,6 +35,7 @@ interface Fooable {
35
35
36
36
// Fooable: automatically calls `foo()` on `connectedCallback`
37
37
exportconst fooable =createAbility(
38
+
// ↓ Notice the `& { new (): Fooable }`
38
39
<TextendsCustomElementClass>(Class:T):T& { new ():Fooable } =>
Inside the `class extends Class` block, you can author custom element logic that you might want to make reusable across a multitude of elements. You can also adjust the input type to subclass `CustomElementClass`, which can be useful for setting up a contract between your Ability and the classes that rely on it:
@@ -58,10 +60,20 @@ interface Fooable {
58
60
foo():void// This interface has additional methods on top of `CustomElementClass`!
59
61
}
60
62
63
+
interfaceFooableClass {
64
+
new(...args:any[]):Fooable
65
+
}
66
+
61
67
// Fooable: automatically calls `foo()` on `connectedCallback`
62
68
exportconst fooable =createAbility(
63
-
<TextendsCustomElementClass& { new ():Fooable }>(Class:T):T=>
0 commit comments