aoye 0.0.8 → 0.0.10
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 +151 -29
- package/dist/aoye.cjs.js.map +1 -1
- package/dist/aoye.esm.js +148 -30
- package/dist/aoye.esm.js.map +1 -1
- package/dist/index.d.ts +33 -6
- package/dist/index.umd.js +151 -29
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -198,10 +198,10 @@
|
|
|
198
198
|
var Keys = /* @__PURE__ */ ((Keys2) => {
|
|
199
199
|
Keys2["Iterator"] = "__AOYE_ITERATOR";
|
|
200
200
|
Keys2["Raw"] = "__AOYE_RAW";
|
|
201
|
-
Keys2["
|
|
202
|
-
Keys2["Scope"] = "__AOYE_SCOPE";
|
|
201
|
+
Keys2["Meta"] = "__AOYE_META";
|
|
203
202
|
return Keys2;
|
|
204
203
|
})(Keys || {});
|
|
204
|
+
const IsStore = /* @__PURE__ */ Symbol("__AOYE_IS_STORE"), StoreIgnoreKeys = /* @__PURE__ */ Symbol("__AOYE_IGNORE_KEYS");
|
|
205
205
|
|
|
206
206
|
let channel = globalThis.MessageChannel ? new MessageChannel() : null;
|
|
207
207
|
if (globalThis.MessageChannel) {
|
|
@@ -264,7 +264,7 @@
|
|
|
264
264
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
265
265
|
subQueue.forEach((effect, item) => {
|
|
266
266
|
effect.runIfDirty();
|
|
267
|
-
|
|
267
|
+
queue.delete(item);
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
270
|
}
|
|
@@ -277,7 +277,7 @@
|
|
|
277
277
|
const task = () => {
|
|
278
278
|
subQueue.forEach((effect, item) => {
|
|
279
279
|
effect.runIfDirty();
|
|
280
|
-
|
|
280
|
+
queue.delete(item);
|
|
281
281
|
});
|
|
282
282
|
return {
|
|
283
283
|
finished: true,
|
|
@@ -297,7 +297,7 @@
|
|
|
297
297
|
const task = () => {
|
|
298
298
|
subQueue.forEach((effect, item) => {
|
|
299
299
|
effect.runIfDirty();
|
|
300
|
-
|
|
300
|
+
queue.delete(item);
|
|
301
301
|
});
|
|
302
302
|
};
|
|
303
303
|
task.time = Date.now();
|
|
@@ -313,7 +313,7 @@
|
|
|
313
313
|
const task = () => {
|
|
314
314
|
subQueue.forEach((effect, item) => {
|
|
315
315
|
effect.runIfDirty();
|
|
316
|
-
|
|
316
|
+
queue.delete(item);
|
|
317
317
|
});
|
|
318
318
|
};
|
|
319
319
|
task.time = Date.now();
|
|
@@ -918,20 +918,33 @@
|
|
|
918
918
|
};
|
|
919
919
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
920
920
|
const deepSignal = (target, scope, deep = true) => {
|
|
921
|
+
var _a;
|
|
921
922
|
const isObj = typeof target === "object" && target !== null;
|
|
922
923
|
if (!isObj || target[Keys.Raw]) return target;
|
|
923
924
|
if (rawToProxy.has(target)) return rawToProxy.get(target);
|
|
924
925
|
const cells = /* @__PURE__ */ new Map();
|
|
925
926
|
const targetIsArray = Array.isArray(target);
|
|
927
|
+
const targetIsStore = Boolean((_a = target.constructor) == null ? void 0 : _a[IsStore]);
|
|
928
|
+
const meta = {
|
|
929
|
+
deep,
|
|
930
|
+
scope,
|
|
931
|
+
cells
|
|
932
|
+
};
|
|
926
933
|
const proxy = new Proxy(target, {
|
|
927
934
|
get(obj, prop, receiver) {
|
|
928
935
|
switch (prop) {
|
|
929
936
|
case Keys.Raw:
|
|
930
937
|
return target;
|
|
931
|
-
case Keys.
|
|
932
|
-
return
|
|
933
|
-
|
|
934
|
-
|
|
938
|
+
case Keys.Meta:
|
|
939
|
+
return meta;
|
|
940
|
+
}
|
|
941
|
+
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
|
|
942
|
+
return Reflect.get(obj, prop, receiver);
|
|
943
|
+
}
|
|
944
|
+
const desc = Reflect.getOwnPropertyDescriptor(obj, prop);
|
|
945
|
+
const isGetter = desc && typeof desc.get === "function";
|
|
946
|
+
if (isGetter) {
|
|
947
|
+
return handleGetterAsComputed(obj, prop, receiver, cells, scope);
|
|
935
948
|
}
|
|
936
949
|
const value = Reflect.get(obj, prop, receiver);
|
|
937
950
|
const valueIsFn = typeof value === "function";
|
|
@@ -955,6 +968,9 @@
|
|
|
955
968
|
return s.v;
|
|
956
969
|
},
|
|
957
970
|
set(obj, prop, value, receiver) {
|
|
971
|
+
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
|
|
972
|
+
return Reflect.set(obj, prop, value, receiver);
|
|
973
|
+
}
|
|
958
974
|
batch.start();
|
|
959
975
|
const success = Reflect.set(obj, prop, value, receiver);
|
|
960
976
|
if (cells.has(prop)) {
|
|
@@ -963,15 +979,21 @@
|
|
|
963
979
|
}
|
|
964
980
|
if (targetIsArray) {
|
|
965
981
|
handleArraySet(obj, prop, value, receiver);
|
|
982
|
+
} else {
|
|
983
|
+
triggerIter(obj, prop, value, receiver);
|
|
966
984
|
}
|
|
967
985
|
batch.end();
|
|
968
986
|
return success;
|
|
969
987
|
},
|
|
970
988
|
// 【核心修改】拦截 delete 操作
|
|
971
989
|
deleteProperty(obj, prop) {
|
|
990
|
+
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
|
|
991
|
+
return Reflect.deleteProperty(obj, prop);
|
|
992
|
+
}
|
|
972
993
|
if (cells.has(prop)) {
|
|
973
994
|
cells.delete(prop);
|
|
974
995
|
}
|
|
996
|
+
triggerIter(obj, prop, void 0, proxy);
|
|
975
997
|
return Reflect.deleteProperty(obj, prop);
|
|
976
998
|
},
|
|
977
999
|
ownKeys(obj) {
|
|
@@ -986,10 +1008,64 @@
|
|
|
986
1008
|
rawToProxy.set(target, proxy);
|
|
987
1009
|
return proxy;
|
|
988
1010
|
};
|
|
1011
|
+
const shareSignal = (from, fromPath, to, toPath) => {
|
|
1012
|
+
try {
|
|
1013
|
+
const toPaths = toPath.split(".");
|
|
1014
|
+
const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split(".");
|
|
1015
|
+
runWithPulling(() => {
|
|
1016
|
+
const { target: fromTarget, key: fromKey } = getTargetAndKey(from, formPaths);
|
|
1017
|
+
fromTarget[fromKey];
|
|
1018
|
+
const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
|
|
1019
|
+
const { target: toTarget, key: toKey } = getTargetAndKey(to, toPaths);
|
|
1020
|
+
toTarget[Keys.Meta].cells.set(toKey, fromSignal);
|
|
1021
|
+
}, null);
|
|
1022
|
+
} catch (error) {
|
|
1023
|
+
console.error("\u6620\u5C04\u4E86\u4E0D\u5B58\u5728\u7684Key\uFF01");
|
|
1024
|
+
throw error;
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
function getTargetAndKey(obj, paths) {
|
|
1028
|
+
let target = obj;
|
|
1029
|
+
let key = "";
|
|
1030
|
+
const len = paths.length;
|
|
1031
|
+
for (let i = 0; i < len; i++) {
|
|
1032
|
+
key = paths[i];
|
|
1033
|
+
if (i < len - 1) {
|
|
1034
|
+
target = target[key];
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
return { target, key };
|
|
1038
|
+
}
|
|
1039
|
+
function isIgnoreKey(ignores, key) {
|
|
1040
|
+
if (typeof key !== "string") {
|
|
1041
|
+
return ignores.includes(key);
|
|
1042
|
+
}
|
|
1043
|
+
return ignores.some((it) => typeof it === "string" && key.startsWith(it));
|
|
1044
|
+
}
|
|
1045
|
+
function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
|
|
1046
|
+
if (cells.has(prop)) {
|
|
1047
|
+
return cells.get(prop).v;
|
|
1048
|
+
}
|
|
1049
|
+
const s = Signal.create(null, {
|
|
1050
|
+
customPull: () => Reflect.get(obj, prop, receiver),
|
|
1051
|
+
scheduler: Scheduler.Sync,
|
|
1052
|
+
isScope: false,
|
|
1053
|
+
scope
|
|
1054
|
+
});
|
|
1055
|
+
cells.set(prop, s);
|
|
1056
|
+
return s.v;
|
|
1057
|
+
}
|
|
989
1058
|
function handleArraySet(arr, prop, value, receiver) {
|
|
990
1059
|
if (prop === "length") ; else if (bobeShared.isNatureNumStr(prop)) {
|
|
991
1060
|
receiver[Keys.Iterator] = (arr[Keys.Iterator] || 0) + 1;
|
|
992
|
-
} else
|
|
1061
|
+
} else {
|
|
1062
|
+
triggerIter(arr, prop, value, receiver);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
function triggerIter(obj, prop, value, receiver) {
|
|
1066
|
+
if (!Reflect.has(obj, prop)) {
|
|
1067
|
+
receiver[Keys.Iterator] = receiver[Keys.Raw][Keys.Iterator] + 1;
|
|
1068
|
+
}
|
|
993
1069
|
}
|
|
994
1070
|
const arrayMethodReWrites = {};
|
|
995
1071
|
["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach((key) => {
|
|
@@ -1028,8 +1104,8 @@
|
|
|
1028
1104
|
const fn = Array.prototype[key];
|
|
1029
1105
|
const rawArray = toRaw(this);
|
|
1030
1106
|
const iter = fn.call(rawArray, ...args);
|
|
1031
|
-
const
|
|
1032
|
-
const isDeep =
|
|
1107
|
+
const meta = this[Keys.Meta];
|
|
1108
|
+
const { deep: isDeep, scope } = meta;
|
|
1033
1109
|
if (isDeep) {
|
|
1034
1110
|
const rawNext = iter.next.bind(iter);
|
|
1035
1111
|
iter.next = () => {
|
|
@@ -1049,8 +1125,8 @@
|
|
|
1049
1125
|
};
|
|
1050
1126
|
});
|
|
1051
1127
|
arrayMethodReWrites.filter = function(callback, thisArg) {
|
|
1052
|
-
const
|
|
1053
|
-
const isDeep =
|
|
1128
|
+
const meta = this[Keys.Meta];
|
|
1129
|
+
const { deep: isDeep, scope } = meta;
|
|
1054
1130
|
const that = toRaw(this);
|
|
1055
1131
|
const result = [];
|
|
1056
1132
|
let resultIndex = 0;
|
|
@@ -1068,8 +1144,8 @@
|
|
|
1068
1144
|
return result;
|
|
1069
1145
|
};
|
|
1070
1146
|
arrayMethodReWrites.slice = function(start, end) {
|
|
1071
|
-
const
|
|
1072
|
-
const isDeep =
|
|
1147
|
+
const meta = this[Keys.Meta];
|
|
1148
|
+
const { deep: isDeep, scope } = meta;
|
|
1073
1149
|
const that = toRaw(this);
|
|
1074
1150
|
const len = that.length;
|
|
1075
1151
|
let k = start || 0;
|
|
@@ -1095,8 +1171,8 @@
|
|
|
1095
1171
|
return result;
|
|
1096
1172
|
};
|
|
1097
1173
|
arrayMethodReWrites.toReversed = function() {
|
|
1098
|
-
const
|
|
1099
|
-
const isDeep =
|
|
1174
|
+
const meta = this[Keys.Meta];
|
|
1175
|
+
const { deep: isDeep, scope } = meta;
|
|
1100
1176
|
const that = toRaw(this);
|
|
1101
1177
|
const len = that.length;
|
|
1102
1178
|
const result = new Array(len);
|
|
@@ -1109,8 +1185,8 @@
|
|
|
1109
1185
|
return result;
|
|
1110
1186
|
};
|
|
1111
1187
|
arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
|
|
1112
|
-
const
|
|
1113
|
-
const isDeep =
|
|
1188
|
+
const meta = this[Keys.Meta];
|
|
1189
|
+
const { deep: isDeep, scope } = meta;
|
|
1114
1190
|
const that = toRaw(this);
|
|
1115
1191
|
const len = that.length;
|
|
1116
1192
|
let relativeStart = start >> 0;
|
|
@@ -1142,8 +1218,8 @@
|
|
|
1142
1218
|
return result;
|
|
1143
1219
|
};
|
|
1144
1220
|
arrayMethodReWrites.with = function(index, value) {
|
|
1145
|
-
const
|
|
1146
|
-
const isDeep =
|
|
1221
|
+
const meta = this[Keys.Meta];
|
|
1222
|
+
const { deep: isDeep, scope } = meta;
|
|
1147
1223
|
const that = toRaw(this);
|
|
1148
1224
|
const len = that.length;
|
|
1149
1225
|
let relativeIndex = Number(index) || 0;
|
|
@@ -1163,8 +1239,8 @@
|
|
|
1163
1239
|
return result;
|
|
1164
1240
|
};
|
|
1165
1241
|
arrayMethodReWrites.concat = function(...items) {
|
|
1166
|
-
const
|
|
1167
|
-
const isDeep =
|
|
1242
|
+
const meta = this[Keys.Meta];
|
|
1243
|
+
const { deep: isDeep, scope } = meta;
|
|
1168
1244
|
const that = toRaw(this);
|
|
1169
1245
|
const selfLen = that.length;
|
|
1170
1246
|
let totalLength = selfLen;
|
|
@@ -1244,9 +1320,9 @@
|
|
|
1244
1320
|
})
|
|
1245
1321
|
].forEach(({ key, wrapReturn, wrapArgs }) => {
|
|
1246
1322
|
arrayMethodReWrites[key] = function(...args) {
|
|
1247
|
-
const
|
|
1323
|
+
const meta = this[Keys.Meta];
|
|
1248
1324
|
const fn = Array.prototype[key];
|
|
1249
|
-
const isDeep =
|
|
1325
|
+
const { deep: isDeep, scope } = meta;
|
|
1250
1326
|
const that = toRaw(this);
|
|
1251
1327
|
warpCallbackArgs(isDeep, args, scope, wrapArgs);
|
|
1252
1328
|
let result = fn.call(that, ...args);
|
|
@@ -1259,8 +1335,8 @@
|
|
|
1259
1335
|
});
|
|
1260
1336
|
arrayMethodReWrites.toSorted = function(...args) {
|
|
1261
1337
|
const fn = Array.prototype["toSorted"];
|
|
1262
|
-
const
|
|
1263
|
-
const isDeep =
|
|
1338
|
+
const meta = this[Keys.Meta];
|
|
1339
|
+
const { deep: isDeep, scope } = meta;
|
|
1264
1340
|
const that = toRaw(this);
|
|
1265
1341
|
warpCallbackArgs(isDeep, args, scope, 3);
|
|
1266
1342
|
let result = fn.call(that, ...args);
|
|
@@ -1288,6 +1364,48 @@
|
|
|
1288
1364
|
args[0] = wrapCb;
|
|
1289
1365
|
}
|
|
1290
1366
|
|
|
1367
|
+
var _a, _b;
|
|
1368
|
+
_b = IsStore, _a = StoreIgnoreKeys;
|
|
1369
|
+
const _Store = class _Store {
|
|
1370
|
+
constructor() {
|
|
1371
|
+
this.parent = () => null;
|
|
1372
|
+
const proxy = deepSignal(this, G.PullingSignal, true);
|
|
1373
|
+
_Store.Current = proxy;
|
|
1374
|
+
return proxy;
|
|
1375
|
+
}
|
|
1376
|
+
static new(keyMap = {}, staticMap = {}) {
|
|
1377
|
+
const parentStore = _Store.Current;
|
|
1378
|
+
const child = new this();
|
|
1379
|
+
if (parentStore) {
|
|
1380
|
+
for (const childKey in keyMap) {
|
|
1381
|
+
const parentKey = keyMap[childKey];
|
|
1382
|
+
shareSignal(parentStore, parentKey, child, childKey);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
for (const key in staticMap) {
|
|
1386
|
+
const value = staticMap[key];
|
|
1387
|
+
child[key] = value;
|
|
1388
|
+
}
|
|
1389
|
+
child.parent = () => parentStore;
|
|
1390
|
+
_Store.Current = parentStore;
|
|
1391
|
+
return child;
|
|
1392
|
+
}
|
|
1393
|
+
map(keyMap = {}) {
|
|
1394
|
+
const parentStore = this.parent();
|
|
1395
|
+
if (parentStore) {
|
|
1396
|
+
for (const childKey in keyMap) {
|
|
1397
|
+
const parentKey = keyMap[childKey];
|
|
1398
|
+
shareSignal(parentStore, parentKey, this, childKey);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
this.parent = null;
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
_Store[_b] = true;
|
|
1405
|
+
_Store[_a] = ["ui", "raw"];
|
|
1406
|
+
_Store.Current = null;
|
|
1407
|
+
let Store = _Store;
|
|
1408
|
+
|
|
1291
1409
|
var __defProp = Object.defineProperty;
|
|
1292
1410
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1293
1411
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -1400,8 +1518,11 @@
|
|
|
1400
1518
|
};
|
|
1401
1519
|
|
|
1402
1520
|
exports.$ = $;
|
|
1521
|
+
exports.IsStore = IsStore;
|
|
1403
1522
|
exports.Keys = Keys;
|
|
1404
1523
|
exports.Scheduler = Scheduler;
|
|
1524
|
+
exports.Store = Store;
|
|
1525
|
+
exports.StoreIgnoreKeys = StoreIgnoreKeys;
|
|
1405
1526
|
exports.TaskQueue = TaskQueue;
|
|
1406
1527
|
exports.batch = batch;
|
|
1407
1528
|
exports.clean = clean;
|
|
@@ -1412,6 +1533,7 @@
|
|
|
1412
1533
|
exports.registerScheduler = registerScheduler;
|
|
1413
1534
|
exports.runWithPulling = runWithPulling;
|
|
1414
1535
|
exports.scope = scope;
|
|
1536
|
+
exports.shareSignal = shareSignal;
|
|
1415
1537
|
|
|
1416
1538
|
}));
|
|
1417
1539
|
//# sourceMappingURL=index.umd.js.map
|