Home / Function/ set() — vue Function Reference

set() — vue Function Reference

Architecture documentation for the set() function in index.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  f3ed2d67_a40e_608d_185e_32b185fb8046["set()"]
  41335b20_70f9_2989_a478_f3e623afbc9a["mergeData()"]
  41335b20_70f9_2989_a478_f3e623afbc9a -->|calls| f3ed2d67_a40e_608d_185e_32b185fb8046
  61d0e216_bbe6_fde1_d695_6f4a6a923f3b["customRef()"]
  61d0e216_bbe6_fde1_d695_6f4a6a923f3b -->|calls| f3ed2d67_a40e_608d_185e_32b185fb8046
  8d0e2195_5d6b_3567_6ef9_1a9c6d6caf20["observe()"]
  f3ed2d67_a40e_608d_185e_32b185fb8046 -->|calls| 8d0e2195_5d6b_3567_6ef9_1a9c6d6caf20
  558ee358_0776_b0dd_fc5b_6c8f87e1a04e["defineReactive()"]
  f3ed2d67_a40e_608d_185e_32b185fb8046 -->|calls| 558ee358_0776_b0dd_fc5b_6c8f87e1a04e
  a736e9c3_51fa_4ff8_f139_f83b45794e0f["notify()"]
  f3ed2d67_a40e_608d_185e_32b185fb8046 -->|calls| a736e9c3_51fa_4ff8_f139_f83b45794e0f
  style f3ed2d67_a40e_608d_185e_32b185fb8046 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/core/observer/index.ts lines 223–276

export function set(
  target: any[] | Record<string, any>,
  key: any,
  val: any
): any {
  if (__DEV__ && (isUndef(target) || isPrimitive(target))) {
    warn(
      `Cannot set reactive property on undefined, null, or primitive value: ${target}`
    )
  }
  if (isReadonly(target)) {
    __DEV__ && warn(`Set operation on key "${key}" failed: target is readonly.`)
    return
  }
  const ob = (target as any).__ob__
  if (isArray(target) && isValidArrayIndex(key)) {
    target.length = Math.max(target.length, key)
    target.splice(key, 1, val)
    // when mocking for SSR, array methods are not hijacked
    if (ob && !ob.shallow && ob.mock) {
      observe(val, false, true)
    }
    return val
  }
  if (key in target && !(key in Object.prototype)) {
    target[key] = val
    return val
  }
  if ((target as any)._isVue || (ob && ob.vmCount)) {
    __DEV__ &&
      warn(
        'Avoid adding reactive properties to a Vue instance or its root $data ' +
          'at runtime - declare it upfront in the data option.'
      )
    return val
  }
  if (!ob) {
    target[key] = val
    return val
  }
  defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock)
  if (__DEV__) {
    ob.dep.notify({
      type: TriggerOpTypes.ADD,
      target: target,
      key,
      newValue: val,
      oldValue: undefined
    })
  } else {
    ob.dep.notify()
  }
  return val
}

Domain

Subdomains

Frequently Asked Questions

What does set() do?
set() is a function in the vue codebase.
What does set() call?
set() calls 3 function(s): defineReactive, notify, observe.
What calls set()?
set() is called by 2 function(s): customRef, mergeData.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free