@reactive-vscode/reactivity
Advanced tools
Comparing version 0.2.6-beta.1 to 0.2.6
@@ -107,7 +107,7 @@ export declare const ARRAY_ITERATE_KEY: unique symbol; | ||
export declare type DeepReadonly<T> = T extends Builtin ? T : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends WeakSet<infer U> ? WeakSet<DeepReadonly<U>> : T extends Promise<infer U> ? Promise<DeepReadonly<U>> : T extends Ref<infer U> ? Readonly<Ref<DeepReadonly<U>>> : T extends {} ? { | ||
export declare type DeepReadonly<T> = T extends Builtin ? T : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends WeakSet<infer U> ? WeakSet<DeepReadonly<U>> : T extends Promise<infer U> ? Promise<DeepReadonly<U>> : T extends Ref<infer U, unknown> ? Readonly<Ref<DeepReadonly<U>>> : T extends {} ? { | ||
readonly [K in keyof T]: DeepReadonly<T[K]>; | ||
} : Readonly<T>; | ||
export declare type DistributeRef<T> = T extends Ref<infer V> ? V : T; | ||
export declare type DistributeRef<T> = T extends Ref<infer V, unknown> ? V : T; | ||
@@ -807,3 +807,3 @@ export declare function effect<T = any>(fn: () => T, options?: ReactiveEffectOptions): ReactiveEffectRunner<T>; | ||
export declare type UnwrapRef<T> = T extends ShallowRef<infer V, infer _> ? V : T extends Ref<infer V, infer _> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>; | ||
export declare type UnwrapRef<T> = T extends ShallowRef<infer V, unknown> ? V : T extends Ref<infer V, unknown> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>; | ||
@@ -810,0 +810,0 @@ export declare type UnwrapRefSimple<T> = T extends Builtin | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | { |
/** | ||
* @vue/shared v3.5.10 | ||
* @vue/shared v3.5.12 | ||
* (c) 2018-present Yuxi (Evan) You and Vue contributors | ||
@@ -63,3 +63,3 @@ * @license MIT | ||
/** | ||
* @vue/reactivity v3.5.10 | ||
* @vue/reactivity v3.5.12 | ||
* (c) 2018-present Yuxi (Evan) You and Vue contributors | ||
@@ -303,4 +303,10 @@ * @license MIT | ||
let batchedSub; | ||
function batch(sub) { | ||
let batchedComputed; | ||
function batch(sub, isComputed = false) { | ||
sub.flags |= 8; | ||
if (isComputed) { | ||
sub.next = batchedComputed; | ||
batchedComputed = sub; | ||
return; | ||
} | ||
sub.next = batchedSub; | ||
@@ -316,16 +322,18 @@ batchedSub = sub; | ||
} | ||
if (batchedComputed) { | ||
let e = batchedComputed; | ||
batchedComputed = void 0; | ||
while (e) { | ||
const next = e.next; | ||
e.next = void 0; | ||
e.flags &= ~8; | ||
e = next; | ||
} | ||
} | ||
let error; | ||
while (batchedSub) { | ||
let e = batchedSub; | ||
let next; | ||
while (e) { | ||
if (!(e.flags & 1)) { | ||
e.flags &= ~8; | ||
} | ||
e = e.next; | ||
} | ||
e = batchedSub; | ||
batchedSub = void 0; | ||
while (e) { | ||
next = e.next; | ||
const next = e.next; | ||
e.next = void 0; | ||
@@ -430,12 +438,12 @@ e.flags &= ~8; | ||
} | ||
if (dep.subs === link) { | ||
dep.subs = prevSub; | ||
} | ||
if (!!(process.env.NODE_ENV !== "production") && dep.subsHead === link) { | ||
dep.subsHead = nextSub; | ||
} | ||
if (!dep.subs && dep.computed) { | ||
dep.computed.flags &= ~4; | ||
for (let l = dep.computed.deps; l; l = l.nextDep) { | ||
removeSub(l, true); | ||
if (dep.subs === link) { | ||
dep.subs = prevSub; | ||
if (!prevSub && dep.computed) { | ||
dep.computed.flags &= ~4; | ||
for (let l = dep.computed.deps; l; l = l.nextDep) { | ||
removeSub(l, true); | ||
} | ||
} | ||
@@ -530,3 +538,2 @@ } | ||
this.subs = void 0; | ||
this.target = void 0; | ||
this.map = void 0; | ||
@@ -656,3 +663,2 @@ this.key = void 0; | ||
depsMap.set(key, dep = new Dep()); | ||
dep.target = target; | ||
dep.map = depsMap; | ||
@@ -708,3 +714,3 @@ dep.key = key; | ||
} else { | ||
if (key !== void 0) { | ||
if (key !== void 0 || depsMap.has(void 0)) { | ||
run(depsMap.get(key)); | ||
@@ -1081,113 +1087,2 @@ } | ||
const getProto = (v) => Reflect.getPrototypeOf(v); | ||
function get(target, key, isReadonly2 = false, isShallow2 = false) { | ||
target = target["__v_raw"]; | ||
const rawTarget = toRaw(target); | ||
const rawKey = toRaw(key); | ||
if (!isReadonly2) { | ||
if (hasChanged(key, rawKey)) { | ||
track(rawTarget, "get", key); | ||
} | ||
track(rawTarget, "get", rawKey); | ||
} | ||
const { has: has2 } = getProto(rawTarget); | ||
const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive; | ||
if (has2.call(rawTarget, key)) { | ||
return wrap(target.get(key)); | ||
} else if (has2.call(rawTarget, rawKey)) { | ||
return wrap(target.get(rawKey)); | ||
} else if (target !== rawTarget) { | ||
target.get(key); | ||
} | ||
} | ||
function has(key, isReadonly2 = false) { | ||
const target = this["__v_raw"]; | ||
const rawTarget = toRaw(target); | ||
const rawKey = toRaw(key); | ||
if (!isReadonly2) { | ||
if (hasChanged(key, rawKey)) { | ||
track(rawTarget, "has", key); | ||
} | ||
track(rawTarget, "has", rawKey); | ||
} | ||
return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey); | ||
} | ||
function size(target, isReadonly2 = false) { | ||
target = target["__v_raw"]; | ||
!isReadonly2 && track(toRaw(target), "iterate", ITERATE_KEY); | ||
return Reflect.get(target, "size", target); | ||
} | ||
function add(value, _isShallow = false) { | ||
if (!_isShallow && !isShallow(value) && !isReadonly(value)) { | ||
value = toRaw(value); | ||
} | ||
const target = toRaw(this); | ||
const proto = getProto(target); | ||
const hadKey = proto.has.call(target, value); | ||
if (!hadKey) { | ||
target.add(value); | ||
trigger(target, "add", value, value); | ||
} | ||
return this; | ||
} | ||
function set(key, value, _isShallow = false) { | ||
if (!_isShallow && !isShallow(value) && !isReadonly(value)) { | ||
value = toRaw(value); | ||
} | ||
const target = toRaw(this); | ||
const { has: has2, get: get2 } = getProto(target); | ||
let hadKey = has2.call(target, key); | ||
if (!hadKey) { | ||
key = toRaw(key); | ||
hadKey = has2.call(target, key); | ||
} else if (!!(process.env.NODE_ENV !== "production")) { | ||
checkIdentityKeys(target, has2, key); | ||
} | ||
const oldValue = get2.call(target, key); | ||
target.set(key, value); | ||
if (!hadKey) { | ||
trigger(target, "add", key, value); | ||
} else if (hasChanged(value, oldValue)) { | ||
trigger(target, "set", key, value, oldValue); | ||
} | ||
return this; | ||
} | ||
function deleteEntry(key) { | ||
const target = toRaw(this); | ||
const { has: has2, get: get2 } = getProto(target); | ||
let hadKey = has2.call(target, key); | ||
if (!hadKey) { | ||
key = toRaw(key); | ||
hadKey = has2.call(target, key); | ||
} else if (!!(process.env.NODE_ENV !== "production")) { | ||
checkIdentityKeys(target, has2, key); | ||
} | ||
const oldValue = get2 ? get2.call(target, key) : void 0; | ||
const result = target.delete(key); | ||
if (hadKey) { | ||
trigger(target, "delete", key, void 0, oldValue); | ||
} | ||
return result; | ||
} | ||
function clear() { | ||
const target = toRaw(this); | ||
const hadItems = target.size !== 0; | ||
const oldTarget = !!(process.env.NODE_ENV !== "production") ? isMap(target) ? new Map(target) : new Set(target) : void 0; | ||
const result = target.clear(); | ||
if (hadItems) { | ||
trigger(target, "clear", void 0, void 0, oldTarget); | ||
} | ||
return result; | ||
} | ||
function createForEach(isReadonly2, isShallow2) { | ||
return function forEach(callback, thisArg) { | ||
const observed = this; | ||
const target = observed["__v_raw"]; | ||
const rawTarget = toRaw(target); | ||
const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive; | ||
!isReadonly2 && track(rawTarget, "iterate", ITERATE_KEY); | ||
return target.forEach((value, key) => { | ||
return callback.call(thisArg, wrap(value), wrap(key), observed); | ||
}); | ||
}; | ||
} | ||
function createIterableMethod(method, isReadonly2, isShallow2) { | ||
@@ -1235,67 +1130,130 @@ return function(...args) { | ||
} | ||
function createInstrumentations() { | ||
const mutableInstrumentations2 = { | ||
function createInstrumentations(readonly2, shallow) { | ||
const instrumentations = { | ||
get(key) { | ||
return get(this, key); | ||
const target = this["__v_raw"]; | ||
const rawTarget = toRaw(target); | ||
const rawKey = toRaw(key); | ||
if (!readonly2) { | ||
if (hasChanged(key, rawKey)) { | ||
track(rawTarget, "get", key); | ||
} | ||
track(rawTarget, "get", rawKey); | ||
} | ||
const { has } = getProto(rawTarget); | ||
const wrap = shallow ? toShallow : readonly2 ? toReadonly : toReactive; | ||
if (has.call(rawTarget, key)) { | ||
return wrap(target.get(key)); | ||
} else if (has.call(rawTarget, rawKey)) { | ||
return wrap(target.get(rawKey)); | ||
} else if (target !== rawTarget) { | ||
target.get(key); | ||
} | ||
}, | ||
get size() { | ||
return size(this); | ||
const target = this["__v_raw"]; | ||
!readonly2 && track(toRaw(target), "iterate", ITERATE_KEY); | ||
return Reflect.get(target, "size", target); | ||
}, | ||
has, | ||
add, | ||
set, | ||
delete: deleteEntry, | ||
clear, | ||
forEach: createForEach(false, false) | ||
}; | ||
const shallowInstrumentations2 = { | ||
get(key) { | ||
return get(this, key, false, true); | ||
}, | ||
get size() { | ||
return size(this); | ||
}, | ||
has, | ||
add(value) { | ||
return add.call(this, value, true); | ||
}, | ||
set(key, value) { | ||
return set.call(this, key, value, true); | ||
}, | ||
delete: deleteEntry, | ||
clear, | ||
forEach: createForEach(false, true) | ||
}; | ||
const readonlyInstrumentations2 = { | ||
get(key) { | ||
return get(this, key, true); | ||
}, | ||
get size() { | ||
return size(this, true); | ||
}, | ||
has(key) { | ||
return has.call(this, key, true); | ||
const target = this["__v_raw"]; | ||
const rawTarget = toRaw(target); | ||
const rawKey = toRaw(key); | ||
if (!readonly2) { | ||
if (hasChanged(key, rawKey)) { | ||
track(rawTarget, "has", key); | ||
} | ||
track(rawTarget, "has", rawKey); | ||
} | ||
return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey); | ||
}, | ||
add: createReadonlyMethod("add"), | ||
set: createReadonlyMethod("set"), | ||
delete: createReadonlyMethod("delete"), | ||
clear: createReadonlyMethod("clear"), | ||
forEach: createForEach(true, false) | ||
forEach(callback, thisArg) { | ||
const observed = this; | ||
const target = observed["__v_raw"]; | ||
const rawTarget = toRaw(target); | ||
const wrap = shallow ? toShallow : readonly2 ? toReadonly : toReactive; | ||
!readonly2 && track(rawTarget, "iterate", ITERATE_KEY); | ||
return target.forEach((value, key) => { | ||
return callback.call(thisArg, wrap(value), wrap(key), observed); | ||
}); | ||
} | ||
}; | ||
const shallowReadonlyInstrumentations2 = { | ||
get(key) { | ||
return get(this, key, true, true); | ||
}, | ||
get size() { | ||
return size(this, true); | ||
}, | ||
has(key) { | ||
return has.call(this, key, true); | ||
}, | ||
add: createReadonlyMethod("add"), | ||
set: createReadonlyMethod("set"), | ||
delete: createReadonlyMethod("delete"), | ||
clear: createReadonlyMethod("clear"), | ||
forEach: createForEach(true, true) | ||
}; | ||
extend( | ||
instrumentations, | ||
readonly2 ? { | ||
add: createReadonlyMethod("add"), | ||
set: createReadonlyMethod("set"), | ||
delete: createReadonlyMethod("delete"), | ||
clear: createReadonlyMethod("clear") | ||
} : { | ||
add(value) { | ||
if (!shallow && !isShallow(value) && !isReadonly(value)) { | ||
value = toRaw(value); | ||
} | ||
const target = toRaw(this); | ||
const proto = getProto(target); | ||
const hadKey = proto.has.call(target, value); | ||
if (!hadKey) { | ||
target.add(value); | ||
trigger(target, "add", value, value); | ||
} | ||
return this; | ||
}, | ||
set(key, value) { | ||
if (!shallow && !isShallow(value) && !isReadonly(value)) { | ||
value = toRaw(value); | ||
} | ||
const target = toRaw(this); | ||
const { has, get } = getProto(target); | ||
let hadKey = has.call(target, key); | ||
if (!hadKey) { | ||
key = toRaw(key); | ||
hadKey = has.call(target, key); | ||
} else if (!!(process.env.NODE_ENV !== "production")) { | ||
checkIdentityKeys(target, has, key); | ||
} | ||
const oldValue = get.call(target, key); | ||
target.set(key, value); | ||
if (!hadKey) { | ||
trigger(target, "add", key, value); | ||
} else if (hasChanged(value, oldValue)) { | ||
trigger(target, "set", key, value, oldValue); | ||
} | ||
return this; | ||
}, | ||
delete(key) { | ||
const target = toRaw(this); | ||
const { has, get } = getProto(target); | ||
let hadKey = has.call(target, key); | ||
if (!hadKey) { | ||
key = toRaw(key); | ||
hadKey = has.call(target, key); | ||
} else if (!!(process.env.NODE_ENV !== "production")) { | ||
checkIdentityKeys(target, has, key); | ||
} | ||
const oldValue = get ? get.call(target, key) : void 0; | ||
const result = target.delete(key); | ||
if (hadKey) { | ||
trigger(target, "delete", key, void 0, oldValue); | ||
} | ||
return result; | ||
}, | ||
clear() { | ||
const target = toRaw(this); | ||
const hadItems = target.size !== 0; | ||
const oldTarget = !!(process.env.NODE_ENV !== "production") ? isMap(target) ? new Map(target) : new Set(target) : void 0; | ||
const result = target.clear(); | ||
if (hadItems) { | ||
trigger( | ||
target, | ||
"clear", | ||
void 0, | ||
void 0, | ||
oldTarget | ||
); | ||
} | ||
return result; | ||
} | ||
} | ||
); | ||
const iteratorMethods = [ | ||
@@ -1308,26 +1266,8 @@ "keys", | ||
iteratorMethods.forEach((method) => { | ||
mutableInstrumentations2[method] = createIterableMethod(method, false, false); | ||
readonlyInstrumentations2[method] = createIterableMethod(method, true, false); | ||
shallowInstrumentations2[method] = createIterableMethod(method, false, true); | ||
shallowReadonlyInstrumentations2[method] = createIterableMethod( | ||
method, | ||
true, | ||
true | ||
); | ||
instrumentations[method] = createIterableMethod(method, readonly2, shallow); | ||
}); | ||
return [ | ||
mutableInstrumentations2, | ||
readonlyInstrumentations2, | ||
shallowInstrumentations2, | ||
shallowReadonlyInstrumentations2 | ||
]; | ||
return instrumentations; | ||
} | ||
const [ | ||
mutableInstrumentations, | ||
readonlyInstrumentations, | ||
shallowInstrumentations, | ||
shallowReadonlyInstrumentations | ||
] = /* @__PURE__ */ createInstrumentations(); | ||
function createInstrumentationGetter(isReadonly2, shallow) { | ||
const instrumentations = shallow ? isReadonly2 ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly2 ? readonlyInstrumentations : mutableInstrumentations; | ||
const instrumentations = createInstrumentations(isReadonly2, shallow); | ||
return (target, key, receiver) => { | ||
@@ -1360,5 +1300,5 @@ if (key === "__v_isReactive") { | ||
}; | ||
function checkIdentityKeys(target, has2, key) { | ||
function checkIdentityKeys(target, has, key) { | ||
const rawKey = toRaw(key); | ||
if (rawKey !== key && has2.call(target, rawKey)) { | ||
if (rawKey !== key && has.call(target, rawKey)) { | ||
const type = toRawType(target); | ||
@@ -1583,5 +1523,5 @@ warn$1( | ||
const dep = this.dep = new Dep(); | ||
const { get: get2, set: set2 } = factory(dep.track.bind(dep), dep.trigger.bind(dep)); | ||
this._get = get2; | ||
this._set = set2; | ||
const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep)); | ||
this._get = get; | ||
this._set = set; | ||
} | ||
@@ -1676,3 +1616,3 @@ get value() { | ||
activeSub !== this) { | ||
batch(this); | ||
batch(this, true); | ||
return true; | ||
@@ -1679,0 +1619,0 @@ } else if (!!(process.env.NODE_ENV !== "production")) ; |
{ | ||
"name": "@reactive-vscode/reactivity", | ||
"type": "module", | ||
"version": "0.2.6-beta.1", | ||
"version": "0.2.6", | ||
"description": "Full Vue Reactivity API without DOM", | ||
@@ -22,6 +22,7 @@ "author": "_Kerman <kermanx@qq.com>", | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js" | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"main": "./dist/index.js", | ||
"main": "./dist/index.cjs", | ||
"types": "./dist/index.d.ts", | ||
@@ -33,7 +34,7 @@ "files": [ | ||
"devDependencies": { | ||
"@vue/reactivity": "^3.5.10", | ||
"@vue/shared": "^3.5.10", | ||
"typescript": "^5.6.2", | ||
"vite": "^5.4.8", | ||
"vite-plugin-dts": "^4.2.1" | ||
"@vue/reactivity": "^3.5.12", | ||
"@vue/shared": "^3.5.12", | ||
"typescript": "^5.6.3", | ||
"vite": "^5.4.10", | ||
"vite-plugin-dts": "^4.3.0" | ||
}, | ||
@@ -40,0 +41,0 @@ "scripts": { |
155227
6
5209