mirror of https://github.com/vuejs/core.git
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { patchClass } from './modules/class'
|
|
import { patchStyle } from './modules/style'
|
|
import { patchAttr } from './modules/attrs'
|
|
import { patchDOMProp } from './modules/props'
|
|
import { patchEvent } from './modules/events'
|
|
import { isOn, isString } from '@vue/shared'
|
|
import { RendererOptions } from '@vue/runtime-core'
|
|
|
|
const nativeOnRE = /^on[a-z]/
|
|
|
|
export const patchProp: RendererOptions<Node, Element>['patchProp'] = (
|
|
el,
|
|
key,
|
|
prevValue,
|
|
nextValue,
|
|
isSVG = false,
|
|
prevChildren,
|
|
parentComponent,
|
|
parentSuspense,
|
|
unmountChildren
|
|
) => {
|
|
switch (key) {
|
|
// special
|
|
case 'class':
|
|
patchClass(el, nextValue, isSVG)
|
|
break
|
|
case 'style':
|
|
patchStyle(el, prevValue, nextValue)
|
|
break
|
|
default:
|
|
if (isOn(key)) {
|
|
// ignore v-model listeners
|
|
if (key.indexOf('onUpdate:') < 0) {
|
|
patchEvent(el, key, prevValue, nextValue, parentComponent)
|
|
}
|
|
} else if (
|
|
!isSVG &&
|
|
key in el &&
|
|
// onclick="foo" needs to be set as an attribute to work
|
|
!(nativeOnRE.test(key) && isString(nextValue))
|
|
) {
|
|
patchDOMProp(
|
|
el,
|
|
key,
|
|
nextValue,
|
|
prevChildren,
|
|
parentComponent,
|
|
parentSuspense,
|
|
unmountChildren
|
|
)
|
|
} else {
|
|
// special case for <input v-model type="checkbox"> with
|
|
// :true-value & :false-value
|
|
// store value as dom properties since non-string values will be
|
|
// stringified.
|
|
if (key === 'true-value') {
|
|
;(el as any)._trueValue = nextValue
|
|
} else if (key === 'false-value') {
|
|
;(el as any)._falseValue = nextValue
|
|
}
|
|
patchAttr(el, key, nextValue, isSVG)
|
|
}
|
|
break
|
|
}
|
|
}
|