MCPcopy
hub / github.com/vuejs/core / patchProp

Function patchProp

packages/runtime-dom/src/patchProp.ts:25–82  ·  view source on GitHub ↗
(
  el,
  key,
  prevValue,
  nextValue,
  namespace,
  parentComponent,
)

Source from the content-addressed store, hash-verified

23type DOMRendererOptions = RendererOptions<Node, Element>
24
25export const patchProp: DOMRendererOptions['patchProp'] = (
26 el,
27 key,
28 prevValue,
29 nextValue,
30 namespace,
31 parentComponent,
32) => {
33 const isSVG = namespace === 'svg'
34 if (key === 'class') {
35 patchClass(el, nextValue, isSVG)
36 } else if (key === 'style') {
37 patchStyle(el, prevValue, nextValue)
38 } else if (isOn(key)) {
39 // ignore v-model listeners
40 if (!isModelListener(key)) {
41 patchEvent(el, key, prevValue, nextValue, parentComponent)
42 }
43 } else if (
44 key[0] === '.'
45 ? ((key = key.slice(1)), true)
46 : key[0] === '^'
47 ? ((key = key.slice(1)), false)
48 : shouldSetAsProp(el, key, nextValue, isSVG)
49 ) {
50 patchDOMProp(el, key, nextValue, parentComponent)
51 // #6007 also set form state as attributes so they work with
52 // <input type="reset"> or libs / extensions that expect attributes
53 // #11163 custom elements may use value as an prop and set it as object
54 if (
55 !el.tagName.includes('-') &&
56 (key === 'value' || key === 'checked' || key === 'selected')
57 ) {
58 patchAttr(el, key, nextValue, isSVG, parentComponent, key !== 'value')
59 }
60 } else if (
61 // #11081 force set props for possible async custom element
62 (el as VueElement)._isVueCE &&
63 // #12408 check if it's declared prop or it's async custom element
64 (shouldSetAsPropForVueCE(el as VueElement, key) ||
65 // @ts-expect-error _def is private
66 ((el as VueElement)._def.__asyncLoader &&
67 (/[A-Z]/.test(key) || !isString(nextValue))))
68 ) {
69 patchDOMProp(el, camelize(key), nextValue, parentComponent, key)
70 } else {
71 // special case for <input v-model type="checkbox"> with
72 // :true-value & :false-value
73 // store value as dom properties since non-string values will be
74 // stringified.
75 if (key === 'true-value') {
76 ;(el as any)._trueValue = nextValue
77 } else if (key === 'false-value') {
78 ;(el as any)._falseValue = nextValue
79 }
80 patchAttr(el, key, nextValue, isSVG, parentComponent)
81 }
82}

Callers 6

patchClass.spec.tsFile · 0.90
patchStyle.spec.tsFile · 0.90
patchAttrs.spec.tsFile · 0.90
patchProps.spec.tsFile · 0.90
hydrateElementFunction · 0.50

Calls 11

patchClassFunction · 0.90
patchStyleFunction · 0.90
isOnFunction · 0.90
isModelListenerFunction · 0.90
patchEventFunction · 0.90
patchDOMPropFunction · 0.90
patchAttrFunction · 0.90
isStringFunction · 0.90
shouldSetAsPropFunction · 0.85
shouldSetAsPropForVueCEFunction · 0.85
testMethod · 0.80

Tested by

no test coverage detected