mirror of https://github.com/vuejs/core.git
wip: optimize props validation
This commit is contained in:
parent
fc9aa62248
commit
4baaa7bca3
|
@ -701,15 +701,16 @@ export function validateProps(
|
||||||
resolvedProps = toRaw(resolvedProps)
|
resolvedProps = toRaw(resolvedProps)
|
||||||
const camelizePropsKey = Object.keys(rawProps).map(key => camelize(key))
|
const camelizePropsKey = Object.keys(rawProps).map(key => camelize(key))
|
||||||
for (const key in options) {
|
for (const key in options) {
|
||||||
let opt = options[key]
|
const opt = options[key]
|
||||||
if (opt == null) continue
|
if (opt != null) {
|
||||||
validateProp(
|
validateProp(
|
||||||
key,
|
key,
|
||||||
resolvedProps[key],
|
resolvedProps[key],
|
||||||
opt,
|
opt,
|
||||||
__DEV__ ? shallowReadonly(resolvedProps) : resolvedProps,
|
resolvedProps,
|
||||||
!camelizePropsKey.includes(key),
|
!camelizePropsKey.includes(key),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,7 +751,10 @@ function validateProp(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// custom validator
|
// custom validator
|
||||||
if (validator && !validator(value, resolvedProps)) {
|
if (
|
||||||
|
validator &&
|
||||||
|
!validator(value, __DEV__ ? shallowReadonly(resolvedProps) : resolvedProps)
|
||||||
|
) {
|
||||||
warn('Invalid prop: custom validator check failed for prop "' + key + '".')
|
warn('Invalid prop: custom validator check failed for prop "' + key + '".')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,4 @@
|
||||||
import {
|
import { EMPTY_ARR, NO, YES, camelize, hasOwn, isFunction } from '@vue/shared'
|
||||||
EMPTY_ARR,
|
|
||||||
NO,
|
|
||||||
YES,
|
|
||||||
camelize,
|
|
||||||
extend,
|
|
||||||
hasOwn,
|
|
||||||
isFunction,
|
|
||||||
} from '@vue/shared'
|
|
||||||
import type { VaporComponent, VaporComponentInstance } from './component'
|
import type { VaporComponent, VaporComponentInstance } from './component'
|
||||||
import {
|
import {
|
||||||
type NormalizedPropsOptions,
|
type NormalizedPropsOptions,
|
||||||
|
@ -239,7 +231,12 @@ export function setupPropsValidation(instance: VaporComponentInstance): void {
|
||||||
const rawProps = instance.rawProps
|
const rawProps = instance.rawProps
|
||||||
if (!rawProps) return
|
if (!rawProps) return
|
||||||
renderEffect(() => {
|
renderEffect(() => {
|
||||||
const mergedRawProps = extend({}, rawProps)
|
const mergedRawProps: Record<string, any> = {}
|
||||||
|
for (const key in rawProps) {
|
||||||
|
if (key !== '$') {
|
||||||
|
mergedRawProps[key] = rawProps[key]()
|
||||||
|
}
|
||||||
|
}
|
||||||
if (rawProps.$) {
|
if (rawProps.$) {
|
||||||
for (const source of rawProps.$) {
|
for (const source of rawProps.$) {
|
||||||
const isDynamic = isFunction(source)
|
const isDynamic = isFunction(source)
|
||||||
|
|
Loading…
Reference in New Issue