patchData.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { VNode } from '@vue/core'
  2. import { patchClass } from './modules/class'
  3. import { patchStyle } from './modules/style'
  4. import { patchAttr } from './modules/attrs'
  5. import { patchDOMProp } from './modules/props'
  6. import { patchEvent } from './modules/events'
  7. export const onRE = /^on/
  8. const domPropsRE = /^domProps/
  9. export function patchData(
  10. el: Element,
  11. key: string,
  12. prevValue: any,
  13. nextValue: any,
  14. prevVNode: VNode,
  15. nextVNode: VNode,
  16. isSVG: boolean,
  17. unmountChildren: any
  18. ) {
  19. switch (key) {
  20. // special
  21. case 'class':
  22. patchClass(el, nextValue, isSVG)
  23. break
  24. case 'style':
  25. patchStyle(el, prevValue, nextValue, nextVNode.data)
  26. break
  27. default:
  28. if (onRE.test(key)) {
  29. patchEvent(el, key.toLowerCase().slice(2), prevValue, nextValue)
  30. } else if (domPropsRE.test(key)) {
  31. patchDOMProp(
  32. el,
  33. key[8].toLowerCase() + key.slice(9),
  34. nextValue,
  35. prevVNode,
  36. unmountChildren
  37. )
  38. } else {
  39. patchAttr(el, key, nextValue, isSVG)
  40. }
  41. break
  42. }
  43. }