refactor: move prop decorator into core, expose initial props to initialziers
This commit is contained in:
24
packages/runtime-core/src/optional/propDecorator.ts
Normal file
24
packages/runtime-core/src/optional/propDecorator.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Component } from '../component'
|
||||
import { PropValidator } from '../componentOptions'
|
||||
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