MCPcopy
hub / github.com/vuejs/core / get

Method get

packages/reactivity/src/baseHandlers.ts:55–134  ·  view source on GitHub ↗
(target: Target, key: string | symbol, receiver: object)

Source from the content-addressed store, hash-verified

53 ) {}
54
55 get(target: Target, key: string | symbol, receiver: object): any {
56 if (key === ReactiveFlags.SKIP) return target[ReactiveFlags.SKIP]
57
58 const isReadonly = this._isReadonly,
59 isShallow = this._isShallow
60 if (key === ReactiveFlags.IS_REACTIVE) {
61 return !isReadonly
62 } else if (key === ReactiveFlags.IS_READONLY) {
63 return isReadonly
64 } else if (key === ReactiveFlags.IS_SHALLOW) {
65 return isShallow
66 } else if (key === ReactiveFlags.RAW) {
67 if (
68 receiver ===
69 (isReadonly
70 ? isShallow
71 ? shallowReadonlyMap
72 : readonlyMap
73 : isShallow
74 ? shallowReactiveMap
75 : reactiveMap
76 ).get(target) ||
77 // receiver is not the reactive proxy, but has the same prototype
78 // this means the receiver is a user proxy of the reactive proxy
79 Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)
80 ) {
81 return target
82 }
83 // early return undefined
84 return
85 }
86
87 const targetIsArray = isArray(target)
88
89 if (!isReadonly) {
90 let fn: Function | undefined
91 if (targetIsArray && (fn = arrayInstrumentations[key])) {
92 return fn
93 }
94 if (key === 'hasOwnProperty') {
95 return hasOwnProperty
96 }
97 }
98
99 const res = Reflect.get(
100 target,
101 key,
102 // if this is a proxy wrapping a ref, return methods using the raw ref
103 // as receiver so that we don't have to call `toRaw` on the ref in all
104 // its class methods
105 isRef(target) ? target : receiver,
106 )
107
108 if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
109 return res
110 }
111
112 if (!isReadonly) {

Callers 15

ref.tsFile · 0.45
onWatcherCleanupFunction · 0.45
watchFunction · 0.45
traverseFunction · 0.45
createReactiveObjectFunction · 0.45
getFunction · 0.45
trackFunction · 0.45
triggerFunction · 0.45
getDepFromReactiveFunction · 0.45
reactive.spec.tsFile · 0.45

Calls 8

isRefFunction · 0.90
isSymbolFunction · 0.90
trackFunction · 0.90
isIntegerKeyFunction · 0.90
isObjectFunction · 0.90
readonlyFunction · 0.90
reactiveFunction · 0.90
hasMethod · 0.80

Tested by

no test coverage detected