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

Function createReactiveObject

packages/reactivity/src/reactive.ts:262–306  ·  view source on GitHub ↗
(
  target: Target,
  isReadonly: boolean,
  baseHandlers: ProxyHandler<any>,
  collectionHandlers: ProxyHandler<any>,
  proxyMap: WeakMap<Target, any>,
)

Source from the content-addressed store, hash-verified

260}
261
262function createReactiveObject(
263 target: Target,
264 isReadonly: boolean,
265 baseHandlers: ProxyHandler<any>,
266 collectionHandlers: ProxyHandler<any>,
267 proxyMap: WeakMap<Target, any>,
268) {
269 if (!isObject(target)) {
270 if (__DEV__) {
271 warn(
272 `value cannot be made ${isReadonly ? 'readonly' : 'reactive'}: ${String(
273 target,
274 )}`,
275 )
276 }
277 return target
278 }
279 // target is already a Proxy, return it.
280 // exception: calling readonly() on a reactive object
281 if (
282 target[ReactiveFlags.RAW] &&
283 !(isReadonly && target[ReactiveFlags.IS_REACTIVE])
284 ) {
285 return target
286 }
287 // only specific value types can be observed.
288 if (target[ReactiveFlags.SKIP] || !Object.isExtensible(target)) {
289 return target
290 }
291 // target already has corresponding Proxy
292 const existingProxy = proxyMap.get(target)
293 if (existingProxy) {
294 return existingProxy
295 }
296 const targetType = targetTypeMap(toRawType(target))
297 if (targetType === TargetType.INVALID) {
298 return target
299 }
300 const proxy = new Proxy(
301 target,
302 targetType === TargetType.COLLECTION ? collectionHandlers : baseHandlers,
303 )
304 proxyMap.set(target, proxy)
305 return proxy
306}
307
308/**
309 * Checks if an object is a proxy created by {@link reactive} or

Callers 4

reactiveFunction · 0.85
shallowReactiveFunction · 0.85
readonlyFunction · 0.85
shallowReadonlyFunction · 0.85

Calls 7

isObjectFunction · 0.90
warnFunction · 0.90
toRawTypeFunction · 0.90
StringInterface · 0.85
targetTypeMapFunction · 0.85
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected