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

Function set

packages/reactivity/src/collectionHandlers.ts:189–212  ·  view source on GitHub ↗
(this: MapTypes, key: unknown, value: unknown)

Source from the content-addressed store, hash-verified

187 return this
188 },
189 set(this: MapTypes, key: unknown, value: unknown) {
190 if (!shallow && !isShallow(value) && !isReadonly(value)) {
191 value = toRaw(value)
192 }
193 const target = toRaw(this)
194 const { has, get } = getProto(target)
195
196 let hadKey = has.call(target, key)
197 if (!hadKey) {
198 key = toRaw(key)
199 hadKey = has.call(target, key)
200 } else if (__DEV__) {
201 checkIdentityKeys(target, has, key)
202 }
203
204 const oldValue = get.call(target, key)
205 target.set(key, value)
206 if (!hadKey) {
207 trigger(target, TriggerOpTypes.ADD, key, value)
208 } else if (hasChanged(value, oldValue)) {
209 trigger(target, TriggerOpTypes.SET, key, value, oldValue)
210 }
211 return this
212 },
213 delete(this: CollectionTypes, key: unknown) {
214 const target = toRaw(this)
215 const { has, get } = getProto(target)

Callers

nothing calls this directly

Calls 8

isShallowFunction · 0.90
isReadonlyFunction · 0.90
toRawFunction · 0.90
triggerFunction · 0.90
hasChangedFunction · 0.90
getProtoFunction · 0.85
checkIdentityKeysFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected