Home / Function/ initComputed() — vue Function Reference

initComputed() — vue Function Reference

Architecture documentation for the initComputed() function in state.ts from the vue codebase.

Function typescript CoreInstance VDOM calls 1 called by 2

Entity Profile

Dependency Diagram

graph TD
  c4c9a03b_1660_44a3_39d7_280f159fba8d["initComputed()"]
  13d1baef_6bea_6a9a_dcef_508dfa47a6ca["initComputed()"]
  13d1baef_6bea_6a9a_dcef_508dfa47a6ca -->|calls| c4c9a03b_1660_44a3_39d7_280f159fba8d
  7d6ab8ef_bd4c_49b2_1b21_a805de50af72["initState()"]
  7d6ab8ef_bd4c_49b2_1b21_a805de50af72 -->|calls| c4c9a03b_1660_44a3_39d7_280f159fba8d
  4b445b08_139d_b6b4_0861_2120f0449ae2["defineComputed()"]
  c4c9a03b_1660_44a3_39d7_280f159fba8d -->|calls| 4b445b08_139d_b6b4_0861_2120f0449ae2
  style c4c9a03b_1660_44a3_39d7_280f159fba8d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/core/instance/state.ts lines 183–224

function initComputed(vm: Component, computed: Object) {
  // $flow-disable-line
  const watchers = (vm._computedWatchers = Object.create(null))
  // computed properties are just getters during SSR
  const isSSR = isServerRendering()

  for (const key in computed) {
    const userDef = computed[key]
    const getter = isFunction(userDef) ? userDef : userDef.get
    if (__DEV__ && getter == null) {
      warn(`Getter is missing for computed property "${key}".`, vm)
    }

    if (!isSSR) {
      // create internal watcher for the computed property.
      watchers[key] = new Watcher(
        vm,
        getter || noop,
        noop,
        computedWatcherOptions
      )
    }

    // component-defined computed properties are already defined on the
    // component prototype. We only need to define computed properties defined
    // at instantiation here.
    if (!(key in vm)) {
      defineComputed(vm, key, userDef)
    } else if (__DEV__) {
      if (key in vm.$data) {
        warn(`The computed property "${key}" is already defined in data.`, vm)
      } else if (vm.$options.props && key in vm.$options.props) {
        warn(`The computed property "${key}" is already defined as a prop.`, vm)
      } else if (vm.$options.methods && key in vm.$options.methods) {
        warn(
          `The computed property "${key}" is already defined as a method.`,
          vm
        )
      }
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does initComputed() do?
initComputed() is a function in the vue codebase.
What does initComputed() call?
initComputed() calls 1 function(s): defineComputed.
What calls initComputed()?
initComputed() is called by 2 function(s): initComputed, initState.

Analyze Your Own Codebase

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

Try Supermodel Free