const arrayInstrumentations: Record<string, Function> = {} // instrument identity-sensitive Array methods to account for possible reactive // values ;(['includes', 'indexOf', 'lastIndexOf'] asconst).forEach(key => { const method = Array.prototype[key] as any arrayInstrumentations[key] = function(this: unknown[], ...args: unknown[]) { const arr = toRaw(this) for (let i = 0, l = this.length; i < l; i++) { track(arr, TrackOpTypes.GET, i + '') } // we run the method using the original args first (which may be reactive) const res = method.apply(arr, args) if (res === -1 || res === false) { // if that didn't work, run it again using raw values. return method.apply(arr, args.map(toRaw)) } else { return res } } }) // instrument length-altering mutation methods to avoid length being tracked // which leads to infinite loops in some cases (#2137) ;(['push', 'pop', 'shift', 'unshift', 'splice'] asconst).forEach(key => { const method = Array.prototype[key] as any arrayInstrumentations[key] = function(this: unknown[], ...args: unknown[]) { pauseTracking() const res = method.apply(this, args) enableTracking() return res } })
// 肤浅模式 直接返回 若不是,则将 res 对象 进行深度追踪 if (shallow) { return res }
// 这里是将 ref 直接展开 if (isRef(res)) { // ref unwrapping - does not apply for Array + integer key. // 不适用数组+整数键。 const shouldUnwrap = !targetIsArray || !isIntegerKey(key) return shouldUnwrap ? res.value : res }
// 如果 res 是一个 对象 if (isObject(res)) { // Convert returned value into a proxy as well. we do the isObject check // here to avoid invalid value warning. Also need to lazy access readonly // and reactive here to avoid circular dependency. // 递归执行 return isReadonly ? readonly(res) : reactive(res) }