vue3-yuanma/packages/runtime-dom/src/patchData.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-10-26 19:44:50 +00:00
import { VNode } from '@vue/runtime-core'
2018-09-19 15:35:38 +00:00
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'
2018-10-17 16:20:54 +00:00
import { isOn } from '@vue/shared'
2018-10-12 23:49:41 +00:00
// value, checked, selected & muted
// plus anything with upperCase letter in it are always patched as properties
const domPropsRE = /\W|^(?:value|checked|selected|muted)$/
2018-11-02 21:31:54 +00:00
const domPropsReplaceRE = /^domProps/
2018-09-19 15:35:38 +00:00
export function patchData(
el: Element,
key: string,
prevValue: any,
nextValue: any,
prevVNode: VNode,
nextVNode: VNode,
isSVG: boolean,
unmountChildren: any
) {
switch (key) {
// special
case 'class':
patchClass(el, nextValue, isSVG)
break
case 'style':
patchStyle(el, prevValue, nextValue, nextVNode.data)
break
default:
2018-10-17 16:20:54 +00:00
if (isOn(key)) {
patchEvent(el, key.slice(2).toLowerCase(), prevValue, nextValue)
} else if (domPropsRE.test(key)) {
2018-09-19 15:35:38 +00:00
patchDOMProp(
el,
2018-11-02 21:31:54 +00:00
key.replace(domPropsReplaceRE, '').toLowerCase(),
2018-09-19 15:35:38 +00:00
nextValue,
prevVNode,
unmountChildren
)
} else {
patchAttr(el, key, nextValue, isSVG)
}
break
}
}