2018-09-19 15:35:38 +00:00
|
|
|
import { VNode } from '@vue/core'
|
|
|
|
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-10 01:10:30 +00:00
|
|
|
export const onRE = /^on/
|
2018-10-12 21:42:08 +00:00
|
|
|
|
|
|
|
// value, checked, selected & muted are always patched as properties
|
|
|
|
const domPropsRE = /^domProps|^(?:value|checked|selected|muted)$/
|
2018-09-25 16:06:19 +00:00
|
|
|
|
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-09-25 16:06:19 +00:00
|
|
|
if (onRE.test(key)) {
|
2018-10-04 20:10:46 +00:00
|
|
|
patchEvent(
|
|
|
|
el,
|
|
|
|
key.replace(onRE, '').toLowerCase(),
|
|
|
|
prevValue,
|
|
|
|
nextValue
|
|
|
|
)
|
2018-09-25 16:06:19 +00:00
|
|
|
} else if (domPropsRE.test(key)) {
|
2018-09-19 15:35:38 +00:00
|
|
|
patchDOMProp(
|
|
|
|
el,
|
|
|
|
key[8].toLowerCase() + key.slice(9),
|
|
|
|
nextValue,
|
|
|
|
prevVNode,
|
|
|
|
unmountChildren
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
patchAttr(el, key, nextValue, isSVG)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|