patchProp.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { patchClass } from './modules/class'
  2. import { patchStyle } from './modules/style'
  3. import { patchAttr } from './modules/attrs'
  4. import { patchDOMProp } from './modules/props'
  5. import { patchEvent } from './modules/events'
  6. import { isOn } from '@vue/shared'
  7. import {
  8. ComponentInternalInstance,
  9. SuspenseBoundary,
  10. VNode
  11. } from '@vue/runtime-core'
  12. export function patchProp(
  13. el: Element,
  14. key: string,
  15. nextValue: any,
  16. prevValue: any,
  17. isSVG: boolean,
  18. prevChildren?: VNode[],
  19. parentComponent?: ComponentInternalInstance,
  20. parentSuspense?: SuspenseBoundary<Node, Element>,
  21. unmountChildren?: any
  22. ) {
  23. switch (key) {
  24. // special
  25. case 'class':
  26. patchClass(el, nextValue, isSVG)
  27. break
  28. case 'style':
  29. patchStyle(el, prevValue, nextValue)
  30. break
  31. case 'modelValue':
  32. case 'onUpdate:modelValue':
  33. // Do nothing. This is handled by v-model directives.
  34. break
  35. default:
  36. if (isOn(key)) {
  37. patchEvent(
  38. el,
  39. key.slice(2).toLowerCase(),
  40. prevValue,
  41. nextValue,
  42. parentComponent
  43. )
  44. } else if (!isSVG && key in el) {
  45. patchDOMProp(
  46. el,
  47. key,
  48. nextValue,
  49. prevChildren,
  50. parentComponent,
  51. parentSuspense,
  52. unmountChildren
  53. )
  54. } else {
  55. // special case for <input v-model type="checkbox"> with
  56. // :true-value & :false-value
  57. // store value as dom properties since non-string values will be
  58. // stringified.
  59. if (key === 'true-value') {
  60. ;(el as any)._trueValue = nextValue
  61. } else if (key === 'false-value') {
  62. ;(el as any)._falseValue = nextValue
  63. }
  64. patchAttr(el, key, nextValue)
  65. }
  66. break
  67. }
  68. }