@vue/reactivity
Advanced tools
Comparing version 3.0.0-alpha.12 to 3.0.0-alpha.13
@@ -34,2 +34,3 @@ 'use strict'; | ||
} | ||
let uid = 0; | ||
function createReactiveEffect(fn, options) { | ||
@@ -55,2 +56,3 @@ const effect = function reactiveEffect(...args) { | ||
}; | ||
effect.id = uid++; | ||
effect._isEffect = true; | ||
@@ -186,11 +188,2 @@ effect.active = true; | ||
// global immutability lock | ||
let LOCKED = true; | ||
function lock() { | ||
LOCKED = true; | ||
} | ||
function unlock() { | ||
LOCKED = false; | ||
} | ||
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol) | ||
@@ -200,3 +193,3 @@ .map(key => Symbol[key]) | ||
const get = /*#__PURE__*/ createGetter(); | ||
const shallowReactiveGet = /*#__PURE__*/ createGetter(false, true); | ||
const shallowGet = /*#__PURE__*/ createGetter(false, true); | ||
const readonlyGet = /*#__PURE__*/ createGetter(true); | ||
@@ -224,3 +217,4 @@ const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true); | ||
return function get(target, key, receiver) { | ||
if (shared.isArray(target) && shared.hasOwn(arrayInstrumentations, key)) { | ||
const targetIsArray = shared.isArray(target); | ||
if (targetIsArray && shared.hasOwn(arrayInstrumentations, key)) { | ||
return Reflect.get(arrayInstrumentations, key, receiver); | ||
@@ -233,11 +227,16 @@ } | ||
if (shallow) { | ||
track(target, "get" /* GET */, key); | ||
// TODO strict mode that returns a shallow-readonly version of the value | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return res; | ||
} | ||
// ref unwrapping, only for Objects, not for Arrays. | ||
if (isRef(res) && !shared.isArray(target)) { | ||
return res.value; | ||
if (isRef(res)) { | ||
if (targetIsArray) { | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return res; | ||
} | ||
else { | ||
// ref unwrapping, only for Objects, not for Arrays. | ||
return res.value; | ||
} | ||
} | ||
track(target, "get" /* GET */, key); | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return shared.isObject(res) | ||
@@ -253,13 +252,5 @@ ? isReadonly | ||
const set = /*#__PURE__*/ createSetter(); | ||
const shallowReactiveSet = /*#__PURE__*/ createSetter(false, true); | ||
const readonlySet = /*#__PURE__*/ createSetter(true); | ||
const shallowReadonlySet = /*#__PURE__*/ createSetter(true, true); | ||
function createSetter(isReadonly = false, shallow = false) { | ||
const shallowSet = /*#__PURE__*/ createSetter(true); | ||
function createSetter(shallow = false) { | ||
return function set(target, key, value, receiver) { | ||
if (isReadonly && LOCKED) { | ||
{ | ||
console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
} | ||
const oldValue = target[key]; | ||
@@ -314,15 +305,15 @@ if (!shallow) { | ||
get: readonlyGet, | ||
set: readonlySet, | ||
has, | ||
ownKeys, | ||
set(target, key) { | ||
{ | ||
console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
}, | ||
deleteProperty(target, key) { | ||
if (LOCKED) { | ||
{ | ||
console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
{ | ||
console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
else { | ||
return deleteProperty(target, key); | ||
} | ||
return true; | ||
} | ||
@@ -332,4 +323,4 @@ }; | ||
...mutableHandlers, | ||
get: shallowReactiveGet, | ||
set: shallowReactiveSet | ||
get: shallowGet, | ||
set: shallowSet | ||
}; | ||
@@ -341,4 +332,3 @@ // Props handlers are special in the sense that it should not unwrap top-level | ||
...readonlyHandlers, | ||
get: shallowReadonlyGet, | ||
set: shallowReadonlySet | ||
get: shallowReadonlyGet | ||
}; | ||
@@ -450,3 +440,3 @@ | ||
const wrap = isReadonly ? toReadonly : toReactive; | ||
track(target, "iterate" /* ITERATE */, ITERATE_KEY); | ||
!isReadonly && track(target, "iterate" /* ITERATE */, ITERATE_KEY); | ||
// important: create sure the callback is | ||
@@ -469,3 +459,4 @@ // 1. invoked with the reactive map as `this` and 3rd arg | ||
const wrap = isReadonly ? toReadonly : toReactive; | ||
track(target, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
!isReadonly && | ||
track(target, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
// return a wrapped iterator which returns observed versions of the | ||
@@ -491,14 +482,9 @@ // values emitted from the real iterator | ||
} | ||
function createReadonlyMethod(method, type) { | ||
function createReadonlyMethod(type) { | ||
return function (...args) { | ||
if (LOCKED) { | ||
{ | ||
const key = args[0] ? `on key "${args[0]}" ` : ``; | ||
console.warn(`${shared.capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this)); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
{ | ||
const key = args[0] ? `on key "${args[0]}" ` : ``; | ||
console.warn(`${shared.capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this)); | ||
} | ||
else { | ||
return method.apply(this, args); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
}; | ||
@@ -528,6 +514,6 @@ } | ||
has: has$1, | ||
add: createReadonlyMethod(add, "add" /* ADD */), | ||
set: createReadonlyMethod(set$1, "set" /* SET */), | ||
delete: createReadonlyMethod(deleteEntry, "delete" /* DELETE */), | ||
clear: createReadonlyMethod(clear, "clear" /* CLEAR */), | ||
add: createReadonlyMethod("add" /* ADD */), | ||
set: createReadonlyMethod("set" /* SET */), | ||
delete: createReadonlyMethod("delete" /* DELETE */), | ||
clear: createReadonlyMethod("clear" /* CLEAR */), | ||
forEach: createForEach(true) | ||
@@ -570,3 +556,2 @@ }; | ||
// observable creation. | ||
const readonlyValues = new WeakSet(); | ||
const nonReactiveValues = new WeakSet(); | ||
@@ -587,17 +572,11 @@ const collectionTypes = new Set([Set, Map, WeakMap, WeakSet]); | ||
} | ||
// target is explicitly marked as readonly by user | ||
if (readonlyValues.has(target)) { | ||
return readonly(target); | ||
} | ||
if (isRef(target)) { | ||
return target; | ||
} | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, mutableHandlers, mutableCollectionHandlers); | ||
} | ||
// Return a reactive-copy of the original object, where only the root level | ||
// properties are reactive, and does NOT unwrap refs nor recursively convert | ||
// returned properties. | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, shallowReactiveHandlers, mutableCollectionHandlers); | ||
} | ||
function readonly(target) { | ||
// value is a mutable observable, retrieve its original and return | ||
// a readonly version. | ||
if (reactiveToRaw.has(target)) { | ||
target = reactiveToRaw.get(target); | ||
} | ||
return createReactiveObject(target, rawToReadonly, readonlyToRaw, readonlyHandlers, readonlyCollectionHandlers); | ||
@@ -612,8 +591,2 @@ } | ||
} | ||
// Return a reactive-copy of the original object, where only the root level | ||
// properties are reactive, and does NOT unwrap refs nor recursively convert | ||
// returned properties. | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, shallowReactiveHandlers, mutableCollectionHandlers); | ||
} | ||
function createReactiveObject(target, toProxy, toRaw, baseHandlers, collectionHandlers) { | ||
@@ -654,8 +627,5 @@ if (!shared.isObject(target)) { | ||
function toRaw(observed) { | ||
return reactiveToRaw.get(observed) || readonlyToRaw.get(observed) || observed; | ||
observed = readonlyToRaw.get(observed) || observed; | ||
return reactiveToRaw.get(observed) || observed; | ||
} | ||
function markReadonly(value) { | ||
readonlyValues.add(value); | ||
return value; | ||
} | ||
function markNonReactive(value) { | ||
@@ -699,2 +669,15 @@ nonReactiveValues.add(value); | ||
} | ||
function customRef(factory) { | ||
const { get, set } = factory(() => track(r, "get" /* GET */, 'value'), () => trigger(r, "set" /* SET */, 'value')); | ||
const r = { | ||
_isRef: true, | ||
get value() { | ||
return get(); | ||
}, | ||
set value(v) { | ||
set(v); | ||
} | ||
}; | ||
return r; | ||
} | ||
function toRefs(object) { | ||
@@ -706,7 +689,7 @@ if ( !isReactive(object)) { | ||
for (const key in object) { | ||
ret[key] = toProxyRef(object, key); | ||
ret[key] = toRef(object, key); | ||
} | ||
return ret; | ||
} | ||
function toProxyRef(object, key) { | ||
function toRef(object, key) { | ||
return { | ||
@@ -772,2 +755,3 @@ _isRef: true, | ||
exports.computed = computed; | ||
exports.customRef = customRef; | ||
exports.effect = effect; | ||
@@ -778,5 +762,3 @@ exports.enableTracking = enableTracking; | ||
exports.isRef = isRef; | ||
exports.lock = lock; | ||
exports.markNonReactive = markNonReactive; | ||
exports.markReadonly = markReadonly; | ||
exports.pauseTracking = pauseTracking; | ||
@@ -792,6 +774,6 @@ exports.reactive = reactive; | ||
exports.toRaw = toRaw; | ||
exports.toRef = toRef; | ||
exports.toRefs = toRefs; | ||
exports.track = track; | ||
exports.trigger = trigger; | ||
exports.unlock = unlock; | ||
exports.unref = unref; |
@@ -34,2 +34,3 @@ 'use strict'; | ||
} | ||
let uid = 0; | ||
function createReactiveEffect(fn, options) { | ||
@@ -55,2 +56,3 @@ const effect = function reactiveEffect(...args) { | ||
}; | ||
effect.id = uid++; | ||
effect._isEffect = true; | ||
@@ -167,11 +169,2 @@ effect.active = true; | ||
// global immutability lock | ||
let LOCKED = true; | ||
function lock() { | ||
LOCKED = true; | ||
} | ||
function unlock() { | ||
LOCKED = false; | ||
} | ||
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol) | ||
@@ -181,3 +174,3 @@ .map(key => Symbol[key]) | ||
const get = /*#__PURE__*/ createGetter(); | ||
const shallowReactiveGet = /*#__PURE__*/ createGetter(false, true); | ||
const shallowGet = /*#__PURE__*/ createGetter(false, true); | ||
const readonlyGet = /*#__PURE__*/ createGetter(true); | ||
@@ -205,3 +198,4 @@ const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true); | ||
return function get(target, key, receiver) { | ||
if (shared.isArray(target) && shared.hasOwn(arrayInstrumentations, key)) { | ||
const targetIsArray = shared.isArray(target); | ||
if (targetIsArray && shared.hasOwn(arrayInstrumentations, key)) { | ||
return Reflect.get(arrayInstrumentations, key, receiver); | ||
@@ -214,11 +208,16 @@ } | ||
if (shallow) { | ||
track(target, "get" /* GET */, key); | ||
// TODO strict mode that returns a shallow-readonly version of the value | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return res; | ||
} | ||
// ref unwrapping, only for Objects, not for Arrays. | ||
if (isRef(res) && !shared.isArray(target)) { | ||
return res.value; | ||
if (isRef(res)) { | ||
if (targetIsArray) { | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return res; | ||
} | ||
else { | ||
// ref unwrapping, only for Objects, not for Arrays. | ||
return res.value; | ||
} | ||
} | ||
track(target, "get" /* GET */, key); | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return shared.isObject(res) | ||
@@ -234,10 +233,5 @@ ? isReadonly | ||
const set = /*#__PURE__*/ createSetter(); | ||
const shallowReactiveSet = /*#__PURE__*/ createSetter(false, true); | ||
const readonlySet = /*#__PURE__*/ createSetter(true); | ||
const shallowReadonlySet = /*#__PURE__*/ createSetter(true, true); | ||
function createSetter(isReadonly = false, shallow = false) { | ||
const shallowSet = /*#__PURE__*/ createSetter(true); | ||
function createSetter(shallow = false) { | ||
return function set(target, key, value, receiver) { | ||
if (isReadonly && LOCKED) { | ||
return true; | ||
} | ||
const oldValue = target[key]; | ||
@@ -292,12 +286,9 @@ if (!shallow) { | ||
get: readonlyGet, | ||
set: readonlySet, | ||
has, | ||
ownKeys, | ||
set(target, key) { | ||
return true; | ||
}, | ||
deleteProperty(target, key) { | ||
if (LOCKED) { | ||
return true; | ||
} | ||
else { | ||
return deleteProperty(target, key); | ||
} | ||
return true; | ||
} | ||
@@ -307,4 +298,4 @@ }; | ||
...mutableHandlers, | ||
get: shallowReactiveGet, | ||
set: shallowReactiveSet | ||
get: shallowGet, | ||
set: shallowSet | ||
}; | ||
@@ -316,4 +307,3 @@ // Props handlers are special in the sense that it should not unwrap top-level | ||
...readonlyHandlers, | ||
get: shallowReadonlyGet, | ||
set: shallowReadonlySet | ||
get: shallowReadonlyGet | ||
}; | ||
@@ -415,3 +405,3 @@ | ||
const wrap = isReadonly ? toReadonly : toReactive; | ||
track(target, "iterate" /* ITERATE */, ITERATE_KEY); | ||
!isReadonly && track(target, "iterate" /* ITERATE */, ITERATE_KEY); | ||
// important: create sure the callback is | ||
@@ -434,3 +424,4 @@ // 1. invoked with the reactive map as `this` and 3rd arg | ||
const wrap = isReadonly ? toReadonly : toReactive; | ||
track(target, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
!isReadonly && | ||
track(target, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
// return a wrapped iterator which returns observed versions of the | ||
@@ -456,10 +447,5 @@ // values emitted from the real iterator | ||
} | ||
function createReadonlyMethod(method, type) { | ||
function createReadonlyMethod(type) { | ||
return function (...args) { | ||
if (LOCKED) { | ||
return type === "delete" /* DELETE */ ? false : this; | ||
} | ||
else { | ||
return method.apply(this, args); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
}; | ||
@@ -489,6 +475,6 @@ } | ||
has: has$1, | ||
add: createReadonlyMethod(add, "add" /* ADD */), | ||
set: createReadonlyMethod(set$1, "set" /* SET */), | ||
delete: createReadonlyMethod(deleteEntry, "delete" /* DELETE */), | ||
clear: createReadonlyMethod(clear, "clear" /* CLEAR */), | ||
add: createReadonlyMethod("add" /* ADD */), | ||
set: createReadonlyMethod("set" /* SET */), | ||
delete: createReadonlyMethod("delete" /* DELETE */), | ||
clear: createReadonlyMethod("clear" /* CLEAR */), | ||
forEach: createForEach(true) | ||
@@ -520,3 +506,2 @@ }; | ||
// observable creation. | ||
const readonlyValues = new WeakSet(); | ||
const nonReactiveValues = new WeakSet(); | ||
@@ -537,17 +522,11 @@ const collectionTypes = new Set([Set, Map, WeakMap, WeakSet]); | ||
} | ||
// target is explicitly marked as readonly by user | ||
if (readonlyValues.has(target)) { | ||
return readonly(target); | ||
} | ||
if (isRef(target)) { | ||
return target; | ||
} | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, mutableHandlers, mutableCollectionHandlers); | ||
} | ||
// Return a reactive-copy of the original object, where only the root level | ||
// properties are reactive, and does NOT unwrap refs nor recursively convert | ||
// returned properties. | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, shallowReactiveHandlers, mutableCollectionHandlers); | ||
} | ||
function readonly(target) { | ||
// value is a mutable observable, retrieve its original and return | ||
// a readonly version. | ||
if (reactiveToRaw.has(target)) { | ||
target = reactiveToRaw.get(target); | ||
} | ||
return createReactiveObject(target, rawToReadonly, readonlyToRaw, readonlyHandlers, readonlyCollectionHandlers); | ||
@@ -562,8 +541,2 @@ } | ||
} | ||
// Return a reactive-copy of the original object, where only the root level | ||
// properties are reactive, and does NOT unwrap refs nor recursively convert | ||
// returned properties. | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, shallowReactiveHandlers, mutableCollectionHandlers); | ||
} | ||
function createReactiveObject(target, toProxy, toRaw, baseHandlers, collectionHandlers) { | ||
@@ -601,8 +574,5 @@ if (!shared.isObject(target)) { | ||
function toRaw(observed) { | ||
return reactiveToRaw.get(observed) || readonlyToRaw.get(observed) || observed; | ||
observed = readonlyToRaw.get(observed) || observed; | ||
return reactiveToRaw.get(observed) || observed; | ||
} | ||
function markReadonly(value) { | ||
readonlyValues.add(value); | ||
return value; | ||
} | ||
function markNonReactive(value) { | ||
@@ -646,10 +616,23 @@ nonReactiveValues.add(value); | ||
} | ||
function customRef(factory) { | ||
const { get, set } = factory(() => track(r, "get" /* GET */, 'value'), () => trigger(r, "set" /* SET */, 'value')); | ||
const r = { | ||
_isRef: true, | ||
get value() { | ||
return get(); | ||
}, | ||
set value(v) { | ||
set(v); | ||
} | ||
}; | ||
return r; | ||
} | ||
function toRefs(object) { | ||
const ret = {}; | ||
for (const key in object) { | ||
ret[key] = toProxyRef(object, key); | ||
ret[key] = toRef(object, key); | ||
} | ||
return ret; | ||
} | ||
function toProxyRef(object, key) { | ||
function toRef(object, key) { | ||
return { | ||
@@ -712,2 +695,3 @@ _isRef: true, | ||
exports.computed = computed; | ||
exports.customRef = customRef; | ||
exports.effect = effect; | ||
@@ -718,5 +702,3 @@ exports.enableTracking = enableTracking; | ||
exports.isRef = isRef; | ||
exports.lock = lock; | ||
exports.markNonReactive = markNonReactive; | ||
exports.markReadonly = markReadonly; | ||
exports.pauseTracking = pauseTracking; | ||
@@ -732,6 +714,6 @@ exports.reactive = reactive; | ||
exports.toRaw = toRaw; | ||
exports.toRef = toRef; | ||
exports.toRefs = toRefs; | ||
exports.track = track; | ||
exports.trigger = trigger; | ||
exports.unlock = unlock; | ||
exports.unref = unref; |
declare type BaseTypes = string | number | boolean; | ||
declare type BaseTypes = string | number | boolean | Node | Window; | ||
@@ -18,2 +18,9 @@ declare type CollectionTypes = IterableCollections | WeakCollections; | ||
export declare function customRef<T>(factory: CustomRefFactory<T>): Ref<T>; | ||
declare type CustomRefFactory<T> = (track: () => void, trigger: () => void) => { | ||
get: () => T; | ||
set: (value: T) => void; | ||
}; | ||
export declare type DebuggerEvent = { | ||
@@ -50,8 +57,4 @@ effect: ReactiveEffect; | ||
export declare function lock(): void; | ||
export declare function markNonReactive<T extends object>(value: T): T; | ||
export declare function markReadonly<T>(value: T): T; | ||
export declare function pauseTracking(): void; | ||
@@ -64,2 +67,3 @@ | ||
_isEffect: true; | ||
id: number; | ||
active: boolean; | ||
@@ -74,3 +78,3 @@ raw: () => T; | ||
computed?: boolean; | ||
scheduler?: (job: () => void) => void; | ||
scheduler?: (job: ReactiveEffect) => void; | ||
onTrack?: (event: DebuggerEvent) => void; | ||
@@ -107,4 +111,64 @@ onTrigger?: (event: DebuggerEvent) => void; | ||
declare type SymbolExtract<T> = (T extends { | ||
[Symbol.asyncIterator]: infer V; | ||
} ? { | ||
[Symbol.asyncIterator]: V; | ||
} : {}) & (T extends { | ||
[Symbol.hasInstance]: infer V; | ||
} ? { | ||
[Symbol.hasInstance]: V; | ||
} : {}) & (T extends { | ||
[Symbol.isConcatSpreadable]: infer V; | ||
} ? { | ||
[Symbol.isConcatSpreadable]: V; | ||
} : {}) & (T extends { | ||
[Symbol.iterator]: infer V; | ||
} ? { | ||
[Symbol.iterator]: V; | ||
} : {}) & (T extends { | ||
[Symbol.match]: infer V; | ||
} ? { | ||
[Symbol.match]: V; | ||
} : {}) & (T extends { | ||
[Symbol.matchAll]: infer V; | ||
} ? { | ||
[Symbol.matchAll]: V; | ||
} : {}) & (T extends { | ||
[Symbol.observable]: infer V; | ||
} ? { | ||
[Symbol.observable]: V; | ||
} : {}) & (T extends { | ||
[Symbol.replace]: infer V; | ||
} ? { | ||
[Symbol.replace]: V; | ||
} : {}) & (T extends { | ||
[Symbol.search]: infer V; | ||
} ? { | ||
[Symbol.search]: V; | ||
} : {}) & (T extends { | ||
[Symbol.species]: infer V; | ||
} ? { | ||
[Symbol.species]: V; | ||
} : {}) & (T extends { | ||
[Symbol.split]: infer V; | ||
} ? { | ||
[Symbol.split]: V; | ||
} : {}) & (T extends { | ||
[Symbol.toPrimitive]: infer V; | ||
} ? { | ||
[Symbol.toPrimitive]: V; | ||
} : {}) & (T extends { | ||
[Symbol.toStringTag]: infer V; | ||
} ? { | ||
[Symbol.toStringTag]: V; | ||
} : {}) & (T extends { | ||
[Symbol.unscopables]: infer V; | ||
} ? { | ||
[Symbol.unscopables]: V; | ||
} : {}); | ||
export declare function toRaw<T>(observed: T): T; | ||
export declare function toRef<T extends object, K extends keyof T>(object: T, key: K): Ref<T[K]>; | ||
export declare function toRefs<T extends object>(object: T): { | ||
@@ -131,4 +195,2 @@ [K in keyof T]: Ref<T[K]>; | ||
export declare function unlock(): void; | ||
export declare function unref<T>(ref: T): T extends Ref<infer V> ? V : T; | ||
@@ -138,11 +200,10 @@ | ||
export declare type UnwrapRef<T> = { | ||
cRef: T extends ComputedRef<infer V> ? UnwrapRef<V> : T; | ||
ref: T extends Ref<infer V> ? UnwrapRef<V> : T; | ||
array: T; | ||
object: { | ||
[K in keyof T]: UnwrapRef<T[K]>; | ||
}; | ||
}[T extends ComputedRef<any> ? 'cRef' : T extends Array<any> ? 'array' : T extends Ref | Function | CollectionTypes | BaseTypes ? 'ref' : T extends object ? 'object' : 'ref']; | ||
declare type UnwrappedObject<T> = { | ||
[P in keyof T]: UnwrapRef<T[P]>; | ||
} & SymbolExtract<T>; | ||
export declare type UnwrapRef<T> = T extends ComputedRef<infer V> ? UnwrapRefSimple<V> : T extends Ref<infer V> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>; | ||
declare type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref ? T : T extends Array<any> ? T : T extends object ? UnwrappedObject<T> : T; | ||
declare type WeakCollections = WeakMap<any, any> | WeakSet<any>; | ||
@@ -149,0 +210,0 @@ |
@@ -30,2 +30,3 @@ import { EMPTY_OBJ, isArray, isSymbol, hasOwn, isObject, hasChanged, capitalize, toRawType, makeMap, isFunction, NOOP } from '@vue/shared'; | ||
} | ||
let uid = 0; | ||
function createReactiveEffect(fn, options) { | ||
@@ -51,2 +52,3 @@ const effect = function reactiveEffect(...args) { | ||
}; | ||
effect.id = uid++; | ||
effect._isEffect = true; | ||
@@ -182,11 +184,2 @@ effect.active = true; | ||
// global immutability lock | ||
let LOCKED = true; | ||
function lock() { | ||
LOCKED = true; | ||
} | ||
function unlock() { | ||
LOCKED = false; | ||
} | ||
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol) | ||
@@ -196,3 +189,3 @@ .map(key => Symbol[key]) | ||
const get = /*#__PURE__*/ createGetter(); | ||
const shallowReactiveGet = /*#__PURE__*/ createGetter(false, true); | ||
const shallowGet = /*#__PURE__*/ createGetter(false, true); | ||
const readonlyGet = /*#__PURE__*/ createGetter(true); | ||
@@ -220,3 +213,4 @@ const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true); | ||
return function get(target, key, receiver) { | ||
if (isArray(target) && hasOwn(arrayInstrumentations, key)) { | ||
const targetIsArray = isArray(target); | ||
if (targetIsArray && hasOwn(arrayInstrumentations, key)) { | ||
return Reflect.get(arrayInstrumentations, key, receiver); | ||
@@ -229,11 +223,16 @@ } | ||
if (shallow) { | ||
track(target, "get" /* GET */, key); | ||
// TODO strict mode that returns a shallow-readonly version of the value | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return res; | ||
} | ||
// ref unwrapping, only for Objects, not for Arrays. | ||
if (isRef(res) && !isArray(target)) { | ||
return res.value; | ||
if (isRef(res)) { | ||
if (targetIsArray) { | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return res; | ||
} | ||
else { | ||
// ref unwrapping, only for Objects, not for Arrays. | ||
return res.value; | ||
} | ||
} | ||
track(target, "get" /* GET */, key); | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return isObject(res) | ||
@@ -249,13 +248,5 @@ ? isReadonly | ||
const set = /*#__PURE__*/ createSetter(); | ||
const shallowReactiveSet = /*#__PURE__*/ createSetter(false, true); | ||
const readonlySet = /*#__PURE__*/ createSetter(true); | ||
const shallowReadonlySet = /*#__PURE__*/ createSetter(true, true); | ||
function createSetter(isReadonly = false, shallow = false) { | ||
const shallowSet = /*#__PURE__*/ createSetter(true); | ||
function createSetter(shallow = false) { | ||
return function set(target, key, value, receiver) { | ||
if (isReadonly && LOCKED) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
} | ||
const oldValue = target[key]; | ||
@@ -310,15 +301,15 @@ if (!shallow) { | ||
get: readonlyGet, | ||
set: readonlySet, | ||
has, | ||
ownKeys, | ||
set(target, key) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
}, | ||
deleteProperty(target, key) { | ||
if (LOCKED) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
else { | ||
return deleteProperty(target, key); | ||
} | ||
return true; | ||
} | ||
@@ -328,4 +319,4 @@ }; | ||
...mutableHandlers, | ||
get: shallowReactiveGet, | ||
set: shallowReactiveSet | ||
get: shallowGet, | ||
set: shallowSet | ||
}; | ||
@@ -337,4 +328,3 @@ // Props handlers are special in the sense that it should not unwrap top-level | ||
...readonlyHandlers, | ||
get: shallowReadonlyGet, | ||
set: shallowReadonlySet | ||
get: shallowReadonlyGet | ||
}; | ||
@@ -447,3 +437,3 @@ | ||
const wrap = isReadonly ? toReadonly : toReactive; | ||
track(target, "iterate" /* ITERATE */, ITERATE_KEY); | ||
!isReadonly && track(target, "iterate" /* ITERATE */, ITERATE_KEY); | ||
// important: create sure the callback is | ||
@@ -466,3 +456,4 @@ // 1. invoked with the reactive map as `this` and 3rd arg | ||
const wrap = isReadonly ? toReadonly : toReactive; | ||
track(target, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
!isReadonly && | ||
track(target, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
// return a wrapped iterator which returns observed versions of the | ||
@@ -488,14 +479,9 @@ // values emitted from the real iterator | ||
} | ||
function createReadonlyMethod(method, type) { | ||
function createReadonlyMethod(type) { | ||
return function (...args) { | ||
if (LOCKED) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
const key = args[0] ? `on key "${args[0]}" ` : ``; | ||
console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this)); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
const key = args[0] ? `on key "${args[0]}" ` : ``; | ||
console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this)); | ||
} | ||
else { | ||
return method.apply(this, args); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
}; | ||
@@ -525,6 +511,6 @@ } | ||
has: has$1, | ||
add: createReadonlyMethod(add, "add" /* ADD */), | ||
set: createReadonlyMethod(set$1, "set" /* SET */), | ||
delete: createReadonlyMethod(deleteEntry, "delete" /* DELETE */), | ||
clear: createReadonlyMethod(clear, "clear" /* CLEAR */), | ||
add: createReadonlyMethod("add" /* ADD */), | ||
set: createReadonlyMethod("set" /* SET */), | ||
delete: createReadonlyMethod("delete" /* DELETE */), | ||
clear: createReadonlyMethod("clear" /* CLEAR */), | ||
forEach: createForEach(true) | ||
@@ -567,3 +553,2 @@ }; | ||
// observable creation. | ||
const readonlyValues = new WeakSet(); | ||
const nonReactiveValues = new WeakSet(); | ||
@@ -584,17 +569,11 @@ const collectionTypes = new Set([Set, Map, WeakMap, WeakSet]); | ||
} | ||
// target is explicitly marked as readonly by user | ||
if (readonlyValues.has(target)) { | ||
return readonly(target); | ||
} | ||
if (isRef(target)) { | ||
return target; | ||
} | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, mutableHandlers, mutableCollectionHandlers); | ||
} | ||
// Return a reactive-copy of the original object, where only the root level | ||
// properties are reactive, and does NOT unwrap refs nor recursively convert | ||
// returned properties. | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, shallowReactiveHandlers, mutableCollectionHandlers); | ||
} | ||
function readonly(target) { | ||
// value is a mutable observable, retrieve its original and return | ||
// a readonly version. | ||
if (reactiveToRaw.has(target)) { | ||
target = reactiveToRaw.get(target); | ||
} | ||
return createReactiveObject(target, rawToReadonly, readonlyToRaw, readonlyHandlers, readonlyCollectionHandlers); | ||
@@ -609,8 +588,2 @@ } | ||
} | ||
// Return a reactive-copy of the original object, where only the root level | ||
// properties are reactive, and does NOT unwrap refs nor recursively convert | ||
// returned properties. | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, shallowReactiveHandlers, mutableCollectionHandlers); | ||
} | ||
function createReactiveObject(target, toProxy, toRaw, baseHandlers, collectionHandlers) { | ||
@@ -651,8 +624,5 @@ if (!isObject(target)) { | ||
function toRaw(observed) { | ||
return reactiveToRaw.get(observed) || readonlyToRaw.get(observed) || observed; | ||
observed = readonlyToRaw.get(observed) || observed; | ||
return reactiveToRaw.get(observed) || observed; | ||
} | ||
function markReadonly(value) { | ||
readonlyValues.add(value); | ||
return value; | ||
} | ||
function markNonReactive(value) { | ||
@@ -696,2 +666,15 @@ nonReactiveValues.add(value); | ||
} | ||
function customRef(factory) { | ||
const { get, set } = factory(() => track(r, "get" /* GET */, 'value'), () => trigger(r, "set" /* SET */, 'value')); | ||
const r = { | ||
_isRef: true, | ||
get value() { | ||
return get(); | ||
}, | ||
set value(v) { | ||
set(v); | ||
} | ||
}; | ||
return r; | ||
} | ||
function toRefs(object) { | ||
@@ -703,7 +686,7 @@ if ((process.env.NODE_ENV !== 'production') && !isReactive(object)) { | ||
for (const key in object) { | ||
ret[key] = toProxyRef(object, key); | ||
ret[key] = toRef(object, key); | ||
} | ||
return ret; | ||
} | ||
function toProxyRef(object, key) { | ||
function toRef(object, key) { | ||
return { | ||
@@ -768,2 +751,2 @@ _isRef: true, | ||
export { ITERATE_KEY, computed, effect, enableTracking, isReactive, isReadonly, isRef, lock, markNonReactive, markReadonly, pauseTracking, reactive, readonly, ref, resetTracking, shallowReactive, shallowReadonly, shallowRef, stop, toRaw, toRefs, track, trigger, unlock, unref }; | ||
export { ITERATE_KEY, computed, customRef, effect, enableTracking, isReactive, isReadonly, isRef, markNonReactive, pauseTracking, reactive, readonly, ref, resetTracking, shallowReactive, shallowReadonly, shallowRef, stop, toRaw, toRef, toRefs, track, trigger, unref }; |
@@ -68,2 +68,3 @@ // Make a map and return a function for checking if a key | ||
} | ||
let uid = 0; | ||
function createReactiveEffect(fn, options) { | ||
@@ -89,2 +90,3 @@ const effect = function reactiveEffect(...args) { | ||
}; | ||
effect.id = uid++; | ||
effect._isEffect = true; | ||
@@ -220,11 +222,2 @@ effect.active = true; | ||
// global immutability lock | ||
let LOCKED = true; | ||
function lock() { | ||
LOCKED = true; | ||
} | ||
function unlock() { | ||
LOCKED = false; | ||
} | ||
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol) | ||
@@ -234,3 +227,3 @@ .map(key => Symbol[key]) | ||
const get = /*#__PURE__*/ createGetter(); | ||
const shallowReactiveGet = /*#__PURE__*/ createGetter(false, true); | ||
const shallowGet = /*#__PURE__*/ createGetter(false, true); | ||
const readonlyGet = /*#__PURE__*/ createGetter(true); | ||
@@ -258,3 +251,4 @@ const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true); | ||
return function get(target, key, receiver) { | ||
if (isArray(target) && hasOwn(arrayInstrumentations, key)) { | ||
const targetIsArray = isArray(target); | ||
if (targetIsArray && hasOwn(arrayInstrumentations, key)) { | ||
return Reflect.get(arrayInstrumentations, key, receiver); | ||
@@ -267,11 +261,16 @@ } | ||
if (shallow) { | ||
track(target, "get" /* GET */, key); | ||
// TODO strict mode that returns a shallow-readonly version of the value | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return res; | ||
} | ||
// ref unwrapping, only for Objects, not for Arrays. | ||
if (isRef(res) && !isArray(target)) { | ||
return res.value; | ||
if (isRef(res)) { | ||
if (targetIsArray) { | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return res; | ||
} | ||
else { | ||
// ref unwrapping, only for Objects, not for Arrays. | ||
return res.value; | ||
} | ||
} | ||
track(target, "get" /* GET */, key); | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return isObject(res) | ||
@@ -287,13 +286,5 @@ ? isReadonly | ||
const set = /*#__PURE__*/ createSetter(); | ||
const shallowReactiveSet = /*#__PURE__*/ createSetter(false, true); | ||
const readonlySet = /*#__PURE__*/ createSetter(true); | ||
const shallowReadonlySet = /*#__PURE__*/ createSetter(true, true); | ||
function createSetter(isReadonly = false, shallow = false) { | ||
const shallowSet = /*#__PURE__*/ createSetter(true); | ||
function createSetter(shallow = false) { | ||
return function set(target, key, value, receiver) { | ||
if (isReadonly && LOCKED) { | ||
{ | ||
console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
} | ||
const oldValue = target[key]; | ||
@@ -348,15 +339,15 @@ if (!shallow) { | ||
get: readonlyGet, | ||
set: readonlySet, | ||
has, | ||
ownKeys, | ||
set(target, key) { | ||
{ | ||
console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
}, | ||
deleteProperty(target, key) { | ||
if (LOCKED) { | ||
{ | ||
console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
{ | ||
console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
else { | ||
return deleteProperty(target, key); | ||
} | ||
return true; | ||
} | ||
@@ -366,4 +357,4 @@ }; | ||
...mutableHandlers, | ||
get: shallowReactiveGet, | ||
set: shallowReactiveSet | ||
get: shallowGet, | ||
set: shallowSet | ||
}; | ||
@@ -375,4 +366,3 @@ // Props handlers are special in the sense that it should not unwrap top-level | ||
...readonlyHandlers, | ||
get: shallowReadonlyGet, | ||
set: shallowReadonlySet | ||
get: shallowReadonlyGet | ||
}; | ||
@@ -484,3 +474,3 @@ | ||
const wrap = isReadonly ? toReadonly : toReactive; | ||
track(target, "iterate" /* ITERATE */, ITERATE_KEY); | ||
!isReadonly && track(target, "iterate" /* ITERATE */, ITERATE_KEY); | ||
// important: create sure the callback is | ||
@@ -503,3 +493,4 @@ // 1. invoked with the reactive map as `this` and 3rd arg | ||
const wrap = isReadonly ? toReadonly : toReactive; | ||
track(target, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
!isReadonly && | ||
track(target, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
// return a wrapped iterator which returns observed versions of the | ||
@@ -525,14 +516,9 @@ // values emitted from the real iterator | ||
} | ||
function createReadonlyMethod(method, type) { | ||
function createReadonlyMethod(type) { | ||
return function (...args) { | ||
if (LOCKED) { | ||
{ | ||
const key = args[0] ? `on key "${args[0]}" ` : ``; | ||
console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this)); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
{ | ||
const key = args[0] ? `on key "${args[0]}" ` : ``; | ||
console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this)); | ||
} | ||
else { | ||
return method.apply(this, args); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
}; | ||
@@ -562,6 +548,6 @@ } | ||
has: has$1, | ||
add: createReadonlyMethod(add, "add" /* ADD */), | ||
set: createReadonlyMethod(set$1, "set" /* SET */), | ||
delete: createReadonlyMethod(deleteEntry, "delete" /* DELETE */), | ||
clear: createReadonlyMethod(clear, "clear" /* CLEAR */), | ||
add: createReadonlyMethod("add" /* ADD */), | ||
set: createReadonlyMethod("set" /* SET */), | ||
delete: createReadonlyMethod("delete" /* DELETE */), | ||
clear: createReadonlyMethod("clear" /* CLEAR */), | ||
forEach: createForEach(true) | ||
@@ -604,3 +590,2 @@ }; | ||
// observable creation. | ||
const readonlyValues = new WeakSet(); | ||
const nonReactiveValues = new WeakSet(); | ||
@@ -621,17 +606,11 @@ const collectionTypes = new Set([Set, Map, WeakMap, WeakSet]); | ||
} | ||
// target is explicitly marked as readonly by user | ||
if (readonlyValues.has(target)) { | ||
return readonly(target); | ||
} | ||
if (isRef(target)) { | ||
return target; | ||
} | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, mutableHandlers, mutableCollectionHandlers); | ||
} | ||
// Return a reactive-copy of the original object, where only the root level | ||
// properties are reactive, and does NOT unwrap refs nor recursively convert | ||
// returned properties. | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, shallowReactiveHandlers, mutableCollectionHandlers); | ||
} | ||
function readonly(target) { | ||
// value is a mutable observable, retrieve its original and return | ||
// a readonly version. | ||
if (reactiveToRaw.has(target)) { | ||
target = reactiveToRaw.get(target); | ||
} | ||
return createReactiveObject(target, rawToReadonly, readonlyToRaw, readonlyHandlers, readonlyCollectionHandlers); | ||
@@ -646,8 +625,2 @@ } | ||
} | ||
// Return a reactive-copy of the original object, where only the root level | ||
// properties are reactive, and does NOT unwrap refs nor recursively convert | ||
// returned properties. | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, shallowReactiveHandlers, mutableCollectionHandlers); | ||
} | ||
function createReactiveObject(target, toProxy, toRaw, baseHandlers, collectionHandlers) { | ||
@@ -688,8 +661,5 @@ if (!isObject(target)) { | ||
function toRaw(observed) { | ||
return reactiveToRaw.get(observed) || readonlyToRaw.get(observed) || observed; | ||
observed = readonlyToRaw.get(observed) || observed; | ||
return reactiveToRaw.get(observed) || observed; | ||
} | ||
function markReadonly(value) { | ||
readonlyValues.add(value); | ||
return value; | ||
} | ||
function markNonReactive(value) { | ||
@@ -733,2 +703,15 @@ nonReactiveValues.add(value); | ||
} | ||
function customRef(factory) { | ||
const { get, set } = factory(() => track(r, "get" /* GET */, 'value'), () => trigger(r, "set" /* SET */, 'value')); | ||
const r = { | ||
_isRef: true, | ||
get value() { | ||
return get(); | ||
}, | ||
set value(v) { | ||
set(v); | ||
} | ||
}; | ||
return r; | ||
} | ||
function toRefs(object) { | ||
@@ -740,7 +723,7 @@ if ( !isReactive(object)) { | ||
for (const key in object) { | ||
ret[key] = toProxyRef(object, key); | ||
ret[key] = toRef(object, key); | ||
} | ||
return ret; | ||
} | ||
function toProxyRef(object, key) { | ||
function toRef(object, key) { | ||
return { | ||
@@ -804,2 +787,2 @@ _isRef: true, | ||
export { ITERATE_KEY, computed, effect, enableTracking, isReactive, isReadonly, isRef, lock, markNonReactive, markReadonly, pauseTracking, reactive, readonly, ref, resetTracking, shallowReactive, shallowReadonly, shallowRef, stop, toRaw, toRefs, track, trigger, unlock, unref }; | ||
export { ITERATE_KEY, computed, customRef, effect, enableTracking, isReactive, isReadonly, isRef, markNonReactive, pauseTracking, reactive, readonly, ref, resetTracking, shallowReactive, shallowReadonly, shallowRef, stop, toRaw, toRef, toRefs, track, trigger, unref }; |
@@ -1,1 +0,1 @@ | ||
function t(t,e){const n=Object.create(null),r=t.split(",");for(let t=0;t<r.length;t++)n[r[t]]=!0;return e?t=>!!n[t.toLowerCase()]:t=>!!n[t]}const e={},n=()=>{},r=Object.prototype.hasOwnProperty,o=(t,e)=>r.call(t,e),c=Array.isArray,s=t=>"symbol"==typeof t,u=t=>null!==t&&"object"==typeof t,i=Object.prototype.toString,a=t=>(t=>i.call(t))(t).slice(8,-1),l=(t,e)=>t!==e&&(t==t||e==e),f=new WeakMap,d=[];let h;const p=Symbol(""),g=Symbol("");function v(t,n=e){(function(t){return t&&!0===t._isEffect})(t)&&(t=t.raw);const r=function(t,e){const n=function(...r){if(!n.active)return e.scheduler?void 0:t(...r);if(!d.includes(n)){w(n);try{return m(),d.push(n),h=n,t(...r)}finally{d.pop(),M(),h=d[d.length-1]}}};return n._isEffect=!0,n.active=!0,n.raw=t,n.deps=[],n.options=e,n}(t,n);return n.lazy||r(),r}function y(t){t.active&&(w(t),t.options.onStop&&t.options.onStop(),t.active=!1)}function w(t){const{deps:e}=t;if(e.length){for(let n=0;n<e.length;n++)e[n].delete(t);e.length=0}}let S=!0;const b=[];function k(){b.push(S),S=!1}function m(){b.push(S),S=!0}function M(){const t=b.pop();S=void 0===t||t}function R(t,e,n){if(!S||void 0===h)return;let r=f.get(t);void 0===r&&f.set(t,r=new Map);let o=r.get(n);void 0===o&&r.set(n,o=new Set),o.has(h)||(o.add(h),h.deps.push(o))}function E(t,e,n,r,o,s){const u=f.get(t);if(void 0===u)return;const i=new Set,a=new Set,l=t=>{void 0!==t&&t.forEach(t=>{t===h&&S||(t.options.computed?a.add(t):i.add(t))})};if("clear"===e)u.forEach(l);else if("length"===n&&c(t))u.forEach((t,e)=>{("length"===e||e>=r)&&l(t)});else{void 0!==n&&l(u.get(n));const r="add"===e||"delete"===e&&!c(t);(r||"set"===e&&t instanceof Map)&&l(u.get(c(t)?"length":p)),r&&t instanceof Map&&l(u.get(g))}const d=t=>{void 0!==t.options.scheduler?t.options.scheduler(t):t()};a.forEach(d),i.forEach(d)}let O=!0;function W(){O=!0}function _(){O=!1}const j=new Set(Object.getOwnPropertyNames(Symbol).map(t=>Symbol[t]).filter(s)),z=N(),P=N(!1,!0),x=N(!0),A=N(!0,!0),K={};function N(t=!1,e=!1){return function(n,r,i){if(c(n)&&o(K,r))return Reflect.get(K,r,i);const a=Reflect.get(n,r,i);return s(r)&&j.has(r)?a:e?(R(n,0,r),a):Pt(a)&&!c(n)?a.value:(R(n,0,r),u(a)?t?kt(a):bt(a):a)}}["includes","indexOf","lastIndexOf"].forEach(t=>{K[t]=function(...e){const n=Wt(this);for(let t=0,e=this.length;t<e;t++)R(n,0,t+"");const r=n[t](...e);return-1===r||!1===r?n[t](...e.map(Wt)):r}});const V=L(),C=L(!1,!0),F=L(!0),I=L(!0,!0);function L(t=!1,e=!1){return function(n,r,s,u){if(t&&O)return!0;const i=n[r];if(!e&&(s=Wt(s),!c(n)&&Pt(i)&&!Pt(s)))return i.value=s,!0;const a=o(n,r),f=Reflect.set(n,r,s,u);return n===Wt(u)&&(a?l(s,i)&&E(n,"set",r,s):E(n,"add",r,s)),f}}function q(t,e){const n=o(t,e),r=Reflect.deleteProperty(t,e);return r&&n&&E(t,"delete",e,void 0),r}function B(t,e){const n=Reflect.has(t,e);return R(t,0,e),n}function D(t){return R(t,0,p),Reflect.ownKeys(t)}const G={get:z,set:V,deleteProperty:q,has:B,ownKeys:D},H={get:x,set:F,has:B,ownKeys:D,deleteProperty:(t,e)=>!!O||q(t,e)},J={...G,get:P,set:C},Q={...H,get:A,set:I},T=t=>u(t)?bt(t):t,U=t=>u(t)?kt(t):t,X=t=>Reflect.getPrototypeOf(t);function Y(t,e,n){t=Wt(t);const r=Wt(e);e!==r&&R(t,0,e),R(t,0,r);const{has:o,get:c}=X(t);return o.call(t,e)?n(c.call(t,e)):o.call(t,r)?n(c.call(t,r)):void 0}function Z(t){const e=Wt(this),n=Wt(t);t!==n&&R(e,0,t),R(e,0,n);const r=X(e).has;return r.call(e,t)||r.call(e,n)}function $(t){return R(t=Wt(t),0,p),Reflect.get(X(t),"size",t)}function tt(t){t=Wt(t);const e=Wt(this),n=X(e),r=n.has.call(e,t),o=n.add.call(e,t);return r||E(e,"add",t,t),o}function et(t,e){e=Wt(e);const n=Wt(this),{has:r,get:o,set:c}=X(n);let s=r.call(n,t);s||(t=Wt(t),s=r.call(n,t));const u=o.call(n,t),i=c.call(n,t,e);return s?l(e,u)&&E(n,"set",t,e):E(n,"add",t,e),i}function nt(t){const e=Wt(this),{has:n,get:r,delete:o}=X(e);let c=n.call(e,t);c||(t=Wt(t),c=n.call(e,t));r&&r.call(e,t);const s=o.call(e,t);return c&&E(e,"delete",t,void 0),s}function rt(){const t=Wt(this),e=0!==t.size,n=X(t).clear.call(t);return e&&E(t,"clear",void 0,void 0),n}function ot(t){return function(e,n){const r=this,o=Wt(r),c=t?U:T;return R(o,0,p),X(o).forEach.call(o,(function(t,n){return e.call(r,c(t),c(n),r)}),n)}}function ct(t,e){return function(...n){const r=Wt(this),o=r instanceof Map,c="entries"===t||t===Symbol.iterator&&o,s="keys"===t&&o,u=X(r)[t].apply(r,n),i=e?U:T;return R(r,0,s?g:p),{next(){const{value:t,done:e}=u.next();return e?{value:t,done:e}:{value:c?[i(t[0]),i(t[1])]:i(t),done:e}},[Symbol.iterator](){return this}}}}function st(t,e){return function(...n){return O?"delete"!==e&&this:t.apply(this,n)}}const ut={get(t){return Y(this,t,T)},get size(){return $(this)},has:Z,add:tt,set:et,delete:nt,clear:rt,forEach:ot(!1)},it={get(t){return Y(this,t,U)},get size(){return $(this)},has:Z,add:st(tt,"add"),set:st(et,"set"),delete:st(nt,"delete"),clear:st(rt,"clear"),forEach:ot(!0)};function at(t){return(e,n,r)=>Reflect.get(o(t,n)&&n in e?t:e,n,r)}["keys","values","entries",Symbol.iterator].forEach(t=>{ut[t]=ct(t,!1),it[t]=ct(t,!0)});const lt={get:at(ut)},ft={get:at(it)},dt=new WeakMap,ht=new WeakMap,pt=new WeakMap,gt=new WeakMap,vt=new WeakSet,yt=new WeakSet,wt=new Set([Set,Map,WeakMap,WeakSet]),St=t("Object,Array,Map,Set,WeakMap,WeakSet");function bt(t){return gt.has(t)?t:vt.has(t)?kt(t):Pt(t)?t:Rt(t,dt,ht,G,lt)}function kt(t){return ht.has(t)&&(t=ht.get(t)),Rt(t,pt,gt,H,ft)}function mt(t){return Rt(t,pt,gt,Q,ft)}function Mt(t){return Rt(t,dt,ht,J,lt)}function Rt(t,e,n,r,o){if(!u(t))return t;let c=e.get(t);if(void 0!==c)return c;if(n.has(t))return t;if((s=t)._isVue||s._isVNode||!St(a(s))||yt.has(s)||Object.isFrozen(s))return t;var s;const i=wt.has(t.constructor)?o:r;return c=new Proxy(t,i),e.set(t,c),n.set(c,t),c}function Et(t){return ht.has(t)||gt.has(t)}function Ot(t){return gt.has(t)}function Wt(t){return ht.get(t)||gt.get(t)||t}function _t(t){return vt.add(t),t}function jt(t){return yt.add(t),t}const zt=t=>u(t)?bt(t):t;function Pt(t){return!!t&&!0===t._isRef}function xt(t){return Kt(t)}function At(t){return Kt(t,!0)}function Kt(t,e=!1){if(Pt(t))return t;e||(t=zt(t));const n={_isRef:!0,get value(){return R(n,0,"value"),t},set value(r){t=e?r:zt(r),E(n,"set","value",void 0)}};return n}function Nt(t){return Pt(t)?t.value:t}function Vt(t){const e={};for(const n in t)e[n]=Ct(t,n);return e}function Ct(t,e){return{_isRef:!0,get value(){return t[e]},set value(n){t[e]=n}}}function Ft(t){let e,r;"function"==typeof t?(e=t,r=n):(e=t.get,r=t.set);let o,c,s=!0;const u=v(e,{lazy:!0,computed:!0,scheduler:()=>{s||(s=!0,E(c,"set","value"))}});return c={_isRef:!0,effect:u,get value(){return s&&(o=u(),s=!1),R(c,0,"value"),o},set value(t){r(t)}},c}export{p as ITERATE_KEY,Ft as computed,v as effect,m as enableTracking,Et as isReactive,Ot as isReadonly,Pt as isRef,W as lock,jt as markNonReactive,_t as markReadonly,k as pauseTracking,bt as reactive,kt as readonly,xt as ref,M as resetTracking,Mt as shallowReactive,mt as shallowReadonly,At as shallowRef,y as stop,Wt as toRaw,Vt as toRefs,R as track,E as trigger,_ as unlock,Nt as unref}; | ||
function t(t,e){const n=Object.create(null),r=t.split(",");for(let t=0;t<r.length;t++)n[r[t]]=!0;return e?t=>!!n[t.toLowerCase()]:t=>!!n[t]}const e={},n=()=>{},r=Object.prototype.hasOwnProperty,o=(t,e)=>r.call(t,e),c=Array.isArray,s=t=>"symbol"==typeof t,u=t=>null!==t&&"object"==typeof t,i=Object.prototype.toString,l=t=>(t=>i.call(t))(t).slice(8,-1),a=(t,e)=>t!==e&&(t==t||e==e),f=new WeakMap,d=[];let h;const p=Symbol(""),g=Symbol("");function v(t,n=e){(function(t){return t&&!0===t._isEffect})(t)&&(t=t.raw);const r=function(t,e){const n=function(...r){if(!n.active)return e.scheduler?void 0:t(...r);if(!d.includes(n)){S(n);try{return M(),d.push(n),h=n,t(...r)}finally{d.pop(),k(),h=d[d.length-1]}}};return n.id=w++,n._isEffect=!0,n.active=!0,n.raw=t,n.deps=[],n.options=e,n}(t,n);return n.lazy||r(),r}function y(t){t.active&&(S(t),t.options.onStop&&t.options.onStop(),t.active=!1)}let w=0;function S(t){const{deps:e}=t;if(e.length){for(let n=0;n<e.length;n++)e[n].delete(t);e.length=0}}let b=!0;const R=[];function m(){R.push(b),b=!1}function M(){R.push(b),b=!0}function k(){const t=R.pop();b=void 0===t||t}function E(t,e,n){if(!b||void 0===h)return;let r=f.get(t);void 0===r&&f.set(t,r=new Map);let o=r.get(n);void 0===o&&r.set(n,o=new Set),o.has(h)||(o.add(h),h.deps.push(o))}function O(t,e,n,r,o,s){const u=f.get(t);if(void 0===u)return;const i=new Set,l=new Set,a=t=>{void 0!==t&&t.forEach(t=>{t===h&&b||(t.options.computed?l.add(t):i.add(t))})};if("clear"===e)u.forEach(a);else if("length"===n&&c(t))u.forEach((t,e)=>{("length"===e||e>=r)&&a(t)});else{void 0!==n&&a(u.get(n));const r="add"===e||"delete"===e&&!c(t);(r||"set"===e&&t instanceof Map)&&a(u.get(c(t)?"length":p)),r&&t instanceof Map&&a(u.get(g))}const d=t=>{void 0!==t.options.scheduler?t.options.scheduler(t):t()};l.forEach(d),i.forEach(d)}const W=new Set(Object.getOwnPropertyNames(Symbol).map(t=>Symbol[t]).filter(s)),_=A(),j=A(!1,!0),z=A(!0),P=A(!0,!0),x={};function A(t=!1,e=!1){return function(n,r,i){const l=c(n);if(l&&o(x,r))return Reflect.get(x,r,i);const a=Reflect.get(n,r,i);return s(r)&&W.has(r)?a:e?(!t&&E(n,0,r),a):bt(a)?l?(!t&&E(n,0,r),a):a.value:(!t&&E(n,0,r),u(a)?t?dt(a):at(a):a)}}["includes","indexOf","lastIndexOf"].forEach(t=>{x[t]=function(...e){const n=yt(this);for(let t=0,e=this.length;t<e;t++)E(n,0,t+"");const r=n[t](...e);return-1===r||!1===r?n[t](...e.map(yt)):r}});const K=V(),N=V(!0);function V(t=!1){return function(e,n,r,s){const u=e[n];if(!t&&(r=yt(r),!c(e)&&bt(u)&&!bt(r)))return u.value=r,!0;const i=o(e,n),l=Reflect.set(e,n,r,s);return e===yt(s)&&(i?a(r,u)&&O(e,"set",n,r):O(e,"add",n,r)),l}}function C(t,e){const n=Reflect.has(t,e);return E(t,0,e),n}function F(t){return E(t,0,p),Reflect.ownKeys(t)}const I={get:_,set:K,deleteProperty:function(t,e){const n=o(t,e),r=Reflect.deleteProperty(t,e);return r&&n&&O(t,"delete",e,void 0),r},has:C,ownKeys:F},L={get:z,has:C,ownKeys:F,set:(t,e)=>!0,deleteProperty:(t,e)=>!0},q={...I,get:j,set:N},B={...L,get:P},D=t=>u(t)?at(t):t,G=t=>u(t)?dt(t):t,H=t=>Reflect.getPrototypeOf(t);function J(t,e,n){t=yt(t);const r=yt(e);e!==r&&E(t,0,e),E(t,0,r);const{has:o,get:c}=H(t);return o.call(t,e)?n(c.call(t,e)):o.call(t,r)?n(c.call(t,r)):void 0}function Q(t){const e=yt(this),n=yt(t);t!==n&&E(e,0,t),E(e,0,n);const r=H(e).has;return r.call(e,t)||r.call(e,n)}function T(t){return E(t=yt(t),0,p),Reflect.get(H(t),"size",t)}function U(t){return function(e,n){const r=this,o=yt(r),c=t?G:D;return!t&&E(o,0,p),H(o).forEach.call(o,(function(t,n){return e.call(r,c(t),c(n),r)}),n)}}function X(t,e){return function(...n){const r=yt(this),o=r instanceof Map,c="entries"===t||t===Symbol.iterator&&o,s="keys"===t&&o,u=H(r)[t].apply(r,n),i=e?G:D;return!e&&E(r,0,s?g:p),{next(){const{value:t,done:e}=u.next();return e?{value:t,done:e}:{value:c?[i(t[0]),i(t[1])]:i(t),done:e}},[Symbol.iterator](){return this}}}}function Y(t){return function(...e){return"delete"!==t&&this}}const Z={get(t){return J(this,t,D)},get size(){return T(this)},has:Q,add:function(t){t=yt(t);const e=yt(this),n=H(e),r=n.has.call(e,t),o=n.add.call(e,t);return r||O(e,"add",t,t),o},set:function(t,e){e=yt(e);const n=yt(this),{has:r,get:o,set:c}=H(n);let s=r.call(n,t);s||(t=yt(t),s=r.call(n,t));const u=o.call(n,t),i=c.call(n,t,e);return s?a(e,u)&&O(n,"set",t,e):O(n,"add",t,e),i},delete:function(t){const e=yt(this),{has:n,get:r,delete:o}=H(e);let c=n.call(e,t);c||(t=yt(t),c=n.call(e,t)),r&&r.call(e,t);const s=o.call(e,t);return c&&O(e,"delete",t,void 0),s},clear:function(){const t=yt(this),e=0!==t.size,n=H(t).clear.call(t);return e&&O(t,"clear",void 0,void 0),n},forEach:U(!1)},$={get(t){return J(this,t,G)},get size(){return T(this)},has:Q,add:Y("add"),set:Y("set"),delete:Y("delete"),clear:Y("clear"),forEach:U(!0)};function tt(t){return(e,n,r)=>Reflect.get(o(t,n)&&n in e?t:e,n,r)}["keys","values","entries",Symbol.iterator].forEach(t=>{Z[t]=X(t,!1),$[t]=X(t,!0)});const et={get:tt(Z)},nt={get:tt($)},rt=new WeakMap,ot=new WeakMap,ct=new WeakMap,st=new WeakMap,ut=new WeakSet,it=new Set([Set,Map,WeakMap,WeakSet]),lt=t("Object,Array,Map,Set,WeakMap,WeakSet");function at(t){return st.has(t)?t:pt(t,rt,ot,I,et)}function ft(t){return pt(t,rt,ot,q,et)}function dt(t){return pt(t,ct,st,L,nt)}function ht(t){return pt(t,ct,st,B,nt)}function pt(t,e,n,r,o){if(!u(t))return t;let c=e.get(t);if(void 0!==c)return c;if(n.has(t))return t;if((s=t)._isVue||s._isVNode||!lt(l(s))||ut.has(s)||Object.isFrozen(s))return t;var s;const i=it.has(t.constructor)?o:r;return c=new Proxy(t,i),e.set(t,c),n.set(c,t),c}function gt(t){return ot.has(t)||st.has(t)}function vt(t){return st.has(t)}function yt(t){return t=st.get(t)||t,ot.get(t)||t}function wt(t){return ut.add(t),t}const St=t=>u(t)?at(t):t;function bt(t){return!!t&&!0===t._isRef}function Rt(t){return Mt(t)}function mt(t){return Mt(t,!0)}function Mt(t,e=!1){if(bt(t))return t;e||(t=St(t));const n={_isRef:!0,get value(){return E(n,0,"value"),t},set value(r){t=e?r:St(r),O(n,"set","value",void 0)}};return n}function kt(t){return bt(t)?t.value:t}function Et(t){const{get:e,set:n}=t(()=>E(r,0,"value"),()=>O(r,"set","value")),r={_isRef:!0,get value(){return e()},set value(t){n(t)}};return r}function Ot(t){const e={};for(const n in t)e[n]=Wt(t,n);return e}function Wt(t,e){return{_isRef:!0,get value(){return t[e]},set value(n){t[e]=n}}}function _t(t){let e,r;"function"==typeof t?(e=t,r=n):(e=t.get,r=t.set);let o,c,s=!0;const u=v(e,{lazy:!0,computed:!0,scheduler:()=>{s||(s=!0,O(c,"set","value"))}});return c={_isRef:!0,effect:u,get value(){return s&&(o=u(),s=!1),E(c,0,"value"),o},set value(t){r(t)}},c}export{p as ITERATE_KEY,_t as computed,Et as customRef,v as effect,M as enableTracking,gt as isReactive,vt as isReadonly,bt as isRef,wt as markNonReactive,m as pauseTracking,at as reactive,dt as readonly,Rt as ref,k as resetTracking,ft as shallowReactive,ht as shallowReadonly,mt as shallowRef,y as stop,yt as toRaw,Wt as toRef,Ot as toRefs,E as track,O as trigger,kt as unref}; |
@@ -71,2 +71,3 @@ var VueReactivity = (function (exports) { | ||
} | ||
let uid = 0; | ||
function createReactiveEffect(fn, options) { | ||
@@ -92,2 +93,3 @@ const effect = function reactiveEffect(...args) { | ||
}; | ||
effect.id = uid++; | ||
effect._isEffect = true; | ||
@@ -223,11 +225,2 @@ effect.active = true; | ||
// global immutability lock | ||
let LOCKED = true; | ||
function lock() { | ||
LOCKED = true; | ||
} | ||
function unlock() { | ||
LOCKED = false; | ||
} | ||
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol) | ||
@@ -237,3 +230,3 @@ .map(key => Symbol[key]) | ||
const get = /*#__PURE__*/ createGetter(); | ||
const shallowReactiveGet = /*#__PURE__*/ createGetter(false, true); | ||
const shallowGet = /*#__PURE__*/ createGetter(false, true); | ||
const readonlyGet = /*#__PURE__*/ createGetter(true); | ||
@@ -261,3 +254,4 @@ const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true); | ||
return function get(target, key, receiver) { | ||
if (isArray(target) && hasOwn(arrayInstrumentations, key)) { | ||
const targetIsArray = isArray(target); | ||
if (targetIsArray && hasOwn(arrayInstrumentations, key)) { | ||
return Reflect.get(arrayInstrumentations, key, receiver); | ||
@@ -270,11 +264,16 @@ } | ||
if (shallow) { | ||
track(target, "get" /* GET */, key); | ||
// TODO strict mode that returns a shallow-readonly version of the value | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return res; | ||
} | ||
// ref unwrapping, only for Objects, not for Arrays. | ||
if (isRef(res) && !isArray(target)) { | ||
return res.value; | ||
if (isRef(res)) { | ||
if (targetIsArray) { | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return res; | ||
} | ||
else { | ||
// ref unwrapping, only for Objects, not for Arrays. | ||
return res.value; | ||
} | ||
} | ||
track(target, "get" /* GET */, key); | ||
!isReadonly && track(target, "get" /* GET */, key); | ||
return isObject(res) | ||
@@ -290,13 +289,5 @@ ? isReadonly | ||
const set = /*#__PURE__*/ createSetter(); | ||
const shallowReactiveSet = /*#__PURE__*/ createSetter(false, true); | ||
const readonlySet = /*#__PURE__*/ createSetter(true); | ||
const shallowReadonlySet = /*#__PURE__*/ createSetter(true, true); | ||
function createSetter(isReadonly = false, shallow = false) { | ||
const shallowSet = /*#__PURE__*/ createSetter(true); | ||
function createSetter(shallow = false) { | ||
return function set(target, key, value, receiver) { | ||
if (isReadonly && LOCKED) { | ||
{ | ||
console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
} | ||
const oldValue = target[key]; | ||
@@ -351,15 +342,15 @@ if (!shallow) { | ||
get: readonlyGet, | ||
set: readonlySet, | ||
has, | ||
ownKeys, | ||
set(target, key) { | ||
{ | ||
console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
}, | ||
deleteProperty(target, key) { | ||
if (LOCKED) { | ||
{ | ||
console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
{ | ||
console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
else { | ||
return deleteProperty(target, key); | ||
} | ||
return true; | ||
} | ||
@@ -369,4 +360,4 @@ }; | ||
...mutableHandlers, | ||
get: shallowReactiveGet, | ||
set: shallowReactiveSet | ||
get: shallowGet, | ||
set: shallowSet | ||
}; | ||
@@ -378,4 +369,3 @@ // Props handlers are special in the sense that it should not unwrap top-level | ||
...readonlyHandlers, | ||
get: shallowReadonlyGet, | ||
set: shallowReadonlySet | ||
get: shallowReadonlyGet | ||
}; | ||
@@ -487,3 +477,3 @@ | ||
const wrap = isReadonly ? toReadonly : toReactive; | ||
track(target, "iterate" /* ITERATE */, ITERATE_KEY); | ||
!isReadonly && track(target, "iterate" /* ITERATE */, ITERATE_KEY); | ||
// important: create sure the callback is | ||
@@ -506,3 +496,4 @@ // 1. invoked with the reactive map as `this` and 3rd arg | ||
const wrap = isReadonly ? toReadonly : toReactive; | ||
track(target, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
!isReadonly && | ||
track(target, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
// return a wrapped iterator which returns observed versions of the | ||
@@ -528,14 +519,9 @@ // values emitted from the real iterator | ||
} | ||
function createReadonlyMethod(method, type) { | ||
function createReadonlyMethod(type) { | ||
return function (...args) { | ||
if (LOCKED) { | ||
{ | ||
const key = args[0] ? `on key "${args[0]}" ` : ``; | ||
console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this)); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
{ | ||
const key = args[0] ? `on key "${args[0]}" ` : ``; | ||
console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this)); | ||
} | ||
else { | ||
return method.apply(this, args); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
}; | ||
@@ -565,6 +551,6 @@ } | ||
has: has$1, | ||
add: createReadonlyMethod(add, "add" /* ADD */), | ||
set: createReadonlyMethod(set$1, "set" /* SET */), | ||
delete: createReadonlyMethod(deleteEntry, "delete" /* DELETE */), | ||
clear: createReadonlyMethod(clear, "clear" /* CLEAR */), | ||
add: createReadonlyMethod("add" /* ADD */), | ||
set: createReadonlyMethod("set" /* SET */), | ||
delete: createReadonlyMethod("delete" /* DELETE */), | ||
clear: createReadonlyMethod("clear" /* CLEAR */), | ||
forEach: createForEach(true) | ||
@@ -607,3 +593,2 @@ }; | ||
// observable creation. | ||
const readonlyValues = new WeakSet(); | ||
const nonReactiveValues = new WeakSet(); | ||
@@ -624,17 +609,11 @@ const collectionTypes = new Set([Set, Map, WeakMap, WeakSet]); | ||
} | ||
// target is explicitly marked as readonly by user | ||
if (readonlyValues.has(target)) { | ||
return readonly(target); | ||
} | ||
if (isRef(target)) { | ||
return target; | ||
} | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, mutableHandlers, mutableCollectionHandlers); | ||
} | ||
// Return a reactive-copy of the original object, where only the root level | ||
// properties are reactive, and does NOT unwrap refs nor recursively convert | ||
// returned properties. | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, shallowReactiveHandlers, mutableCollectionHandlers); | ||
} | ||
function readonly(target) { | ||
// value is a mutable observable, retrieve its original and return | ||
// a readonly version. | ||
if (reactiveToRaw.has(target)) { | ||
target = reactiveToRaw.get(target); | ||
} | ||
return createReactiveObject(target, rawToReadonly, readonlyToRaw, readonlyHandlers, readonlyCollectionHandlers); | ||
@@ -649,8 +628,2 @@ } | ||
} | ||
// Return a reactive-copy of the original object, where only the root level | ||
// properties are reactive, and does NOT unwrap refs nor recursively convert | ||
// returned properties. | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, rawToReactive, reactiveToRaw, shallowReactiveHandlers, mutableCollectionHandlers); | ||
} | ||
function createReactiveObject(target, toProxy, toRaw, baseHandlers, collectionHandlers) { | ||
@@ -691,8 +664,5 @@ if (!isObject(target)) { | ||
function toRaw(observed) { | ||
return reactiveToRaw.get(observed) || readonlyToRaw.get(observed) || observed; | ||
observed = readonlyToRaw.get(observed) || observed; | ||
return reactiveToRaw.get(observed) || observed; | ||
} | ||
function markReadonly(value) { | ||
readonlyValues.add(value); | ||
return value; | ||
} | ||
function markNonReactive(value) { | ||
@@ -736,2 +706,15 @@ nonReactiveValues.add(value); | ||
} | ||
function customRef(factory) { | ||
const { get, set } = factory(() => track(r, "get" /* GET */, 'value'), () => trigger(r, "set" /* SET */, 'value')); | ||
const r = { | ||
_isRef: true, | ||
get value() { | ||
return get(); | ||
}, | ||
set value(v) { | ||
set(v); | ||
} | ||
}; | ||
return r; | ||
} | ||
function toRefs(object) { | ||
@@ -743,7 +726,7 @@ if ( !isReactive(object)) { | ||
for (const key in object) { | ||
ret[key] = toProxyRef(object, key); | ||
ret[key] = toRef(object, key); | ||
} | ||
return ret; | ||
} | ||
function toProxyRef(object, key) { | ||
function toRef(object, key) { | ||
return { | ||
@@ -809,2 +792,3 @@ _isRef: true, | ||
exports.computed = computed; | ||
exports.customRef = customRef; | ||
exports.effect = effect; | ||
@@ -815,5 +799,3 @@ exports.enableTracking = enableTracking; | ||
exports.isRef = isRef; | ||
exports.lock = lock; | ||
exports.markNonReactive = markNonReactive; | ||
exports.markReadonly = markReadonly; | ||
exports.pauseTracking = pauseTracking; | ||
@@ -829,6 +811,6 @@ exports.reactive = reactive; | ||
exports.toRaw = toRaw; | ||
exports.toRef = toRef; | ||
exports.toRefs = toRefs; | ||
exports.track = track; | ||
exports.trigger = trigger; | ||
exports.unlock = unlock; | ||
exports.unref = unref; | ||
@@ -835,0 +817,0 @@ |
@@ -1,1 +0,1 @@ | ||
var VueReactivity=function(e){"use strict";function t(e,t){const n=Object.create(null),r=e.split(",");for(let e=0;e<r.length;e++)n[r[e]]=!0;return t?e=>!!n[e.toLowerCase()]:e=>!!n[e]}const n={},r=()=>{},o=Object.prototype.hasOwnProperty,c=(e,t)=>o.call(e,t),s=Array.isArray,u=e=>"symbol"==typeof e,a=e=>null!==e&&"object"==typeof e,i=Object.prototype.toString,l=e=>(e=>i.call(e))(e).slice(8,-1),f=(e,t)=>e!==t&&(e==e||t==t),d=new WeakMap,h=[];let p;const g=Symbol(""),v=Symbol("");function y(e,t=n){(function(e){return e&&!0===e._isEffect})(e)&&(e=e.raw);const r=function(e,t){const n=function(...r){if(!n.active)return t.scheduler?void 0:e(...r);if(!h.includes(n)){w(n);try{return S(),h.push(n),p=n,e(...r)}finally{h.pop(),b(),p=h[h.length-1]}}};return n._isEffect=!0,n.active=!0,n.raw=e,n.deps=[],n.options=t,n}(e,t);return t.lazy||r(),r}function w(e){const{deps:t}=e;if(t.length){for(let n=0;n<t.length;n++)t[n].delete(e);t.length=0}}let R=!0;const k=[];function S(){k.push(R),R=!0}function b(){const e=k.pop();R=void 0===e||e}function m(e,t,n){if(!R||void 0===p)return;let r=d.get(e);void 0===r&&d.set(e,r=new Map);let o=r.get(n);void 0===o&&r.set(n,o=new Set),o.has(p)||(o.add(p),p.deps.push(o))}function E(e,t,n,r,o,c){const u=d.get(e);if(void 0===u)return;const a=new Set,i=new Set,l=e=>{void 0!==e&&e.forEach(e=>{e===p&&R||(e.options.computed?i.add(e):a.add(e))})};if("clear"===t)u.forEach(l);else if("length"===n&&s(e))u.forEach((e,t)=>{("length"===t||t>=r)&&l(e)});else{void 0!==n&&l(u.get(n));const r="add"===t||"delete"===t&&!s(e);(r||"set"===t&&e instanceof Map)&&l(u.get(s(e)?"length":g)),r&&e instanceof Map&&l(u.get(v))}const f=e=>{void 0!==e.options.scheduler?e.options.scheduler(e):e()};i.forEach(f),a.forEach(f)}let M=!0;const O=new Set(Object.getOwnPropertyNames(Symbol).map(e=>Symbol[e]).filter(u)),W=x(),_=x(!1,!0),j=x(!0),z=x(!0,!0),P={};function x(e=!1,t=!1){return function(n,r,o){if(s(n)&&c(P,r))return Reflect.get(P,r,o);const i=Reflect.get(n,r,o);return u(r)&&O.has(r)?i:t?(m(n,0,r),i):be(i)&&!s(n)?i.value:(m(n,0,r),a(i)?e?we(i):ye(i):i)}}["includes","indexOf","lastIndexOf"].forEach(e=>{P[e]=function(...t){const n=ke(this);for(let e=0,t=this.length;e<t;e++)m(n,0,e+"");const r=n[e](...t);return-1===r||!1===r?n[e](...t.map(ke)):r}});const T=V(),A=V(!1,!0),K=V(!0),N=V(!0,!0);function V(e=!1,t=!1){return function(n,r,o,u){if(e&&M)return!0;const a=n[r];if(!t&&(o=ke(o),!s(n)&&be(a)&&!be(o)))return a.value=o,!0;const i=c(n,r),l=Reflect.set(n,r,o,u);return n===ke(u)&&(i?f(o,a)&&E(n,"set",r,o):E(n,"add",r,o)),l}}function I(e,t){const n=c(e,t),r=Reflect.deleteProperty(e,t);return r&&n&&E(e,"delete",t,void 0),r}function C(e,t){const n=Reflect.has(e,t);return m(e,0,t),n}function F(e){return m(e,0,g),Reflect.ownKeys(e)}const L={get:W,set:T,deleteProperty:I,has:C,ownKeys:F},Y={get:j,set:K,has:C,ownKeys:F,deleteProperty:(e,t)=>!!M||I(e,t)},q={...L,get:_,set:A},B={...Y,get:z,set:N},D=e=>a(e)?ye(e):e,G=e=>a(e)?we(e):e,H=e=>Reflect.getPrototypeOf(e);function J(e,t,n){e=ke(e);const r=ke(t);t!==r&&m(e,0,t),m(e,0,r);const{has:o,get:c}=H(e);return o.call(e,t)?n(c.call(e,t)):o.call(e,r)?n(c.call(e,r)):void 0}function Q(e){const t=ke(this),n=ke(e);e!==n&&m(t,0,e),m(t,0,n);const r=H(t).has;return r.call(t,e)||r.call(t,n)}function U(e){return m(e=ke(e),0,g),Reflect.get(H(e),"size",e)}function X(e){e=ke(e);const t=ke(this),n=H(t),r=n.has.call(t,e),o=n.add.call(t,e);return r||E(t,"add",e,e),o}function Z(e,t){t=ke(t);const n=ke(this),{has:r,get:o,set:c}=H(n);let s=r.call(n,e);s||(e=ke(e),s=r.call(n,e));const u=o.call(n,e),a=c.call(n,e,t);return s?f(t,u)&&E(n,"set",e,t):E(n,"add",e,t),a}function $(e){const t=ke(this),{has:n,get:r,delete:o}=H(t);let c=n.call(t,e);c||(e=ke(e),c=n.call(t,e));r&&r.call(t,e);const s=o.call(t,e);return c&&E(t,"delete",e,void 0),s}function ee(){const e=ke(this),t=0!==e.size,n=H(e).clear.call(e);return t&&E(e,"clear",void 0,void 0),n}function te(e){return function(t,n){const r=this,o=ke(r),c=e?G:D;return m(o,0,g),H(o).forEach.call(o,(function(e,n){return t.call(r,c(e),c(n),r)}),n)}}function ne(e,t){return function(...n){const r=ke(this),o=r instanceof Map,c="entries"===e||e===Symbol.iterator&&o,s="keys"===e&&o,u=H(r)[e].apply(r,n),a=t?G:D;return m(r,0,s?v:g),{next(){const{value:e,done:t}=u.next();return t?{value:e,done:t}:{value:c?[a(e[0]),a(e[1])]:a(e),done:t}},[Symbol.iterator](){return this}}}}function re(e,t){return function(...n){return M?"delete"!==t&&this:e.apply(this,n)}}const oe={get(e){return J(this,e,D)},get size(){return U(this)},has:Q,add:X,set:Z,delete:$,clear:ee,forEach:te(!1)},ce={get(e){return J(this,e,G)},get size(){return U(this)},has:Q,add:re(X,"add"),set:re(Z,"set"),delete:re($,"delete"),clear:re(ee,"clear"),forEach:te(!0)};function se(e){return(t,n,r)=>Reflect.get(c(e,n)&&n in t?e:t,n,r)}["keys","values","entries",Symbol.iterator].forEach(e=>{oe[e]=ne(e,!1),ce[e]=ne(e,!0)});const ue={get:se(oe)},ae={get:se(ce)},ie=new WeakMap,le=new WeakMap,fe=new WeakMap,de=new WeakMap,he=new WeakSet,pe=new WeakSet,ge=new Set([Set,Map,WeakMap,WeakSet]),ve=t("Object,Array,Map,Set,WeakMap,WeakSet");function ye(e){return de.has(e)?e:he.has(e)?we(e):be(e)?e:Re(e,ie,le,L,ue)}function we(e){return le.has(e)&&(e=le.get(e)),Re(e,fe,de,Y,ae)}function Re(e,t,n,r,o){if(!a(e))return e;let c=t.get(e);if(void 0!==c)return c;if(n.has(e))return e;if((s=e)._isVue||s._isVNode||!ve(l(s))||pe.has(s)||Object.isFrozen(s))return e;var s;const u=ge.has(e.constructor)?o:r;return c=new Proxy(e,u),t.set(e,c),n.set(c,e),c}function ke(e){return le.get(e)||de.get(e)||e}const Se=e=>a(e)?ye(e):e;function be(e){return!!e&&!0===e._isRef}function me(e,t=!1){if(be(e))return e;t||(e=Se(e));const n={_isRef:!0,get value(){return m(n,0,"value"),e},set value(r){e=t?r:Se(r),E(n,"set","value",void 0)}};return n}function Ee(e,t){return{_isRef:!0,get value(){return e[t]},set value(n){e[t]=n}}}return e.ITERATE_KEY=g,e.computed=function(e){let t,n;"function"==typeof e?(t=e,n=r):(t=e.get,n=e.set);let o,c,s=!0;const u=y(t,{lazy:!0,computed:!0,scheduler:()=>{s||(s=!0,E(c,"set","value"))}});return c={_isRef:!0,effect:u,get value(){return s&&(o=u(),s=!1),m(c,0,"value"),o},set value(e){n(e)}},c},e.effect=y,e.enableTracking=S,e.isReactive=function(e){return le.has(e)||de.has(e)},e.isReadonly=function(e){return de.has(e)},e.isRef=be,e.lock=function(){M=!0},e.markNonReactive=function(e){return pe.add(e),e},e.markReadonly=function(e){return he.add(e),e},e.pauseTracking=function(){k.push(R),R=!1},e.reactive=ye,e.readonly=we,e.ref=function(e){return me(e)},e.resetTracking=b,e.shallowReactive=function(e){return Re(e,ie,le,q,ue)},e.shallowReadonly=function(e){return Re(e,fe,de,B,ae)},e.shallowRef=function(e){return me(e,!0)},e.stop=function(e){e.active&&(w(e),e.options.onStop&&e.options.onStop(),e.active=!1)},e.toRaw=ke,e.toRefs=function(e){const t={};for(const n in e)t[n]=Ee(e,n);return t},e.track=m,e.trigger=E,e.unlock=function(){M=!1},e.unref=function(e){return be(e)?e.value:e},e}({}); | ||
var VueReactivity=function(e){"use strict";function t(e,t){const n=Object.create(null),r=e.split(",");for(let e=0;e<r.length;e++)n[r[e]]=!0;return t?e=>!!n[e.toLowerCase()]:e=>!!n[e]}const n={},r=()=>{},o=Object.prototype.hasOwnProperty,c=(e,t)=>o.call(e,t),s=Array.isArray,u=e=>"symbol"==typeof e,a=e=>null!==e&&"object"==typeof e,i=Object.prototype.toString,l=e=>(e=>i.call(e))(e).slice(8,-1),f=(e,t)=>e!==t&&(e==e||t==t),d=new WeakMap,h=[];let p;const g=Symbol(""),v=Symbol("");function y(e,t=n){(function(e){return e&&!0===e._isEffect})(e)&&(e=e.raw);const r=function(e,t){const n=function(...r){if(!n.active)return t.scheduler?void 0:e(...r);if(!h.includes(n)){w(n);try{return b(),h.push(n),p=n,e(...r)}finally{h.pop(),m(),p=h[h.length-1]}}};return n.id=R++,n._isEffect=!0,n.active=!0,n.raw=e,n.deps=[],n.options=t,n}(e,t);return t.lazy||r(),r}let R=0;function w(e){const{deps:t}=e;if(t.length){for(let n=0;n<t.length;n++)t[n].delete(e);t.length=0}}let S=!0;const k=[];function b(){k.push(S),S=!0}function m(){const e=k.pop();S=void 0===e||e}function E(e,t,n){if(!S||void 0===p)return;let r=d.get(e);void 0===r&&d.set(e,r=new Map);let o=r.get(n);void 0===o&&r.set(n,o=new Set),o.has(p)||(o.add(p),p.deps.push(o))}function M(e,t,n,r,o,c){const u=d.get(e);if(void 0===u)return;const a=new Set,i=new Set,l=e=>{void 0!==e&&e.forEach(e=>{e===p&&S||(e.options.computed?i.add(e):a.add(e))})};if("clear"===t)u.forEach(l);else if("length"===n&&s(e))u.forEach((e,t)=>{("length"===t||t>=r)&&l(e)});else{void 0!==n&&l(u.get(n));const r="add"===t||"delete"===t&&!s(e);(r||"set"===t&&e instanceof Map)&&l(u.get(s(e)?"length":g)),r&&e instanceof Map&&l(u.get(v))}const f=e=>{void 0!==e.options.scheduler?e.options.scheduler(e):e()};i.forEach(f),a.forEach(f)}const O=new Set(Object.getOwnPropertyNames(Symbol).map(e=>Symbol[e]).filter(u)),W=x(),_=x(!1,!0),j=x(!0),z=x(!0,!0),P={};function x(e=!1,t=!1){return function(n,r,o){const i=s(n);if(i&&c(P,r))return Reflect.get(P,r,o);const l=Reflect.get(n,r,o);return u(r)&&O.has(r)?l:t?(!e&&E(n,0,r),l):pe(l)?i?(!e&&E(n,0,r),l):l.value:(!e&&E(n,0,r),a(l)?e?le(l):ie(l):l)}}["includes","indexOf","lastIndexOf"].forEach(e=>{P[e]=function(...t){const n=de(this);for(let e=0,t=this.length;e<t;e++)E(n,0,e+"");const r=n[e](...t);return-1===r||!1===r?n[e](...t.map(de)):r}});const T=K(),A=K(!0);function K(e=!1){return function(t,n,r,o){const u=t[n];if(!e&&(r=de(r),!s(t)&&pe(u)&&!pe(r)))return u.value=r,!0;const a=c(t,n),i=Reflect.set(t,n,r,o);return t===de(o)&&(a?f(r,u)&&M(t,"set",n,r):M(t,"add",n,r)),i}}function N(e,t){const n=Reflect.has(e,t);return E(e,0,t),n}function V(e){return E(e,0,g),Reflect.ownKeys(e)}const I={get:W,set:T,deleteProperty:function(e,t){const n=c(e,t),r=Reflect.deleteProperty(e,t);return r&&n&&M(e,"delete",t,void 0),r},has:N,ownKeys:V},C={get:j,has:N,ownKeys:V,set:(e,t)=>!0,deleteProperty:(e,t)=>!0},F={...I,get:_,set:A},L={...C,get:z},Y=e=>a(e)?ie(e):e,q=e=>a(e)?le(e):e,B=e=>Reflect.getPrototypeOf(e);function D(e,t,n){e=de(e);const r=de(t);t!==r&&E(e,0,t),E(e,0,r);const{has:o,get:c}=B(e);return o.call(e,t)?n(c.call(e,t)):o.call(e,r)?n(c.call(e,r)):void 0}function G(e){const t=de(this),n=de(e);e!==n&&E(t,0,e),E(t,0,n);const r=B(t).has;return r.call(t,e)||r.call(t,n)}function H(e){return E(e=de(e),0,g),Reflect.get(B(e),"size",e)}function J(e){return function(t,n){const r=this,o=de(r),c=e?q:Y;return!e&&E(o,0,g),B(o).forEach.call(o,(function(e,n){return t.call(r,c(e),c(n),r)}),n)}}function Q(e,t){return function(...n){const r=de(this),o=r instanceof Map,c="entries"===e||e===Symbol.iterator&&o,s="keys"===e&&o,u=B(r)[e].apply(r,n),a=t?q:Y;return!t&&E(r,0,s?v:g),{next(){const{value:e,done:t}=u.next();return t?{value:e,done:t}:{value:c?[a(e[0]),a(e[1])]:a(e),done:t}},[Symbol.iterator](){return this}}}}function U(e){return function(...t){return"delete"!==e&&this}}const X={get(e){return D(this,e,Y)},get size(){return H(this)},has:G,add:function(e){e=de(e);const t=de(this),n=B(t),r=n.has.call(t,e),o=n.add.call(t,e);return r||M(t,"add",e,e),o},set:function(e,t){t=de(t);const n=de(this),{has:r,get:o,set:c}=B(n);let s=r.call(n,e);s||(e=de(e),s=r.call(n,e));const u=o.call(n,e),a=c.call(n,e,t);return s?f(t,u)&&M(n,"set",e,t):M(n,"add",e,t),a},delete:function(e){const t=de(this),{has:n,get:r,delete:o}=B(t);let c=n.call(t,e);c||(e=de(e),c=n.call(t,e)),r&&r.call(t,e);const s=o.call(t,e);return c&&M(t,"delete",e,void 0),s},clear:function(){const e=de(this),t=0!==e.size,n=B(e).clear.call(e);return t&&M(e,"clear",void 0,void 0),n},forEach:J(!1)},Z={get(e){return D(this,e,q)},get size(){return H(this)},has:G,add:U("add"),set:U("set"),delete:U("delete"),clear:U("clear"),forEach:J(!0)};function $(e){return(t,n,r)=>Reflect.get(c(e,n)&&n in t?e:t,n,r)}["keys","values","entries",Symbol.iterator].forEach(e=>{X[e]=Q(e,!1),Z[e]=Q(e,!0)});const ee={get:$(X)},te={get:$(Z)},ne=new WeakMap,re=new WeakMap,oe=new WeakMap,ce=new WeakMap,se=new WeakSet,ue=new Set([Set,Map,WeakMap,WeakSet]),ae=t("Object,Array,Map,Set,WeakMap,WeakSet");function ie(e){return ce.has(e)?e:fe(e,ne,re,I,ee)}function le(e){return fe(e,oe,ce,C,te)}function fe(e,t,n,r,o){if(!a(e))return e;let c=t.get(e);if(void 0!==c)return c;if(n.has(e))return e;if((s=e)._isVue||s._isVNode||!ae(l(s))||se.has(s)||Object.isFrozen(s))return e;var s;const u=ue.has(e.constructor)?o:r;return c=new Proxy(e,u),t.set(e,c),n.set(c,e),c}function de(e){return e=ce.get(e)||e,re.get(e)||e}const he=e=>a(e)?ie(e):e;function pe(e){return!!e&&!0===e._isRef}function ge(e,t=!1){if(pe(e))return e;t||(e=he(e));const n={_isRef:!0,get value(){return E(n,0,"value"),e},set value(r){e=t?r:he(r),M(n,"set","value",void 0)}};return n}function ve(e,t){return{_isRef:!0,get value(){return e[t]},set value(n){e[t]=n}}}return e.ITERATE_KEY=g,e.computed=function(e){let t,n;"function"==typeof e?(t=e,n=r):(t=e.get,n=e.set);let o,c,s=!0;const u=y(t,{lazy:!0,computed:!0,scheduler:()=>{s||(s=!0,M(c,"set","value"))}});return c={_isRef:!0,effect:u,get value(){return s&&(o=u(),s=!1),E(c,0,"value"),o},set value(e){n(e)}},c},e.customRef=function(e){const{get:t,set:n}=e(()=>E(r,0,"value"),()=>M(r,"set","value")),r={_isRef:!0,get value(){return t()},set value(e){n(e)}};return r},e.effect=y,e.enableTracking=b,e.isReactive=function(e){return re.has(e)||ce.has(e)},e.isReadonly=function(e){return ce.has(e)},e.isRef=pe,e.markNonReactive=function(e){return se.add(e),e},e.pauseTracking=function(){k.push(S),S=!1},e.reactive=ie,e.readonly=le,e.ref=function(e){return ge(e)},e.resetTracking=m,e.shallowReactive=function(e){return fe(e,ne,re,F,ee)},e.shallowReadonly=function(e){return fe(e,oe,ce,L,te)},e.shallowRef=function(e){return ge(e,!0)},e.stop=function(e){e.active&&(w(e),e.options.onStop&&e.options.onStop(),e.active=!1)},e.toRaw=de,e.toRef=ve,e.toRefs=function(e){const t={};for(const n in e)t[n]=ve(e,n);return t},e.track=E,e.trigger=M,e.unref=function(e){return pe(e)?e.value:e},e}({}); |
{ | ||
"name": "@vue/reactivity", | ||
"version": "3.0.0-alpha.12", | ||
"version": "3.0.0-alpha.13", | ||
"description": "@vue/reactivity", | ||
@@ -37,4 +37,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"@vue/shared": "3.0.0-alpha.12" | ||
"@vue/shared": "3.0.0-alpha.13" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
147901
3925
+ Added@vue/shared@3.0.0-alpha.13(transitive)
- Removed@vue/shared@3.0.0-alpha.12(transitive)
Updated@vue/shared@3.0.0-alpha.13