Home / Function/ validateProp() — vue Function Reference

validateProp() — vue Function Reference

Architecture documentation for the validateProp() function in props.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  d99d7982_2691_1c11_3bae_459f2d25122d["validateProp()"]
  f2fe9306_50d5_675e_2dfa_2c4d78443a49["hasOwn()"]
  d99d7982_2691_1c11_3bae_459f2d25122d -->|calls| f2fe9306_50d5_675e_2dfa_2c4d78443a49
  625bda12_3309_28dd_7cf5_fa6ffe15bea0["getTypeIndex()"]
  d99d7982_2691_1c11_3bae_459f2d25122d -->|calls| 625bda12_3309_28dd_7cf5_fa6ffe15bea0
  e78b8b23_1803_b152_f10f_06b6c4015dc9["hyphenate()"]
  d99d7982_2691_1c11_3bae_459f2d25122d -->|calls| e78b8b23_1803_b152_f10f_06b6c4015dc9
  f17df5f9_8c05_1fd0_9b66_82a82a8be567["getPropDefaultValue()"]
  d99d7982_2691_1c11_3bae_459f2d25122d -->|calls| f17df5f9_8c05_1fd0_9b66_82a82a8be567
  604e5809_df6d_b3ac_e76f_cf1b5eeb9809["toggleObserving()"]
  d99d7982_2691_1c11_3bae_459f2d25122d -->|calls| 604e5809_df6d_b3ac_e76f_cf1b5eeb9809
  38718d0e_50b6_f32c_7ce6_c7fe083f1ba2["observe()"]
  d99d7982_2691_1c11_3bae_459f2d25122d -->|calls| 38718d0e_50b6_f32c_7ce6_c7fe083f1ba2
  87f7db47_5b28_fa14_0778_0d908fd6f104["assertProp()"]
  d99d7982_2691_1c11_3bae_459f2d25122d -->|calls| 87f7db47_5b28_fa14_0778_0d908fd6f104
  style d99d7982_2691_1c11_3bae_459f2d25122d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/core/util/props.ts lines 22–59

export function validateProp(
  key: string,
  propOptions: Object,
  propsData: Object,
  vm?: Component
): any {
  const prop = propOptions[key]
  const absent = !hasOwn(propsData, key)
  let value = propsData[key]
  // boolean casting
  const booleanIndex = getTypeIndex(Boolean, prop.type)
  if (booleanIndex > -1) {
    if (absent && !hasOwn(prop, 'default')) {
      value = false
    } else if (value === '' || value === hyphenate(key)) {
      // only cast empty string / same name to boolean if
      // boolean has higher priority
      const stringIndex = getTypeIndex(String, prop.type)
      if (stringIndex < 0 || booleanIndex < stringIndex) {
        value = true
      }
    }
  }
  // check default value
  if (value === undefined) {
    value = getPropDefaultValue(vm, prop, key)
    // since the default value is a fresh copy,
    // make sure to observe it.
    const prevShouldObserve = shouldObserve
    toggleObserving(true)
    observe(value)
    toggleObserving(prevShouldObserve)
  }
  if (__DEV__) {
    assertProp(prop, key, value, vm, absent)
  }
  return value
}

Domain

Subdomains

Frequently Asked Questions

What does validateProp() do?
validateProp() is a function in the vue codebase.
What does validateProp() call?
validateProp() calls 7 function(s): assertProp, getPropDefaultValue, getTypeIndex, hasOwn, hyphenate, observe, toggleObserving.

Analyze Your Own Codebase

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

Try Supermodel Free