Home / File/ readonly.ts — vue Source File

readonly.ts — vue Source File

Architecture documentation for readonly.ts, a typescript file in the vue codebase. 10 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  0c0a6db0_d081_921f_5fe2_f51407664b15["readonly.ts"]
  abfe3078_bfec_252c_2107_7cdf0dd06f08["reactive.ts"]
  0c0a6db0_d081_921f_5fe2_f51407664b15 --> abfe3078_bfec_252c_2107_7cdf0dd06f08
  17645efb_66ee_96d8_ce0d_83b1eee19e3e["isCollectionType"]
  0c0a6db0_d081_921f_5fe2_f51407664b15 --> 17645efb_66ee_96d8_ce0d_83b1eee19e3e
  9243ce8a_d877_78fa_a26d_a35d289a1277["isReadonly"]
  0c0a6db0_d081_921f_5fe2_f51407664b15 --> 9243ce8a_d877_78fa_a26d_a35d289a1277
  4dec4402_504f_d778_cdf1_34adb751a2fb["isShallow"]
  0c0a6db0_d081_921f_5fe2_f51407664b15 --> 4dec4402_504f_d778_cdf1_34adb751a2fb
  2b181521_4bf2_5868_7efc_af9addf489bf["ReactiveFlags"]
  0c0a6db0_d081_921f_5fe2_f51407664b15 --> 2b181521_4bf2_5868_7efc_af9addf489bf
  b991efdb_a484_6482_e954_4e5d4455273d["UnwrapNestedRefs"]
  0c0a6db0_d081_921f_5fe2_f51407664b15 --> b991efdb_a484_6482_e954_4e5d4455273d
  ada43310_8d32_ee2a_f18b_1e24fd4f8a1d["ref.ts"]
  0c0a6db0_d081_921f_5fe2_f51407664b15 --> ada43310_8d32_ee2a_f18b_1e24fd4f8a1d
  64ef09a1_8484_35c7_6154_30d045c3ca15["isRef"]
  0c0a6db0_d081_921f_5fe2_f51407664b15 --> 64ef09a1_8484_35c7_6154_30d045c3ca15
  b2dbf772_f39b_f942_7a94_3bc9c73b0a11["Ref"]
  0c0a6db0_d081_921f_5fe2_f51407664b15 --> b2dbf772_f39b_f942_7a94_3bc9c73b0a11
  8a5fb776_a8f4_ce8a_8549_67af07f2e1e9["util"]
  0c0a6db0_d081_921f_5fe2_f51407664b15 --> 8a5fb776_a8f4_ce8a_8549_67af07f2e1e9
  style 0c0a6db0_d081_921f_5fe2_f51407664b15 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { def, warn, isPlainObject, isArray } from 'core/util'
import {
  isCollectionType,
  isReadonly,
  isShallow,
  ReactiveFlags,
  UnwrapNestedRefs
} from './reactive'
import { isRef, Ref, RefFlag } from './ref'

type Primitive = string | number | boolean | bigint | symbol | undefined | null
type Builtin = Primitive | Function | Date | Error | RegExp
export type DeepReadonly<T> = T extends Builtin
  ? T
  : T extends Map<infer K, infer V>
  ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
  : T extends ReadonlyMap<infer K, infer V>
  ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
  : T extends WeakMap<infer K, infer V>
  ? WeakMap<DeepReadonly<K>, DeepReadonly<V>>
  : T extends Set<infer U>
  ? ReadonlySet<DeepReadonly<U>>
  : T extends ReadonlySet<infer U>
  ? ReadonlySet<DeepReadonly<U>>
  : T extends WeakSet<infer U>
  ? WeakSet<DeepReadonly<U>>
  : T extends Promise<infer U>
  ? Promise<DeepReadonly<U>>
  : T extends Ref<infer U>
  ? Readonly<Ref<DeepReadonly<U>>>
  : T extends {}
  ? { readonly [K in keyof T]: DeepReadonly<T[K]> }
  : Readonly<T>

const rawToReadonlyFlag = `__v_rawToReadonly`
const rawToShallowReadonlyFlag = `__v_rawToShallowReadonly`

export function readonly<T extends object>(
  target: T
): DeepReadonly<UnwrapNestedRefs<T>> {
  return createReadonly(target, false)
}

function createReadonly(target: any, shallow: boolean) {
  if (!isPlainObject(target)) {
    if (__DEV__) {
      if (isArray(target)) {
        warn(`Vue 2 does not support readonly arrays.`)
      } else if (isCollectionType(target)) {
        warn(
          `Vue 2 does not support readonly collection types such as Map or Set.`
        )
      } else {
        warn(`value cannot be made readonly: ${typeof target}`)
      }
    }
    return target as any
  }

  if (__DEV__ && !Object.isExtensible(target)) {
// ... (68 more lines)

Domain

Subdomains

Frequently Asked Questions

What does readonly.ts do?
readonly.ts is a source file in the vue codebase, written in typescript. It belongs to the CompilerSFC domain, TemplateTransformer subdomain.
What functions are defined in readonly.ts?
readonly.ts defines 4 function(s): createReadonly, defineReadonlyProperty, readonly, shallowReadonly.
What does readonly.ts depend on?
readonly.ts imports 10 module(s): ReactiveFlags, Ref, UnwrapNestedRefs, isCollectionType, isReadonly, isRef, isShallow, reactive.ts, and 2 more.
Where is readonly.ts in the architecture?
readonly.ts is located at src/v3/reactivity/readonly.ts (domain: CompilerSFC, subdomain: TemplateTransformer, directory: src/v3/reactivity).

Analyze Your Own Codebase

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

Try Supermodel Free