Home / File/ attrs.ts — vue Source File

attrs.ts — vue Source File

Architecture documentation for attrs.ts, a typescript file in the vue codebase. 4 imports, 1 dependents.

File typescript WebPlatform WebRuntime 4 imports 1 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  79ac8337_fd93_af91_1c63_9d155d74dbf5["attrs.ts"]
  1ec7e50f_8f20_0656_28f0_45cecc26cf74["env"]
  79ac8337_fd93_af91_1c63_9d155d74dbf5 --> 1ec7e50f_8f20_0656_28f0_45cecc26cf74
  09aa5370_2caa_6b33_3f44_6ac5211bd11b["util"]
  79ac8337_fd93_af91_1c63_9d155d74dbf5 --> 09aa5370_2caa_6b33_3f44_6ac5211bd11b
  ba925ef2_b0f4_efe3_c23d_fe293c46b2c1["vnode"]
  79ac8337_fd93_af91_1c63_9d155d74dbf5 --> ba925ef2_b0f4_efe3_c23d_fe293c46b2c1
  28507de2_df66_4d38_8b45_3af459d16f77["index"]
  79ac8337_fd93_af91_1c63_9d155d74dbf5 --> 28507de2_df66_4d38_8b45_3af459d16f77
  7973a695_d0db_6940_134b_f6ff953b9e97["index.ts"]
  7973a695_d0db_6940_134b_f6ff953b9e97 --> 79ac8337_fd93_af91_1c63_9d155d74dbf5
  style 79ac8337_fd93_af91_1c63_9d155d74dbf5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { isIE, isIE9, isEdge } from 'core/util/env'

import { extend, isDef, isUndef, isTrue } from 'shared/util'
import type { VNodeWithData } from 'types/vnode'

import {
  isXlink,
  xlinkNS,
  getXlinkProp,
  isBooleanAttr,
  isEnumeratedAttr,
  isFalsyAttrValue,
  convertEnumeratedValue
} from 'web/util/index'

function updateAttrs(oldVnode: VNodeWithData, vnode: VNodeWithData) {
  const opts = vnode.componentOptions
  if (isDef(opts) && opts.Ctor.options.inheritAttrs === false) {
    return
  }
  if (isUndef(oldVnode.data.attrs) && isUndef(vnode.data.attrs)) {
    return
  }
  let key, cur, old
  const elm = vnode.elm
  const oldAttrs = oldVnode.data.attrs || {}
  let attrs: any = vnode.data.attrs || {}
  // clone observed objects, as the user probably wants to mutate it
  if (isDef(attrs.__ob__) || isTrue(attrs._v_attr_proxy)) {
    attrs = vnode.data.attrs = extend({}, attrs)
  }

  for (key in attrs) {
    cur = attrs[key]
    old = oldAttrs[key]
    if (old !== cur) {
      setAttr(elm, key, cur, vnode.data.pre)
    }
  }
  // #4391: in IE9, setting type can reset value for input[type=radio]
  // #6666: IE/Edge forces progress value down to 1 before setting a max
  /* istanbul ignore if */
  if ((isIE || isEdge) && attrs.value !== oldAttrs.value) {
    setAttr(elm, 'value', attrs.value)
  }
  for (key in oldAttrs) {
    if (isUndef(attrs[key])) {
      if (isXlink(key)) {
        elm.removeAttributeNS(xlinkNS, getXlinkProp(key))
      } else if (!isEnumeratedAttr(key)) {
        elm.removeAttribute(key)
      }
    }
  }
}

function setAttr(el: Element, key: string, value: any, isInPre?: any) {
  if (isInPre || el.tagName.indexOf('-') > -1) {
    baseSetAttr(el, key, value)
  } else if (isBooleanAttr(key)) {
    // set attribute for blank value
    // e.g. <option disabled>Select one</option>
    if (isFalsyAttrValue(value)) {
      el.removeAttribute(key)
    } else {
      // technically allowfullscreen is a boolean attribute for <iframe>,
      // but Flash expects a value of "true" when used on <embed> tag
      value = key === 'allowfullscreen' && el.tagName === 'EMBED' ? 'true' : key
      el.setAttribute(key, value)
    }
  } else if (isEnumeratedAttr(key)) {
    el.setAttribute(key, convertEnumeratedValue(key, value))
  } else if (isXlink(key)) {
    if (isFalsyAttrValue(value)) {
      el.removeAttributeNS(xlinkNS, getXlinkProp(key))
    } else {
      el.setAttributeNS(xlinkNS, key, value)
    }
  } else {
    baseSetAttr(el, key, value)
  }
}

function baseSetAttr(el, key, value) {
  if (isFalsyAttrValue(value)) {
    el.removeAttribute(key)
  } else {
    // #7138: IE10 & 11 fires input event when setting placeholder on
    // <textarea>... block the first input event and remove the blocker
    // immediately.
    /* istanbul ignore if */
    if (
      isIE &&
      !isIE9 &&
      el.tagName === 'TEXTAREA' &&
      key === 'placeholder' &&
      value !== '' &&
      !el.__ieph
    ) {
      const blocker = e => {
        e.stopImmediatePropagation()
        el.removeEventListener('input', blocker)
      }
      el.addEventListener('input', blocker)
      // $flow-disable-line
      el.__ieph = true /* IE placeholder patched */
    }
    el.setAttribute(key, value)
  }
}

export default {
  create: updateAttrs,
  update: updateAttrs
}

Domain

Subdomains

Dependencies

  • env
  • index
  • util
  • vnode

Frequently Asked Questions

What does attrs.ts do?
attrs.ts is a source file in the vue codebase, written in typescript. It belongs to the WebPlatform domain, WebRuntime subdomain.
What functions are defined in attrs.ts?
attrs.ts defines 3 function(s): baseSetAttr, setAttr, updateAttrs.
What does attrs.ts depend on?
attrs.ts imports 4 module(s): env, index, util, vnode.
What files import attrs.ts?
attrs.ts is imported by 1 file(s): index.ts.
Where is attrs.ts in the architecture?
attrs.ts is located at src/platforms/web/runtime/modules/attrs.ts (domain: WebPlatform, subdomain: WebRuntime, directory: src/platforms/web/runtime/modules).

Analyze Your Own Codebase

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

Try Supermodel Free