Skip to content

Commit 533edc7

Browse files
committed
2.1.0 tsx attribute types, in class render
1 parent 6e56bdd commit 533edc7

File tree

18 files changed

+134
-14
lines changed

18 files changed

+134
-14
lines changed

docs/_sidebar.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
- Inheritance
1616
- [ECMAScript class](inheritance/es-class/es-class.md)
1717
- [Component](inheritance/component/component.md)
18-
- [Complex example](inheritance/complex-example/complex-example.md)
18+
- [Complex example](inheritance/complex-example/complex-example.md)
19+
- TSX
20+
- [Attribute types](tsx/attribute-types/attribute-types.md)

docs/class-component/component-property/code-option-type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ export default class MyComponent extends Vue {
1818
@Prop({
1919
type: String
2020
})
21-
p!: string
21+
p?: string
2222
}

docs/class-component/component-property/code-option-validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ export default class MyComponent extends Vue {
2222
return true
2323
}
2424
})
25-
p!: string
25+
p?: string
2626
}

docs/class-component/component-property/code-usage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Vue option component
1616
@Component
1717
export default class MyComponent extends Vue {
1818
@Prop
19-
p!: string
19+
p?: string
2020
}

docs/class-component/component/component.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ This is the `render` in vue option component api.
5454

5555
If you use vue Single-File component. The render will be applied to the `export default` component automatically.
5656

57+
> This will overwrite the render in class body.
58+
5759
[](./code-option-template.ts ':include :type=code typescript')
5860

5961
### template

docs/class-component/event/event.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Usage
22

3-
You could define a method which triggers a vue event by `Emit` decorator.
3+
We could define a method which triggers a vue event by `Emit` decorator.
44

55
The decorator received an optional event name paramater. Event will be triggered with this name and the method returned value. If the event name parameter is omitted, use method's name by default.
66

docs/class-component/lifecycle-hook/lifecycle-hook.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ Class component supports almost all lifecycle hooks in vanilla vue. Write then a
2323
"renderTracked",
2424
"renderTriggered",
2525
"errorCaptured",
26-
"serverPrefetch"
26+
"serverPrefetch",
27+
"render"
2728
]
2829
```
2930

31+
All these hooks must be methods of a class, not properties.
32+
3033
## For other names
3134

3235
If your hook names aren't in the above list. You could use `options` or `modifier` in `Component` decorator.

docs/class-component/method/method.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Usage
22

3-
In a class component, you could define methods of vue option component as class methods directly. Library will analyze methods and transform them into `methods` option.
3+
In a class component, we could define methods of vue option component as class methods directly. Library will analyze methods and transform them into `methods` option.
44

55
[](./code-usage.ts ':include :type=code typescript')

docs/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
},
3030
"include": [
3131
"./**/*.ts",
32+
"./**/*.tsx",
3233
],
3334
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Usage
2+
3+
To make enable TSX attribute types:
4+
5+
1. Import `TSX` function from this repo.
6+
7+
2. Define an interface(i.e. `Props`) to decribe properties in component.
8+
9+
3. Make your component extend from `TSX<Props>()(BaseComponent)`.
10+
11+
> There are two `()`s after `TSX<Props>`.
12+
13+
[](./code-usage.tsx ':include :type=code tsx')
14+
15+
## Type checking
16+
17+
We could check if component implements properties by `implements`.
18+
19+
[](./code-type-checking.tsx ':include :type=code tsx')
20+
21+
## Component inheritance
22+
23+
TSX attributes supports component inheritance.
24+
25+
[](./code-component-inheritance.tsx ':include :type=code tsx')
26+
27+
28+

0 commit comments

Comments
 (0)