aoye 0.0.9 → 0.0.11
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/aoye.cjs.js +65 -39
- package/dist/aoye.cjs.js.map +1 -1
- package/dist/aoye.esm.js +65 -40
- package/dist/aoye.esm.js.map +1 -1
- package/dist/index.d.ts +14 -8
- package/dist/index.umd.js +65 -39
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/aoye.esm.js
CHANGED
|
@@ -194,9 +194,7 @@ class TaskQueue {
|
|
|
194
194
|
var Keys = /* @__PURE__ */ ((Keys2) => {
|
|
195
195
|
Keys2["Iterator"] = "__AOYE_ITERATOR";
|
|
196
196
|
Keys2["Raw"] = "__AOYE_RAW";
|
|
197
|
-
Keys2["
|
|
198
|
-
Keys2["Scope"] = "__AOYE_SCOPE";
|
|
199
|
-
Keys2["Cells"] = "__AOYE_CELLS";
|
|
197
|
+
Keys2["Meta"] = "__AOYE_META";
|
|
200
198
|
return Keys2;
|
|
201
199
|
})(Keys || {});
|
|
202
200
|
const IsStore = /* @__PURE__ */ Symbol("__AOYE_IS_STORE"), StoreIgnoreKeys = /* @__PURE__ */ Symbol("__AOYE_IGNORE_KEYS");
|
|
@@ -923,19 +921,20 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
923
921
|
const cells = /* @__PURE__ */ new Map();
|
|
924
922
|
const targetIsArray = Array.isArray(target);
|
|
925
923
|
const targetIsStore = Boolean((_a = target.constructor) == null ? void 0 : _a[IsStore]);
|
|
924
|
+
const meta = {
|
|
925
|
+
deep,
|
|
926
|
+
scope,
|
|
927
|
+
cells
|
|
928
|
+
};
|
|
926
929
|
const proxy = new Proxy(target, {
|
|
927
930
|
get(obj, prop, receiver) {
|
|
928
931
|
switch (prop) {
|
|
929
932
|
case Keys.Raw:
|
|
930
933
|
return target;
|
|
931
|
-
case Keys.
|
|
932
|
-
return
|
|
933
|
-
case Keys.Scope:
|
|
934
|
-
return scope;
|
|
935
|
-
case Keys.Cells:
|
|
936
|
-
return cells;
|
|
934
|
+
case Keys.Meta:
|
|
935
|
+
return meta;
|
|
937
936
|
}
|
|
938
|
-
if (targetIsStore && obj.constructor[StoreIgnoreKeys]
|
|
937
|
+
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
|
|
939
938
|
return Reflect.get(obj, prop, receiver);
|
|
940
939
|
}
|
|
941
940
|
const desc = Reflect.getOwnPropertyDescriptor(obj, prop);
|
|
@@ -965,7 +964,7 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
965
964
|
return s.v;
|
|
966
965
|
},
|
|
967
966
|
set(obj, prop, value, receiver) {
|
|
968
|
-
if (targetIsStore && obj.constructor[StoreIgnoreKeys]
|
|
967
|
+
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
|
|
969
968
|
return Reflect.set(obj, prop, value, receiver);
|
|
970
969
|
}
|
|
971
970
|
batch.start();
|
|
@@ -976,18 +975,21 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
976
975
|
}
|
|
977
976
|
if (targetIsArray) {
|
|
978
977
|
handleArraySet(obj, prop, value, receiver);
|
|
978
|
+
} else {
|
|
979
|
+
triggerIter(obj, prop, value, receiver);
|
|
979
980
|
}
|
|
980
981
|
batch.end();
|
|
981
982
|
return success;
|
|
982
983
|
},
|
|
983
984
|
// 【核心修改】拦截 delete 操作
|
|
984
985
|
deleteProperty(obj, prop) {
|
|
985
|
-
if (targetIsStore && obj.constructor[StoreIgnoreKeys]
|
|
986
|
+
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
|
|
986
987
|
return Reflect.deleteProperty(obj, prop);
|
|
987
988
|
}
|
|
988
989
|
if (cells.has(prop)) {
|
|
989
990
|
cells.delete(prop);
|
|
990
991
|
}
|
|
992
|
+
triggerIter(obj, prop, void 0, proxy);
|
|
991
993
|
return Reflect.deleteProperty(obj, prop);
|
|
992
994
|
},
|
|
993
995
|
ownKeys(obj) {
|
|
@@ -1009,9 +1011,9 @@ const shareSignal = (from, fromPath, to, toPath) => {
|
|
|
1009
1011
|
runWithPulling(() => {
|
|
1010
1012
|
const { target: fromTarget, key: fromKey } = getTargetAndKey(from, formPaths);
|
|
1011
1013
|
fromTarget[fromKey];
|
|
1012
|
-
const fromSignal = fromTarget[Keys.
|
|
1014
|
+
const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
|
|
1013
1015
|
const { target: toTarget, key: toKey } = getTargetAndKey(to, toPaths);
|
|
1014
|
-
toTarget[Keys.
|
|
1016
|
+
toTarget[Keys.Meta].cells.set(toKey, fromSignal);
|
|
1015
1017
|
}, null);
|
|
1016
1018
|
} catch (error) {
|
|
1017
1019
|
console.error("\u6620\u5C04\u4E86\u4E0D\u5B58\u5728\u7684Key\uFF01");
|
|
@@ -1030,6 +1032,12 @@ function getTargetAndKey(obj, paths) {
|
|
|
1030
1032
|
}
|
|
1031
1033
|
return { target, key };
|
|
1032
1034
|
}
|
|
1035
|
+
function isIgnoreKey(ignores, key) {
|
|
1036
|
+
if (typeof key !== "string") {
|
|
1037
|
+
return ignores.includes(key);
|
|
1038
|
+
}
|
|
1039
|
+
return ignores.some((it) => typeof it === "string" && key.startsWith(it));
|
|
1040
|
+
}
|
|
1033
1041
|
function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
|
|
1034
1042
|
if (cells.has(prop)) {
|
|
1035
1043
|
return cells.get(prop).v;
|
|
@@ -1046,7 +1054,14 @@ function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
|
|
|
1046
1054
|
function handleArraySet(arr, prop, value, receiver) {
|
|
1047
1055
|
if (prop === "length") ; else if (isNatureNumStr(prop)) {
|
|
1048
1056
|
receiver[Keys.Iterator] = (arr[Keys.Iterator] || 0) + 1;
|
|
1049
|
-
} else
|
|
1057
|
+
} else {
|
|
1058
|
+
triggerIter(arr, prop, value, receiver);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
function triggerIter(obj, prop, value, receiver) {
|
|
1062
|
+
if (!Reflect.has(obj, prop)) {
|
|
1063
|
+
receiver[Keys.Iterator] = receiver[Keys.Raw][Keys.Iterator] + 1;
|
|
1064
|
+
}
|
|
1050
1065
|
}
|
|
1051
1066
|
const arrayMethodReWrites = {};
|
|
1052
1067
|
["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach((key) => {
|
|
@@ -1085,8 +1100,8 @@ const arrayMethodReWrites = {};
|
|
|
1085
1100
|
const fn = Array.prototype[key];
|
|
1086
1101
|
const rawArray = toRaw(this);
|
|
1087
1102
|
const iter = fn.call(rawArray, ...args);
|
|
1088
|
-
const
|
|
1089
|
-
const isDeep =
|
|
1103
|
+
const meta = this[Keys.Meta];
|
|
1104
|
+
const { deep: isDeep, scope } = meta;
|
|
1090
1105
|
if (isDeep) {
|
|
1091
1106
|
const rawNext = iter.next.bind(iter);
|
|
1092
1107
|
iter.next = () => {
|
|
@@ -1106,8 +1121,8 @@ const arrayMethodReWrites = {};
|
|
|
1106
1121
|
};
|
|
1107
1122
|
});
|
|
1108
1123
|
arrayMethodReWrites.filter = function(callback, thisArg) {
|
|
1109
|
-
const
|
|
1110
|
-
const isDeep =
|
|
1124
|
+
const meta = this[Keys.Meta];
|
|
1125
|
+
const { deep: isDeep, scope } = meta;
|
|
1111
1126
|
const that = toRaw(this);
|
|
1112
1127
|
const result = [];
|
|
1113
1128
|
let resultIndex = 0;
|
|
@@ -1125,8 +1140,8 @@ arrayMethodReWrites.filter = function(callback, thisArg) {
|
|
|
1125
1140
|
return result;
|
|
1126
1141
|
};
|
|
1127
1142
|
arrayMethodReWrites.slice = function(start, end) {
|
|
1128
|
-
const
|
|
1129
|
-
const isDeep =
|
|
1143
|
+
const meta = this[Keys.Meta];
|
|
1144
|
+
const { deep: isDeep, scope } = meta;
|
|
1130
1145
|
const that = toRaw(this);
|
|
1131
1146
|
const len = that.length;
|
|
1132
1147
|
let k = start || 0;
|
|
@@ -1152,8 +1167,8 @@ arrayMethodReWrites.slice = function(start, end) {
|
|
|
1152
1167
|
return result;
|
|
1153
1168
|
};
|
|
1154
1169
|
arrayMethodReWrites.toReversed = function() {
|
|
1155
|
-
const
|
|
1156
|
-
const isDeep =
|
|
1170
|
+
const meta = this[Keys.Meta];
|
|
1171
|
+
const { deep: isDeep, scope } = meta;
|
|
1157
1172
|
const that = toRaw(this);
|
|
1158
1173
|
const len = that.length;
|
|
1159
1174
|
const result = new Array(len);
|
|
@@ -1166,8 +1181,8 @@ arrayMethodReWrites.toReversed = function() {
|
|
|
1166
1181
|
return result;
|
|
1167
1182
|
};
|
|
1168
1183
|
arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
|
|
1169
|
-
const
|
|
1170
|
-
const isDeep =
|
|
1184
|
+
const meta = this[Keys.Meta];
|
|
1185
|
+
const { deep: isDeep, scope } = meta;
|
|
1171
1186
|
const that = toRaw(this);
|
|
1172
1187
|
const len = that.length;
|
|
1173
1188
|
let relativeStart = start >> 0;
|
|
@@ -1199,8 +1214,8 @@ arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
|
|
|
1199
1214
|
return result;
|
|
1200
1215
|
};
|
|
1201
1216
|
arrayMethodReWrites.with = function(index, value) {
|
|
1202
|
-
const
|
|
1203
|
-
const isDeep =
|
|
1217
|
+
const meta = this[Keys.Meta];
|
|
1218
|
+
const { deep: isDeep, scope } = meta;
|
|
1204
1219
|
const that = toRaw(this);
|
|
1205
1220
|
const len = that.length;
|
|
1206
1221
|
let relativeIndex = Number(index) || 0;
|
|
@@ -1220,8 +1235,8 @@ arrayMethodReWrites.with = function(index, value) {
|
|
|
1220
1235
|
return result;
|
|
1221
1236
|
};
|
|
1222
1237
|
arrayMethodReWrites.concat = function(...items) {
|
|
1223
|
-
const
|
|
1224
|
-
const isDeep =
|
|
1238
|
+
const meta = this[Keys.Meta];
|
|
1239
|
+
const { deep: isDeep, scope } = meta;
|
|
1225
1240
|
const that = toRaw(this);
|
|
1226
1241
|
const selfLen = that.length;
|
|
1227
1242
|
let totalLength = selfLen;
|
|
@@ -1301,9 +1316,9 @@ const GetMethodConf = {
|
|
|
1301
1316
|
})
|
|
1302
1317
|
].forEach(({ key, wrapReturn, wrapArgs }) => {
|
|
1303
1318
|
arrayMethodReWrites[key] = function(...args) {
|
|
1304
|
-
const
|
|
1319
|
+
const meta = this[Keys.Meta];
|
|
1305
1320
|
const fn = Array.prototype[key];
|
|
1306
|
-
const isDeep =
|
|
1321
|
+
const { deep: isDeep, scope } = meta;
|
|
1307
1322
|
const that = toRaw(this);
|
|
1308
1323
|
warpCallbackArgs(isDeep, args, scope, wrapArgs);
|
|
1309
1324
|
let result = fn.call(that, ...args);
|
|
@@ -1316,8 +1331,8 @@ const GetMethodConf = {
|
|
|
1316
1331
|
});
|
|
1317
1332
|
arrayMethodReWrites.toSorted = function(...args) {
|
|
1318
1333
|
const fn = Array.prototype["toSorted"];
|
|
1319
|
-
const
|
|
1320
|
-
const isDeep =
|
|
1334
|
+
const meta = this[Keys.Meta];
|
|
1335
|
+
const { deep: isDeep, scope } = meta;
|
|
1321
1336
|
const that = toRaw(this);
|
|
1322
1337
|
warpCallbackArgs(isDeep, args, scope, 3);
|
|
1323
1338
|
let result = fn.call(that, ...args);
|
|
@@ -1349,11 +1364,12 @@ var _a, _b;
|
|
|
1349
1364
|
_b = IsStore, _a = StoreIgnoreKeys;
|
|
1350
1365
|
const _Store = class _Store {
|
|
1351
1366
|
constructor() {
|
|
1367
|
+
this.parent = () => null;
|
|
1352
1368
|
const proxy = deepSignal(this, G.PullingSignal, true);
|
|
1353
1369
|
_Store.Current = proxy;
|
|
1354
1370
|
return proxy;
|
|
1355
1371
|
}
|
|
1356
|
-
static new(keyMap = {}) {
|
|
1372
|
+
static new(keyMap = {}, staticMap = {}) {
|
|
1357
1373
|
const parentStore = _Store.Current;
|
|
1358
1374
|
const child = new this();
|
|
1359
1375
|
if (parentStore) {
|
|
@@ -1362,14 +1378,23 @@ const _Store = class _Store {
|
|
|
1362
1378
|
shareSignal(parentStore, parentKey, child, childKey);
|
|
1363
1379
|
}
|
|
1364
1380
|
}
|
|
1381
|
+
for (const key in staticMap) {
|
|
1382
|
+
const value = staticMap[key];
|
|
1383
|
+
child[key] = value;
|
|
1384
|
+
}
|
|
1385
|
+
child.parent = () => parentStore;
|
|
1365
1386
|
_Store.Current = parentStore;
|
|
1366
1387
|
return child;
|
|
1367
1388
|
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1389
|
+
map(keyMap = {}) {
|
|
1390
|
+
const parentStore = this.parent();
|
|
1391
|
+
if (parentStore) {
|
|
1392
|
+
for (const childKey in keyMap) {
|
|
1393
|
+
const parentKey = keyMap[childKey];
|
|
1394
|
+
shareSignal(parentStore, parentKey, this, childKey);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
this.parent = null;
|
|
1373
1398
|
}
|
|
1374
1399
|
};
|
|
1375
1400
|
_Store[_b] = true;
|
|
@@ -1488,5 +1513,5 @@ const isScope = (value) => {
|
|
|
1488
1513
|
return value instanceof Signal;
|
|
1489
1514
|
};
|
|
1490
1515
|
|
|
1491
|
-
export { $, IsStore, Keys, Scheduler, Store, StoreIgnoreKeys, TaskQueue, batch, clean, customEffect, effect, isScope, isSignal, registerScheduler, runWithPulling, scope };
|
|
1516
|
+
export { $, IsStore, Keys, Scheduler, Store, StoreIgnoreKeys, TaskQueue, batch, clean, customEffect, effect, isScope, isSignal, registerScheduler, runWithPulling, scope, shareSignal };
|
|
1492
1517
|
//# sourceMappingURL=aoye.esm.js.map
|