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

Function trigger

packages/reactivity/src/dep.ts:294–389  ·  view source on GitHub ↗
(
  target: object,
  type: TriggerOpTypes,
  key?: unknown,
  newValue?: unknown,
  oldValue?: unknown,
  oldTarget?: Map<unknown, unknown> | Set<unknown>,
)

Source from the content-addressed store, hash-verified

292 * @param key - Can be used to target a specific reactive property in the target object.
293 */
294export function trigger(
295 target: object,
296 type: TriggerOpTypes,
297 key?: unknown,
298 newValue?: unknown,
299 oldValue?: unknown,
300 oldTarget?: Map<unknown, unknown> | Set<unknown>,
301): void {
302 const depsMap = targetMap.get(target)
303 if (!depsMap) {
304 // never been tracked
305 globalVersion++
306 return
307 }
308
309 const run = (dep: Dep | undefined) => {
310 if (dep) {
311 if (__DEV__) {
312 dep.trigger({
313 target,
314 type,
315 key,
316 newValue,
317 oldValue,
318 oldTarget,
319 })
320 } else {
321 dep.trigger()
322 }
323 }
324 }
325
326 startBatch()
327
328 if (type === TriggerOpTypes.CLEAR) {
329 // collection being cleared
330 // trigger all effects for target
331 depsMap.forEach(run)
332 } else {
333 const targetIsArray = isArray(target)
334 const isArrayIndex = targetIsArray && isIntegerKey(key)
335
336 if (targetIsArray && key === 'length') {
337 const newLength = Number(newValue)
338 depsMap.forEach((dep, key) => {
339 if (
340 key === 'length' ||
341 key === ARRAY_ITERATE_KEY ||
342 (!isSymbol(key) && key >= newLength)
343 ) {
344 run(dep)
345 }
346 })
347 } else {
348 // schedule runs for SET | ADD | DELETE
349 if (key !== void 0 || depsMap.has(void 0)) {
350 run(depsMap.get(key))
351 }

Callers 13

addFunction · 0.90
setFunction · 0.90
deleteFunction · 0.90
clearFunction · 0.90
setMethod · 0.90
deletePropertyMethod · 0.90
updateSlotsFunction · 0.90
updatePropsFunction · 0.90
setFunction · 0.90
setFunction · 0.85
useModelFunction · 0.85
setFunction · 0.85

Calls 9

startBatchFunction · 0.90
isIntegerKeyFunction · 0.90
isSymbolFunction · 0.90
isMapFunction · 0.90
endBatchFunction · 0.90
forEachMethod · 0.80
hasMethod · 0.80
runFunction · 0.70
getMethod · 0.45

Tested by 1

setFunction · 0.68