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

Function updateProps

packages/runtime-core/src/componentProps.ts:241–373  ·  view source on GitHub ↗
(
  instance: ComponentInternalInstance,
  rawProps: Data | null,
  rawPrevProps: Data | null,
  optimized: boolean,
)

Source from the content-addressed store, hash-verified

239}
240
241export function updateProps(
242 instance: ComponentInternalInstance,
243 rawProps: Data | null,
244 rawPrevProps: Data | null,
245 optimized: boolean,
246): void {
247 const {
248 props,
249 attrs,
250 vnode: { patchFlag },
251 } = instance
252 const rawCurrentProps = toRaw(props)
253 const [options] = instance.propsOptions
254 let hasAttrsChanged = false
255
256 if (
257 // always force full diff in dev
258 // - #1942 if hmr is enabled with sfc component
259 // - vite#872 non-sfc component used by sfc component
260 !(__DEV__ && isInHmrContext(instance)) &&
261 (optimized || patchFlag > 0) &&
262 !(patchFlag & PatchFlags.FULL_PROPS)
263 ) {
264 if (patchFlag & PatchFlags.PROPS) {
265 // Compiler-generated props & no keys change, just set the updated
266 // the props.
267 const propsToUpdate = instance.vnode.dynamicProps!
268 for (let i = 0; i < propsToUpdate.length; i++) {
269 let key = propsToUpdate[i]
270 // skip if the prop key is a declared emit event listener
271 if (isEmitListener(instance.emitsOptions, key)) {
272 continue
273 }
274 // PROPS flag guarantees rawProps to be non-null
275 const value = rawProps![key]
276 if (options) {
277 // attr / props separation was done on init and will be consistent
278 // in this code path, so just check if attrs have it.
279 if (hasOwn(attrs, key)) {
280 if (value !== attrs[key]) {
281 attrs[key] = value
282 hasAttrsChanged = true
283 }
284 } else {
285 const camelizedKey = camelize(key)
286 props[camelizedKey] = resolvePropValue(
287 options,
288 rawCurrentProps,
289 camelizedKey,
290 value,
291 instance,
292 false /* isAbsent */,
293 )
294 }
295 } else {
296 if (__COMPAT__) {
297 if (isOn(key) && key.endsWith('Native')) {
298 key = key.slice(0, -6) // remove Native postfix

Callers 1

updateComponentPreRenderFunction · 0.90

Calls 10

toRawFunction · 0.90
isEmitListenerFunction · 0.90
hasOwnFunction · 0.90
isOnFunction · 0.90
shouldSkipAttrFunction · 0.90
triggerFunction · 0.90
isInHmrContextFunction · 0.85
resolvePropValueFunction · 0.85
setFullPropsFunction · 0.85
validatePropsFunction · 0.85

Tested by

no test coverage detected