export function ref(value?: unknown) { return createRef(value, false); } function createRef(rawValue: unknown, shallow: boolean) { if (isRef(rawValue)) { return rawValue; } return new RefImpl(rawValue, shallow); } class RefImpl { private _value: T; private _rawValue: T; constructor(value: T, public readonly __v_isShallow: boolean) { this._rawValue = value; this._value = __v_isShallow ? value : toReactive(value); } get value() { trackRefValue(this); return this._value; } set value(newVal) { if (hasChanged(newVal, this._rawValue)) { this._rawValue = newVal; this._value = toReactive(newVal); triggerRefValue(this); } } } // 判断 ref 的引用值是否是对象 function toReactive(value: any): any { return isObject(value) ? reactive(value) : value; }
export function reactive(target: object) { if (isReadonly(target)) { return target; } return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers); } function createReactiveObject( target: Target, isReadonly: boolean, baseHandlers: ProxyHandler, collectionHandlers: ProxyHandler ) { if (!isObject(target)) { if (__DEV__) { console.warn(`value cannot be made reactive: ${String(target)}`); } return target; } const proxy = new Proxy( target, collectionType ? collectionHandlers : baseHandlers ); return proxy; } export const mutableHandlers: ProxyHandler
上一篇:日记审计遵守合规安全要求
下一篇:怎么查看手机序列号,串号是多少