@yiin/reactive-proxy-state 1.0.39 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +50 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +50 -4
- package/dist/reactive.d.ts +0 -5
- package/dist/utils.d.ts +10 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2362,6 +2362,35 @@ __export(exports_src, {
|
|
|
2362
2362
|
module.exports = __toCommonJS(exports_src);
|
|
2363
2363
|
|
|
2364
2364
|
// src/utils.ts
|
|
2365
|
+
function toRaw(observed) {
|
|
2366
|
+
let value = observed;
|
|
2367
|
+
while (value && value["__v_raw" /* RAW */]) {
|
|
2368
|
+
value = value["__v_raw" /* RAW */];
|
|
2369
|
+
}
|
|
2370
|
+
return value;
|
|
2371
|
+
}
|
|
2372
|
+
function unwrapForStore(value) {
|
|
2373
|
+
if (value["__v_isReactive" /* IS_REACTIVE */])
|
|
2374
|
+
return toRaw(value);
|
|
2375
|
+
if (Array.isArray(value)) {
|
|
2376
|
+
for (let i = 0;i < value.length; i++) {
|
|
2377
|
+
const child = value[i];
|
|
2378
|
+
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */]) {
|
|
2379
|
+
value[i] = toRaw(child);
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
} else if (!(value instanceof Map) && !(value instanceof Set) && !(value instanceof Date)) {
|
|
2383
|
+
for (const key in value) {
|
|
2384
|
+
if (!Object.prototype.hasOwnProperty.call(value, key))
|
|
2385
|
+
continue;
|
|
2386
|
+
const child = value[key];
|
|
2387
|
+
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */]) {
|
|
2388
|
+
value[key] = toRaw(child);
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
return value;
|
|
2393
|
+
}
|
|
2365
2394
|
var deepEqualCache = new WeakMap;
|
|
2366
2395
|
var MAX_CACHE_SIZE = 1000;
|
|
2367
2396
|
var pathCache = new WeakMap;
|
|
@@ -2392,6 +2421,7 @@ function resetProxyStats() {
|
|
|
2392
2421
|
function evictDeep(value) {
|
|
2393
2422
|
if (value == null || typeof value !== "object")
|
|
2394
2423
|
return;
|
|
2424
|
+
value = toRaw(value);
|
|
2395
2425
|
if (!globalSeen.has(value))
|
|
2396
2426
|
return;
|
|
2397
2427
|
globalSeen.delete(value);
|
|
@@ -3047,6 +3077,10 @@ function wrapSet(set, emit, path = []) {
|
|
|
3047
3077
|
const methodCache = {};
|
|
3048
3078
|
const proxy = new Proxy(set, {
|
|
3049
3079
|
get(target, prop, receiver) {
|
|
3080
|
+
if (prop === "__v_raw" /* RAW */)
|
|
3081
|
+
return target;
|
|
3082
|
+
if (prop === "__v_isReactive" /* IS_REACTIVE */)
|
|
3083
|
+
return true;
|
|
3050
3084
|
track(target, prop);
|
|
3051
3085
|
if (prop === Symbol.iterator || prop === "entries" || prop === "values" || prop === "keys" || prop === "forEach") {
|
|
3052
3086
|
track(target, Symbol.iterator);
|
|
@@ -3056,6 +3090,8 @@ function wrapSet(set, emit, path = []) {
|
|
|
3056
3090
|
}
|
|
3057
3091
|
if (prop === "add") {
|
|
3058
3092
|
methodCache[prop] = function(value2) {
|
|
3093
|
+
if (value2 != null && typeof value2 === "object")
|
|
3094
|
+
value2 = unwrapForStore(value2);
|
|
3059
3095
|
const existed = target.has(value2);
|
|
3060
3096
|
const oldSize = target.size;
|
|
3061
3097
|
if (!existed) {
|
|
@@ -3224,6 +3260,10 @@ function wrapMap(map, emit, path = []) {
|
|
|
3224
3260
|
const methodCache = {};
|
|
3225
3261
|
const proxy = new Proxy(map, {
|
|
3226
3262
|
get(target, prop, receiver) {
|
|
3263
|
+
if (prop === "__v_raw" /* RAW */)
|
|
3264
|
+
return target;
|
|
3265
|
+
if (prop === "__v_isReactive" /* IS_REACTIVE */)
|
|
3266
|
+
return true;
|
|
3227
3267
|
track(target, prop);
|
|
3228
3268
|
if (prop === Symbol.iterator || prop === "entries" || prop === "values" || prop === "keys" || prop === "forEach") {
|
|
3229
3269
|
track(target, Symbol.iterator);
|
|
@@ -3233,6 +3273,8 @@ function wrapMap(map, emit, path = []) {
|
|
|
3233
3273
|
}
|
|
3234
3274
|
if (prop === "set") {
|
|
3235
3275
|
methodCache[prop] = function(key, value2) {
|
|
3276
|
+
if (value2 != null && typeof value2 === "object")
|
|
3277
|
+
value2 = unwrapForStore(value2);
|
|
3236
3278
|
const existed = target.has(key);
|
|
3237
3279
|
const oldValue = target.get(key);
|
|
3238
3280
|
const oldSize = target.size;
|
|
@@ -3470,6 +3512,10 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3470
3512
|
const methodCache = {};
|
|
3471
3513
|
const proxy = new Proxy(arr, {
|
|
3472
3514
|
get(target, prop, receiver) {
|
|
3515
|
+
if (prop === "__v_raw" /* RAW */)
|
|
3516
|
+
return target;
|
|
3517
|
+
if (prop === "__v_isReactive" /* IS_REACTIVE */)
|
|
3518
|
+
return true;
|
|
3473
3519
|
track(target, prop);
|
|
3474
3520
|
if (methodCache[prop]) {
|
|
3475
3521
|
return methodCache[prop];
|
|
@@ -3729,6 +3775,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3729
3775
|
return value;
|
|
3730
3776
|
},
|
|
3731
3777
|
set(target, prop, value, receiver) {
|
|
3778
|
+
if (isObject2(value))
|
|
3779
|
+
value = unwrapForStore(value);
|
|
3732
3780
|
const oldValue = target[prop];
|
|
3733
3781
|
if (oldValue === value)
|
|
3734
3782
|
return true;
|
|
@@ -3774,10 +3822,6 @@ function isObject3(v) {
|
|
|
3774
3822
|
function isReactive(value) {
|
|
3775
3823
|
return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
|
|
3776
3824
|
}
|
|
3777
|
-
function toRaw(observed) {
|
|
3778
|
-
const raw = observed && observed["__v_raw" /* RAW */];
|
|
3779
|
-
return raw ? toRaw(raw) : observed;
|
|
3780
|
-
}
|
|
3781
3825
|
function createAsyncEmit(emit) {
|
|
3782
3826
|
const queue = [];
|
|
3783
3827
|
let flushScheduled = false;
|
|
@@ -3862,6 +3906,8 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3862
3906
|
return wrapValue(value, newPath);
|
|
3863
3907
|
},
|
|
3864
3908
|
set(target, prop, value, receiver) {
|
|
3909
|
+
if (isObject3(value))
|
|
3910
|
+
value = unwrapForStore(value);
|
|
3865
3911
|
const oldValue = target[prop];
|
|
3866
3912
|
if (oldValue === value)
|
|
3867
3913
|
return true;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './types';
|
|
2
|
-
export { deepClone, deepEqual, getProxyStats, resetProxyStats } from './utils';
|
|
2
|
+
export { deepClone, deepEqual, getProxyStats, resetProxyStats, toRaw } from './utils';
|
|
3
3
|
export * from './state';
|
|
4
4
|
export * from './reactive';
|
|
5
5
|
export * from './watch';
|
package/dist/index.js
CHANGED
|
@@ -2300,6 +2300,35 @@ var require_reactivity_cjs = __commonJS((exports) => {
|
|
|
2300
2300
|
exports.watch = watch2;
|
|
2301
2301
|
});
|
|
2302
2302
|
// src/utils.ts
|
|
2303
|
+
function toRaw(observed) {
|
|
2304
|
+
let value = observed;
|
|
2305
|
+
while (value && value["__v_raw" /* RAW */]) {
|
|
2306
|
+
value = value["__v_raw" /* RAW */];
|
|
2307
|
+
}
|
|
2308
|
+
return value;
|
|
2309
|
+
}
|
|
2310
|
+
function unwrapForStore(value) {
|
|
2311
|
+
if (value["__v_isReactive" /* IS_REACTIVE */])
|
|
2312
|
+
return toRaw(value);
|
|
2313
|
+
if (Array.isArray(value)) {
|
|
2314
|
+
for (let i = 0;i < value.length; i++) {
|
|
2315
|
+
const child = value[i];
|
|
2316
|
+
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */]) {
|
|
2317
|
+
value[i] = toRaw(child);
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
} else if (!(value instanceof Map) && !(value instanceof Set) && !(value instanceof Date)) {
|
|
2321
|
+
for (const key in value) {
|
|
2322
|
+
if (!Object.prototype.hasOwnProperty.call(value, key))
|
|
2323
|
+
continue;
|
|
2324
|
+
const child = value[key];
|
|
2325
|
+
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */]) {
|
|
2326
|
+
value[key] = toRaw(child);
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
return value;
|
|
2331
|
+
}
|
|
2303
2332
|
var deepEqualCache = new WeakMap;
|
|
2304
2333
|
var MAX_CACHE_SIZE = 1000;
|
|
2305
2334
|
var pathCache = new WeakMap;
|
|
@@ -2330,6 +2359,7 @@ function resetProxyStats() {
|
|
|
2330
2359
|
function evictDeep(value) {
|
|
2331
2360
|
if (value == null || typeof value !== "object")
|
|
2332
2361
|
return;
|
|
2362
|
+
value = toRaw(value);
|
|
2333
2363
|
if (!globalSeen.has(value))
|
|
2334
2364
|
return;
|
|
2335
2365
|
globalSeen.delete(value);
|
|
@@ -2985,6 +3015,10 @@ function wrapSet(set, emit, path = []) {
|
|
|
2985
3015
|
const methodCache = {};
|
|
2986
3016
|
const proxy = new Proxy(set, {
|
|
2987
3017
|
get(target, prop, receiver) {
|
|
3018
|
+
if (prop === "__v_raw" /* RAW */)
|
|
3019
|
+
return target;
|
|
3020
|
+
if (prop === "__v_isReactive" /* IS_REACTIVE */)
|
|
3021
|
+
return true;
|
|
2988
3022
|
track(target, prop);
|
|
2989
3023
|
if (prop === Symbol.iterator || prop === "entries" || prop === "values" || prop === "keys" || prop === "forEach") {
|
|
2990
3024
|
track(target, Symbol.iterator);
|
|
@@ -2994,6 +3028,8 @@ function wrapSet(set, emit, path = []) {
|
|
|
2994
3028
|
}
|
|
2995
3029
|
if (prop === "add") {
|
|
2996
3030
|
methodCache[prop] = function(value2) {
|
|
3031
|
+
if (value2 != null && typeof value2 === "object")
|
|
3032
|
+
value2 = unwrapForStore(value2);
|
|
2997
3033
|
const existed = target.has(value2);
|
|
2998
3034
|
const oldSize = target.size;
|
|
2999
3035
|
if (!existed) {
|
|
@@ -3162,6 +3198,10 @@ function wrapMap(map, emit, path = []) {
|
|
|
3162
3198
|
const methodCache = {};
|
|
3163
3199
|
const proxy = new Proxy(map, {
|
|
3164
3200
|
get(target, prop, receiver) {
|
|
3201
|
+
if (prop === "__v_raw" /* RAW */)
|
|
3202
|
+
return target;
|
|
3203
|
+
if (prop === "__v_isReactive" /* IS_REACTIVE */)
|
|
3204
|
+
return true;
|
|
3165
3205
|
track(target, prop);
|
|
3166
3206
|
if (prop === Symbol.iterator || prop === "entries" || prop === "values" || prop === "keys" || prop === "forEach") {
|
|
3167
3207
|
track(target, Symbol.iterator);
|
|
@@ -3171,6 +3211,8 @@ function wrapMap(map, emit, path = []) {
|
|
|
3171
3211
|
}
|
|
3172
3212
|
if (prop === "set") {
|
|
3173
3213
|
methodCache[prop] = function(key, value2) {
|
|
3214
|
+
if (value2 != null && typeof value2 === "object")
|
|
3215
|
+
value2 = unwrapForStore(value2);
|
|
3174
3216
|
const existed = target.has(key);
|
|
3175
3217
|
const oldValue = target.get(key);
|
|
3176
3218
|
const oldSize = target.size;
|
|
@@ -3408,6 +3450,10 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3408
3450
|
const methodCache = {};
|
|
3409
3451
|
const proxy = new Proxy(arr, {
|
|
3410
3452
|
get(target, prop, receiver) {
|
|
3453
|
+
if (prop === "__v_raw" /* RAW */)
|
|
3454
|
+
return target;
|
|
3455
|
+
if (prop === "__v_isReactive" /* IS_REACTIVE */)
|
|
3456
|
+
return true;
|
|
3411
3457
|
track(target, prop);
|
|
3412
3458
|
if (methodCache[prop]) {
|
|
3413
3459
|
return methodCache[prop];
|
|
@@ -3667,6 +3713,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3667
3713
|
return value;
|
|
3668
3714
|
},
|
|
3669
3715
|
set(target, prop, value, receiver) {
|
|
3716
|
+
if (isObject2(value))
|
|
3717
|
+
value = unwrapForStore(value);
|
|
3670
3718
|
const oldValue = target[prop];
|
|
3671
3719
|
if (oldValue === value)
|
|
3672
3720
|
return true;
|
|
@@ -3712,10 +3760,6 @@ function isObject3(v) {
|
|
|
3712
3760
|
function isReactive(value) {
|
|
3713
3761
|
return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
|
|
3714
3762
|
}
|
|
3715
|
-
function toRaw(observed) {
|
|
3716
|
-
const raw = observed && observed["__v_raw" /* RAW */];
|
|
3717
|
-
return raw ? toRaw(raw) : observed;
|
|
3718
|
-
}
|
|
3719
3763
|
function createAsyncEmit(emit) {
|
|
3720
3764
|
const queue = [];
|
|
3721
3765
|
let flushScheduled = false;
|
|
@@ -3800,6 +3844,8 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3800
3844
|
return wrapValue(value, newPath);
|
|
3801
3845
|
},
|
|
3802
3846
|
set(target, prop, value, receiver) {
|
|
3847
|
+
if (isObject3(value))
|
|
3848
|
+
value = unwrapForStore(value);
|
|
3803
3849
|
const oldValue = target[prop];
|
|
3804
3850
|
if (oldValue === value)
|
|
3805
3851
|
return true;
|
package/dist/reactive.d.ts
CHANGED
|
@@ -3,11 +3,6 @@ import { EmitFunction, Path, ReactiveOptions } from "./types";
|
|
|
3
3
|
* Checks if an object is a reactive proxy
|
|
4
4
|
*/
|
|
5
5
|
export declare function isReactive(value: any): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Returns the raw, original object underlying a reactive proxy.
|
|
8
|
-
* If the input is not a proxy, returns the input itself.
|
|
9
|
-
*/
|
|
10
|
-
export declare function toRaw<T>(observed: T): T;
|
|
11
6
|
/**
|
|
12
7
|
* Create a reactive proxy for an object
|
|
13
8
|
*/
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the raw, original object underlying a reactive proxy.
|
|
3
|
+
* If the input is not a proxy, returns the input itself.
|
|
4
|
+
*/
|
|
5
|
+
export declare function toRaw<T>(observed: T): T;
|
|
6
|
+
/**
|
|
7
|
+
* Strip proxy refs from spread results before storing in raw state.
|
|
8
|
+
* Prevents unbounded proxy nesting from `{ ...reactiveProxy }` patterns.
|
|
9
|
+
*/
|
|
10
|
+
export declare function unwrapForStore(value: any): any;
|
|
1
11
|
export declare const pathCache: WeakMap<object, Map<string, any>>;
|
|
2
12
|
export declare const pathConcatCache: Map<string, any[]>;
|
|
3
13
|
export declare const globalSeen: WeakMap<any, any>;
|