Skip to content

Commit 0b42081

Browse files
author
brendon silva
committed
docs-pr-br: createDecorator
1 parent d43ab9b commit 0b42081

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

docs/pt-br/_sidebar.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@
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)

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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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')

0 commit comments

Comments
 (0)