refactor: move decorators into their own package
This commit is contained in:
2
packages/decorators/src/index.ts
Normal file
2
packages/decorators/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { prop } from './prop'
|
||||
export { inject } from './inject'
|
||||
1
packages/decorators/src/inject.ts
Normal file
1
packages/decorators/src/inject.ts
Normal file
@@ -0,0 +1 @@
|
||||
export function inject() {}
|
||||
23
packages/decorators/src/prop.ts
Normal file
23
packages/decorators/src/prop.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Component, PropValidator } from '@vue/runtime-core'
|
||||
import { camelize } from '@vue/shared'
|
||||
|
||||
export function prop(
|
||||
target: Component | PropValidator<any>,
|
||||
key?: string
|
||||
): any {
|
||||
if (key) {
|
||||
applyProp(target, key)
|
||||
} else {
|
||||
const options = target as PropValidator<any>
|
||||
return (target: any, key: string) => {
|
||||
applyProp(target, key, options)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function applyProp(target: any, key: string, options: PropValidator<any> = {}) {
|
||||
// here `target` is the prototype of the component class
|
||||
Object.defineProperty(target, `__prop_${camelize(key)}`, {
|
||||
value: options
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user