Skip to content

Commit a1c93de

Browse files
committed
Merge branch 'master' of github.com:facing-dev/vue-facing-decorator
2 parents 4cfc5af + 671fe45 commit a1c93de

File tree

11 files changed

+116
-11
lines changed

11 files changed

+116
-11
lines changed

docs/pt-br/_sidebar.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
- [Observadores](/pt-br/class-component/watcher/watcher.md)
1313
- [Inject](/pt-br/class-component/injection/injection.md)
1414
- [Model](/pt-br/class-component/model/model.md)
15-
- [Use](/pt-br/class-component/use/use.md)
15+
- [Setup](/pt-br/class-component/setup/setup.md)
1616
- Herança
1717
- [Classes ECMAScript](/pt-br/inheritance/es-class/es-class.md)
1818
- [Componentes](/pt-br/inheritance/component/component.md)
1919
- [Exemplo complexo](/pt-br/inheritance/complex-example/complex-example.md)
2020
- TSX
2121
- [TSX render](/pt-br/tsx/tsx-render/tsx-render.md)
2222
- [Tipando Atributos](/pt-br/tsx/attribute-types/attribute-types.md)
23+
- Custom Decorator
24+
- [Custom Decorator](/pt-br/custom/custom.md)
2325
- Compatibilidade
2426
- [reflect-metadata](/pt-br/compatibility/reflect-metadata/reflect-metadata.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
import { Component, Vue } from 'vue-facing-decorator'
3+
4+
/*
5+
Vue options API
6+
{
7+
setup() {
8+
return { key: 'value' }
9+
}
10+
}
11+
*/
12+
13+
@Component({
14+
setup() {
15+
return { key: 'value' }
16+
}
17+
})
18+
export default class MyComponent extends Vue {
19+
key!: string
20+
}

docs/pt-br/class-component/component/component.md

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ Se você utiliza SFC ( Single File components ). O método render será aplicado
5858
5959
[](./code-option-render.ts ':include :type=code typescript')
6060

61+
### setup
62+
63+
Assim fica a propriedade `setup` do vue options API, mas não pode retornar uma função render.
64+
65+
[](./code-option-setup.ts ':include :type=code typescript')
66+
6167
### template
6268

6369
Assim fica a propriedade `template` do vue options API.

docs/pt-br/class-component/use/code-usage-base.ts renamed to docs/pt-br/class-component/setup/code-usage-base.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Component, Vue, Use } from 'vue-facing-decorator'
1+
import { Component, Vue, Setup } from 'vue-facing-decorator'
22
import { ref } from 'vue'
33
import { useRouter, Router } from 'vue-router'
44

55
@Component
66
class MyComponent extends Vue {
77

8-
@Use(useRouter)
8+
@Setup((props,ctx)=>useRouter())
99
router!: Router
1010

1111
mounted() {
@@ -16,7 +16,7 @@ class MyComponent extends Vue {
1616
@Component
1717
class MyComponent2 extends Vue {
1818

19-
@Use(() => ref('hello world'))
19+
@Setup(() => ref('hello world'))
2020
data!: string
2121

2222
mounted() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Utilização
2+
3+
Use o decorator `Setup` exportado de `'vue-facing-decorator'` para injetar [composables](https://vuejs.org/guide/reusability/composables.html) no seu class componente como uma propriedade.
4+
5+
[](./code-usage-base.ts ':include :type=code typescript')
6+
7+

docs/pt-br/class-component/use/use.md

-6
This file was deleted.

docs/pt-br/custom/code-usage.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { createDecorator, Component, Vue } from 'vue-facing-decorator'
2+
3+
function Log(prefix: string) {
4+
return createDecorator(function (options, key) {
5+
const old = options.methods?.[key]
6+
if (!old) {
7+
throw 'not found'
8+
}
9+
options.methods[key] = function (...args: any[]) {
10+
old.apply(this, args)
11+
}
12+
})
13+
}
14+
15+
@Component
16+
export default class Comp extends Vue {
17+
@Log('prefix')
18+
method() {
19+
20+
}
21+
}

docs/pt-br/custom/custom.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Utilização
2+
3+
Use `createDecorator` para construir seus próprios decorators.
4+
5+
Se você é um autor de algum package, instale vue-facing-decorator como `devDependecies` e marque-a dentro de `peerDependencies`.
6+
7+
8+
`createDecorator` recebe uma função criadora, a qual aceita dois parâmetros:
9+
10+
1. Componentes Vue gerados com options API, você pode modifica-lo para implementar o que você quiser.
11+
2. A key da propriedade da classe(ou método), o qual o decorator irá ser aplicado.
12+
13+
[](./code-usage.ts ':include :type=code typescript')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Component, ComponentBase, Vue, mixins } from 'vue-facing-decorator'
2+
3+
/*
4+
Vue options API
5+
{
6+
name:"MyComponent",
7+
extends:{
8+
mixins:[{
9+
name:'ComponentA'
10+
},{
11+
name:'ComponentB'
12+
}]
13+
}
14+
}
15+
*/
16+
@ComponentBase({
17+
name: "ComponentA"
18+
})
19+
class ComponentA extends Vue {
20+
21+
}
22+
23+
@ComponentBase({
24+
name: "ComponentB"
25+
})
26+
class ComponentB extends Vue {
27+
28+
}
29+
30+
@Component({
31+
name: "MyComponent"
32+
})
33+
export default class MyComponent extends mixins(ComponentA,ComponentB) {
34+
35+
}

docs/pt-br/inheritance/component/component.md

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ Considere o código:
1010

1111
Exitem dois componentes: `MyComponent` e `SuperComponent`. A herança é implementada pelo vue com `extends`.
1212

13+
## Estender múltiplos componentes
14+
15+
Use `mixins` para estender múltiplos componentes que utilizam o decorator `ComponentBase`.
16+
17+
[](./code-mixins-function.ts ':include :type=code typescript')
18+
19+
20+
1321
## Para componentes nativos
1422

1523
Use `mixins` para mesclar dois componentes nativos.

docs/pt-br/readme.md

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Sugestões e contribuições são bem-vindas.
2222

2323
# Doações
2424

25-
Doação
2625

2726
# Discussões
2827

0 commit comments

Comments
 (0)