@yiin/reactive-proxy-state 1.0.13 → 1.0.14
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.js +51 -51
- package/dist/reactive.d.ts +2 -2
- package/dist/wrap-array.d.ts +2 -2
- package/dist/wrap-map.d.ts +2 -2
- package/dist/wrap-set.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -539,12 +539,12 @@ function watchEffect(effectCallback, options = {}) {
|
|
|
539
539
|
}
|
|
540
540
|
|
|
541
541
|
// src/wrap-set.ts
|
|
542
|
-
function wrapSet(set, emit, path = []
|
|
542
|
+
function wrapSet(set, emit, path = []) {
|
|
543
543
|
const cachedProxy = wrapperCache.get(set);
|
|
544
544
|
if (cachedProxy)
|
|
545
545
|
return cachedProxy;
|
|
546
|
-
if (
|
|
547
|
-
return
|
|
546
|
+
if (globalSeen.has(set))
|
|
547
|
+
return globalSeen.get(set);
|
|
548
548
|
const methodCache = {};
|
|
549
549
|
const proxy = new Proxy(set, {
|
|
550
550
|
get(target, prop, receiver) {
|
|
@@ -657,8 +657,8 @@ function wrapSet(set, emit, path = [], seen = globalSeen) {
|
|
|
657
657
|
track(target, String(index));
|
|
658
658
|
let wrappedValue = valueToWrap;
|
|
659
659
|
if (valueToWrap && typeof valueToWrap === "object") {
|
|
660
|
-
if (
|
|
661
|
-
wrappedValue =
|
|
660
|
+
if (globalSeen.has(valueToWrap)) {
|
|
661
|
+
wrappedValue = globalSeen.get(valueToWrap);
|
|
662
662
|
} else {
|
|
663
663
|
const cachedValueProxy = wrapperCache.get(valueToWrap);
|
|
664
664
|
if (cachedValueProxy) {
|
|
@@ -672,15 +672,15 @@ function wrapSet(set, emit, path = [], seen = globalSeen) {
|
|
|
672
672
|
setPathConcat(pathKey, newPath);
|
|
673
673
|
}
|
|
674
674
|
if (valueToWrap instanceof Map)
|
|
675
|
-
wrappedValue = wrapMap(valueToWrap, emit, newPath
|
|
675
|
+
wrappedValue = wrapMap(valueToWrap, emit, newPath);
|
|
676
676
|
else if (valueToWrap instanceof Set)
|
|
677
|
-
wrappedValue = wrapSet(valueToWrap, emit, newPath
|
|
677
|
+
wrappedValue = wrapSet(valueToWrap, emit, newPath);
|
|
678
678
|
else if (Array.isArray(valueToWrap))
|
|
679
|
-
wrappedValue = wrapArray(valueToWrap, emit, newPath
|
|
679
|
+
wrappedValue = wrapArray(valueToWrap, emit, newPath);
|
|
680
680
|
else if (valueToWrap instanceof Date)
|
|
681
681
|
wrappedValue = new Date(valueToWrap.getTime());
|
|
682
682
|
else
|
|
683
|
-
wrappedValue = reactive(valueToWrap, emit, newPath
|
|
683
|
+
wrappedValue = reactive(valueToWrap, emit, newPath);
|
|
684
684
|
}
|
|
685
685
|
}
|
|
686
686
|
}
|
|
@@ -705,18 +705,18 @@ function wrapSet(set, emit, path = [], seen = globalSeen) {
|
|
|
705
705
|
return value;
|
|
706
706
|
}
|
|
707
707
|
});
|
|
708
|
-
|
|
708
|
+
globalSeen.set(set, proxy);
|
|
709
709
|
wrapperCache.set(set, proxy);
|
|
710
710
|
return proxy;
|
|
711
711
|
}
|
|
712
712
|
|
|
713
713
|
// src/wrap-map.ts
|
|
714
|
-
function wrapMap(map, emit, path = []
|
|
714
|
+
function wrapMap(map, emit, path = []) {
|
|
715
715
|
const cachedProxy = wrapperCache.get(map);
|
|
716
716
|
if (cachedProxy)
|
|
717
717
|
return cachedProxy;
|
|
718
|
-
if (
|
|
719
|
-
return
|
|
718
|
+
if (globalSeen.has(map))
|
|
719
|
+
return globalSeen.get(map);
|
|
720
720
|
const methodCache = {};
|
|
721
721
|
const proxy = new Proxy(map, {
|
|
722
722
|
get(target, prop, receiver) {
|
|
@@ -823,8 +823,8 @@ function wrapMap(map, emit, path = [], seen = globalSeen) {
|
|
|
823
823
|
const value2 = target.get(key);
|
|
824
824
|
if (!value2 || typeof value2 !== "object")
|
|
825
825
|
return value2;
|
|
826
|
-
if (
|
|
827
|
-
return
|
|
826
|
+
if (globalSeen.has(value2))
|
|
827
|
+
return globalSeen.get(value2);
|
|
828
828
|
const cachedValueProxy = wrapperCache.get(value2);
|
|
829
829
|
if (cachedValueProxy)
|
|
830
830
|
return cachedValueProxy;
|
|
@@ -836,14 +836,14 @@ function wrapMap(map, emit, path = [], seen = globalSeen) {
|
|
|
836
836
|
setPathConcat(pathKey, newPath);
|
|
837
837
|
}
|
|
838
838
|
if (value2 instanceof Map)
|
|
839
|
-
return wrapMap(value2, emit, newPath
|
|
839
|
+
return wrapMap(value2, emit, newPath);
|
|
840
840
|
if (value2 instanceof Set)
|
|
841
|
-
return wrapSet(value2, emit, newPath
|
|
841
|
+
return wrapSet(value2, emit, newPath);
|
|
842
842
|
if (Array.isArray(value2))
|
|
843
|
-
return wrapArray(value2, emit, newPath
|
|
843
|
+
return wrapArray(value2, emit, newPath);
|
|
844
844
|
if (value2 instanceof Date)
|
|
845
845
|
return new Date(value2.getTime());
|
|
846
|
-
return reactive(value2, emit, newPath
|
|
846
|
+
return reactive(value2, emit, newPath);
|
|
847
847
|
};
|
|
848
848
|
return methodCache[prop];
|
|
849
849
|
}
|
|
@@ -880,8 +880,8 @@ function wrapMap(map, emit, path = [], seen = globalSeen) {
|
|
|
880
880
|
}
|
|
881
881
|
let wrappedKey = keyToWrap;
|
|
882
882
|
if (isEntry && keyToWrap && typeof keyToWrap === "object") {
|
|
883
|
-
if (
|
|
884
|
-
wrappedKey =
|
|
883
|
+
if (globalSeen.has(keyToWrap)) {
|
|
884
|
+
wrappedKey = globalSeen.get(keyToWrap);
|
|
885
885
|
} else {
|
|
886
886
|
const pathKey = path.length > 0 ? `${path.join(".")}.${String(keyToWrap)}` : String(keyToWrap);
|
|
887
887
|
let keyPath = getPathConcat(pathKey);
|
|
@@ -889,13 +889,13 @@ function wrapMap(map, emit, path = [], seen = globalSeen) {
|
|
|
889
889
|
keyPath = path.concat(String(keyToWrap));
|
|
890
890
|
setPathConcat(pathKey, keyPath);
|
|
891
891
|
}
|
|
892
|
-
wrappedKey = reactive(keyToWrap, emit, keyPath
|
|
892
|
+
wrappedKey = reactive(keyToWrap, emit, keyPath);
|
|
893
893
|
}
|
|
894
894
|
}
|
|
895
895
|
let wrappedValue = valueToWrap;
|
|
896
896
|
if (valueToWrap && typeof valueToWrap === "object") {
|
|
897
|
-
if (
|
|
898
|
-
wrappedValue =
|
|
897
|
+
if (globalSeen.has(valueToWrap)) {
|
|
898
|
+
wrappedValue = globalSeen.get(valueToWrap);
|
|
899
899
|
} else {
|
|
900
900
|
const cachedValueProxy = wrapperCache.get(valueToWrap);
|
|
901
901
|
if (cachedValueProxy) {
|
|
@@ -909,15 +909,15 @@ function wrapMap(map, emit, path = [], seen = globalSeen) {
|
|
|
909
909
|
setPathConcat(pathKey, newPath);
|
|
910
910
|
}
|
|
911
911
|
if (valueToWrap instanceof Map)
|
|
912
|
-
wrappedValue = wrapMap(valueToWrap, emit, newPath
|
|
912
|
+
wrappedValue = wrapMap(valueToWrap, emit, newPath);
|
|
913
913
|
else if (valueToWrap instanceof Set)
|
|
914
|
-
wrappedValue = wrapSet(valueToWrap, emit, newPath
|
|
914
|
+
wrappedValue = wrapSet(valueToWrap, emit, newPath);
|
|
915
915
|
else if (Array.isArray(valueToWrap))
|
|
916
|
-
wrappedValue = wrapArray(valueToWrap, emit, newPath
|
|
916
|
+
wrappedValue = wrapArray(valueToWrap, emit, newPath);
|
|
917
917
|
else if (valueToWrap instanceof Date)
|
|
918
918
|
wrappedValue = new Date(valueToWrap.getTime());
|
|
919
919
|
else
|
|
920
|
-
wrappedValue = reactive(valueToWrap, emit, newPath
|
|
920
|
+
wrappedValue = reactive(valueToWrap, emit, newPath);
|
|
921
921
|
}
|
|
922
922
|
}
|
|
923
923
|
}
|
|
@@ -943,7 +943,7 @@ function wrapMap(map, emit, path = [], seen = globalSeen) {
|
|
|
943
943
|
return value;
|
|
944
944
|
}
|
|
945
945
|
});
|
|
946
|
-
|
|
946
|
+
globalSeen.set(map, proxy);
|
|
947
947
|
wrapperCache.set(map, proxy);
|
|
948
948
|
return proxy;
|
|
949
949
|
}
|
|
@@ -952,12 +952,12 @@ function wrapMap(map, emit, path = [], seen = globalSeen) {
|
|
|
952
952
|
function isObject2(v) {
|
|
953
953
|
return v && typeof v === "object";
|
|
954
954
|
}
|
|
955
|
-
function wrapArray(arr, emit, path = []
|
|
955
|
+
function wrapArray(arr, emit, path = []) {
|
|
956
956
|
const cachedProxy = wrapperCache.get(arr);
|
|
957
957
|
if (cachedProxy)
|
|
958
958
|
return cachedProxy;
|
|
959
|
-
if (
|
|
960
|
-
return
|
|
959
|
+
if (globalSeen.has(arr))
|
|
960
|
+
return globalSeen.get(arr);
|
|
961
961
|
const methodCache = {};
|
|
962
962
|
const proxy = new Proxy(arr, {
|
|
963
963
|
get(target, prop, receiver) {
|
|
@@ -1111,8 +1111,8 @@ function wrapArray(arr, emit, path = [], seen = globalSeen) {
|
|
|
1111
1111
|
track(target, String(prop));
|
|
1112
1112
|
if (!isObject2(value))
|
|
1113
1113
|
return value;
|
|
1114
|
-
if (
|
|
1115
|
-
return
|
|
1114
|
+
if (globalSeen.has(value))
|
|
1115
|
+
return globalSeen.get(value);
|
|
1116
1116
|
const cachedValueProxy = wrapperCache.get(value);
|
|
1117
1117
|
if (cachedValueProxy)
|
|
1118
1118
|
return cachedValueProxy;
|
|
@@ -1124,14 +1124,14 @@ function wrapArray(arr, emit, path = [], seen = globalSeen) {
|
|
|
1124
1124
|
setPathConcat(pathKey, newPath);
|
|
1125
1125
|
}
|
|
1126
1126
|
if (Array.isArray(value))
|
|
1127
|
-
return wrapArray(value, emit, newPath
|
|
1127
|
+
return wrapArray(value, emit, newPath);
|
|
1128
1128
|
if (value instanceof Map)
|
|
1129
|
-
return wrapMap(value, emit, newPath
|
|
1129
|
+
return wrapMap(value, emit, newPath);
|
|
1130
1130
|
if (value instanceof Set)
|
|
1131
|
-
return wrapSet(value, emit, newPath
|
|
1131
|
+
return wrapSet(value, emit, newPath);
|
|
1132
1132
|
if (value instanceof Date)
|
|
1133
1133
|
return new Date(value.getTime());
|
|
1134
|
-
return reactive(value, emit, newPath
|
|
1134
|
+
return reactive(value, emit, newPath);
|
|
1135
1135
|
}
|
|
1136
1136
|
if (typeof value === "function") {
|
|
1137
1137
|
return value.bind(target);
|
|
@@ -1167,7 +1167,7 @@ function wrapArray(arr, emit, path = [], seen = globalSeen) {
|
|
|
1167
1167
|
return result;
|
|
1168
1168
|
}
|
|
1169
1169
|
});
|
|
1170
|
-
|
|
1170
|
+
globalSeen.set(arr, proxy);
|
|
1171
1171
|
wrapperCache.set(arr, proxy);
|
|
1172
1172
|
return proxy;
|
|
1173
1173
|
}
|
|
@@ -1191,9 +1191,9 @@ function toRaw(observed) {
|
|
|
1191
1191
|
const raw = observed && observed["__v_raw" /* RAW */];
|
|
1192
1192
|
return raw ? toRaw(raw) : observed;
|
|
1193
1193
|
}
|
|
1194
|
-
function reactive(obj, emit, path = []
|
|
1195
|
-
if (
|
|
1196
|
-
return
|
|
1194
|
+
function reactive(obj, emit, path = []) {
|
|
1195
|
+
if (globalSeen.has(obj))
|
|
1196
|
+
return globalSeen.get(obj);
|
|
1197
1197
|
if (emit && path.length === 0) {
|
|
1198
1198
|
try {
|
|
1199
1199
|
const initialEvent = {
|
|
@@ -1207,28 +1207,28 @@ function reactive(obj, emit, path = [], seen = globalSeen) {
|
|
|
1207
1207
|
}
|
|
1208
1208
|
}
|
|
1209
1209
|
if (Array.isArray(obj)) {
|
|
1210
|
-
return wrapArray(obj, emit, path
|
|
1210
|
+
return wrapArray(obj, emit, path);
|
|
1211
1211
|
}
|
|
1212
1212
|
if (obj instanceof Map) {
|
|
1213
|
-
return wrapMap(obj, emit, path
|
|
1213
|
+
return wrapMap(obj, emit, path);
|
|
1214
1214
|
}
|
|
1215
1215
|
if (obj instanceof Set) {
|
|
1216
|
-
return wrapSet(obj, emit, path
|
|
1216
|
+
return wrapSet(obj, emit, path);
|
|
1217
1217
|
}
|
|
1218
1218
|
function wrapValue(val, subPath) {
|
|
1219
1219
|
if (!isObject3(val))
|
|
1220
1220
|
return val;
|
|
1221
|
-
if (
|
|
1222
|
-
return
|
|
1221
|
+
if (globalSeen.has(val))
|
|
1222
|
+
return globalSeen.get(val);
|
|
1223
1223
|
if (Array.isArray(val))
|
|
1224
1224
|
return wrapArray(val, emit, subPath);
|
|
1225
1225
|
if (val instanceof Map)
|
|
1226
|
-
return wrapMap(val, emit, subPath
|
|
1226
|
+
return wrapMap(val, emit, subPath);
|
|
1227
1227
|
if (val instanceof Set)
|
|
1228
|
-
return wrapSet(val, emit, subPath
|
|
1228
|
+
return wrapSet(val, emit, subPath);
|
|
1229
1229
|
if (val instanceof Date)
|
|
1230
1230
|
return new Date(val.getTime());
|
|
1231
|
-
return reactive(val, emit, subPath
|
|
1231
|
+
return reactive(val, emit, subPath);
|
|
1232
1232
|
}
|
|
1233
1233
|
const proxy = new Proxy(obj, {
|
|
1234
1234
|
get(target, prop, receiver) {
|
|
@@ -1301,7 +1301,7 @@ function reactive(obj, emit, path = [], seen = globalSeen) {
|
|
|
1301
1301
|
return result;
|
|
1302
1302
|
}
|
|
1303
1303
|
});
|
|
1304
|
-
|
|
1304
|
+
globalSeen.set(obj, proxy);
|
|
1305
1305
|
return proxy;
|
|
1306
1306
|
}
|
|
1307
1307
|
// src/watch.ts
|
package/dist/reactive.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmitFunction, Path } from
|
|
1
|
+
import { EmitFunction, Path } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Checks if an object is a reactive proxy
|
|
4
4
|
*/
|
|
@@ -11,4 +11,4 @@ export declare function toRaw<T>(observed: T): T;
|
|
|
11
11
|
/**
|
|
12
12
|
* Create a reactive proxy for an object
|
|
13
13
|
*/
|
|
14
|
-
export declare function reactive<T extends object>(obj: T, emit?: EmitFunction, path?: Path
|
|
14
|
+
export declare function reactive<T extends object>(obj: T, emit?: EmitFunction, path?: Path): T;
|
package/dist/wrap-array.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EmitFunction, Path } from
|
|
2
|
-
export declare function wrapArray<T extends any[]>(arr: T, emit?: EmitFunction, path?: Path
|
|
1
|
+
import { EmitFunction, Path } from "./types";
|
|
2
|
+
export declare function wrapArray<T extends any[]>(arr: T, emit?: EmitFunction, path?: Path): T;
|
package/dist/wrap-map.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EmitFunction, Path } from
|
|
2
|
-
export declare function wrapMap<K, V>(map: Map<K, V>, emit?: EmitFunction, path?: Path
|
|
1
|
+
import { EmitFunction, Path } from "./types";
|
|
2
|
+
export declare function wrapMap<K, V>(map: Map<K, V>, emit?: EmitFunction, path?: Path): Map<K, V>;
|
package/dist/wrap-set.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EmitFunction, Path } from
|
|
2
|
-
export declare function wrapSet<T>(set: Set<T>, emit?: EmitFunction, path?: Path
|
|
1
|
+
import { EmitFunction, Path } from "./types";
|
|
2
|
+
export declare function wrapSet<T>(set: Set<T>, emit?: EmitFunction, path?: Path): Set<T>;
|