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/aoye.esm.js
CHANGED
|
@@ -194,10 +194,10 @@ 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";
|
|
197
|
+
Keys2["Meta"] = "__AOYE_META";
|
|
199
198
|
return Keys2;
|
|
200
199
|
})(Keys || {});
|
|
200
|
+
const IsStore = /* @__PURE__ */ Symbol("__AOYE_IS_STORE"), StoreIgnoreKeys = /* @__PURE__ */ Symbol("__AOYE_IGNORE_KEYS");
|
|
201
201
|
|
|
202
202
|
let channel = globalThis.MessageChannel ? new MessageChannel() : null;
|
|
203
203
|
if (globalThis.MessageChannel) {
|
|
@@ -260,7 +260,7 @@ class SyncScheduler extends Scheduler {
|
|
|
260
260
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
261
261
|
subQueue.forEach((effect, item) => {
|
|
262
262
|
effect.runIfDirty();
|
|
263
|
-
|
|
263
|
+
queue.delete(item);
|
|
264
264
|
});
|
|
265
265
|
}
|
|
266
266
|
}
|
|
@@ -273,7 +273,7 @@ class MicroScheduler extends Scheduler {
|
|
|
273
273
|
const task = () => {
|
|
274
274
|
subQueue.forEach((effect, item) => {
|
|
275
275
|
effect.runIfDirty();
|
|
276
|
-
|
|
276
|
+
queue.delete(item);
|
|
277
277
|
});
|
|
278
278
|
return {
|
|
279
279
|
finished: true,
|
|
@@ -293,7 +293,7 @@ class MacroScheduler extends Scheduler {
|
|
|
293
293
|
const task = () => {
|
|
294
294
|
subQueue.forEach((effect, item) => {
|
|
295
295
|
effect.runIfDirty();
|
|
296
|
-
|
|
296
|
+
queue.delete(item);
|
|
297
297
|
});
|
|
298
298
|
};
|
|
299
299
|
task.time = Date.now();
|
|
@@ -309,7 +309,7 @@ class LayoutScheduler extends Scheduler {
|
|
|
309
309
|
const task = () => {
|
|
310
310
|
subQueue.forEach((effect, item) => {
|
|
311
311
|
effect.runIfDirty();
|
|
312
|
-
|
|
312
|
+
queue.delete(item);
|
|
313
313
|
});
|
|
314
314
|
};
|
|
315
315
|
task.time = Date.now();
|
|
@@ -914,20 +914,33 @@ var __spreadValues$1 = (a, b) => {
|
|
|
914
914
|
};
|
|
915
915
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
916
916
|
const deepSignal = (target, scope, deep = true) => {
|
|
917
|
+
var _a;
|
|
917
918
|
const isObj = typeof target === "object" && target !== null;
|
|
918
919
|
if (!isObj || target[Keys.Raw]) return target;
|
|
919
920
|
if (rawToProxy.has(target)) return rawToProxy.get(target);
|
|
920
921
|
const cells = /* @__PURE__ */ new Map();
|
|
921
922
|
const targetIsArray = Array.isArray(target);
|
|
923
|
+
const targetIsStore = Boolean((_a = target.constructor) == null ? void 0 : _a[IsStore]);
|
|
924
|
+
const meta = {
|
|
925
|
+
deep,
|
|
926
|
+
scope,
|
|
927
|
+
cells
|
|
928
|
+
};
|
|
922
929
|
const proxy = new Proxy(target, {
|
|
923
930
|
get(obj, prop, receiver) {
|
|
924
931
|
switch (prop) {
|
|
925
932
|
case Keys.Raw:
|
|
926
933
|
return target;
|
|
927
|
-
case Keys.
|
|
928
|
-
return
|
|
929
|
-
|
|
930
|
-
|
|
934
|
+
case Keys.Meta:
|
|
935
|
+
return meta;
|
|
936
|
+
}
|
|
937
|
+
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
|
|
938
|
+
return Reflect.get(obj, prop, receiver);
|
|
939
|
+
}
|
|
940
|
+
const desc = Reflect.getOwnPropertyDescriptor(obj, prop);
|
|
941
|
+
const isGetter = desc && typeof desc.get === "function";
|
|
942
|
+
if (isGetter) {
|
|
943
|
+
return handleGetterAsComputed(obj, prop, receiver, cells, scope);
|
|
931
944
|
}
|
|
932
945
|
const value = Reflect.get(obj, prop, receiver);
|
|
933
946
|
const valueIsFn = typeof value === "function";
|
|
@@ -951,6 +964,9 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
951
964
|
return s.v;
|
|
952
965
|
},
|
|
953
966
|
set(obj, prop, value, receiver) {
|
|
967
|
+
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
|
|
968
|
+
return Reflect.set(obj, prop, value, receiver);
|
|
969
|
+
}
|
|
954
970
|
batch.start();
|
|
955
971
|
const success = Reflect.set(obj, prop, value, receiver);
|
|
956
972
|
if (cells.has(prop)) {
|
|
@@ -959,15 +975,21 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
959
975
|
}
|
|
960
976
|
if (targetIsArray) {
|
|
961
977
|
handleArraySet(obj, prop, value, receiver);
|
|
978
|
+
} else {
|
|
979
|
+
triggerIter(obj, prop, value, receiver);
|
|
962
980
|
}
|
|
963
981
|
batch.end();
|
|
964
982
|
return success;
|
|
965
983
|
},
|
|
966
984
|
// 【核心修改】拦截 delete 操作
|
|
967
985
|
deleteProperty(obj, prop) {
|
|
986
|
+
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
|
|
987
|
+
return Reflect.deleteProperty(obj, prop);
|
|
988
|
+
}
|
|
968
989
|
if (cells.has(prop)) {
|
|
969
990
|
cells.delete(prop);
|
|
970
991
|
}
|
|
992
|
+
triggerIter(obj, prop, void 0, proxy);
|
|
971
993
|
return Reflect.deleteProperty(obj, prop);
|
|
972
994
|
},
|
|
973
995
|
ownKeys(obj) {
|
|
@@ -982,10 +1004,64 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
982
1004
|
rawToProxy.set(target, proxy);
|
|
983
1005
|
return proxy;
|
|
984
1006
|
};
|
|
1007
|
+
const shareSignal = (from, fromPath, to, toPath) => {
|
|
1008
|
+
try {
|
|
1009
|
+
const toPaths = toPath.split(".");
|
|
1010
|
+
const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split(".");
|
|
1011
|
+
runWithPulling(() => {
|
|
1012
|
+
const { target: fromTarget, key: fromKey } = getTargetAndKey(from, formPaths);
|
|
1013
|
+
fromTarget[fromKey];
|
|
1014
|
+
const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
|
|
1015
|
+
const { target: toTarget, key: toKey } = getTargetAndKey(to, toPaths);
|
|
1016
|
+
toTarget[Keys.Meta].cells.set(toKey, fromSignal);
|
|
1017
|
+
}, null);
|
|
1018
|
+
} catch (error) {
|
|
1019
|
+
console.error("\u6620\u5C04\u4E86\u4E0D\u5B58\u5728\u7684Key\uFF01");
|
|
1020
|
+
throw error;
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
function getTargetAndKey(obj, paths) {
|
|
1024
|
+
let target = obj;
|
|
1025
|
+
let key = "";
|
|
1026
|
+
const len = paths.length;
|
|
1027
|
+
for (let i = 0; i < len; i++) {
|
|
1028
|
+
key = paths[i];
|
|
1029
|
+
if (i < len - 1) {
|
|
1030
|
+
target = target[key];
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
return { target, key };
|
|
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
|
+
}
|
|
1041
|
+
function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
|
|
1042
|
+
if (cells.has(prop)) {
|
|
1043
|
+
return cells.get(prop).v;
|
|
1044
|
+
}
|
|
1045
|
+
const s = Signal.create(null, {
|
|
1046
|
+
customPull: () => Reflect.get(obj, prop, receiver),
|
|
1047
|
+
scheduler: Scheduler.Sync,
|
|
1048
|
+
isScope: false,
|
|
1049
|
+
scope
|
|
1050
|
+
});
|
|
1051
|
+
cells.set(prop, s);
|
|
1052
|
+
return s.v;
|
|
1053
|
+
}
|
|
985
1054
|
function handleArraySet(arr, prop, value, receiver) {
|
|
986
1055
|
if (prop === "length") ; else if (isNatureNumStr(prop)) {
|
|
987
1056
|
receiver[Keys.Iterator] = (arr[Keys.Iterator] || 0) + 1;
|
|
988
|
-
} 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
|
+
}
|
|
989
1065
|
}
|
|
990
1066
|
const arrayMethodReWrites = {};
|
|
991
1067
|
["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach((key) => {
|
|
@@ -1024,8 +1100,8 @@ const arrayMethodReWrites = {};
|
|
|
1024
1100
|
const fn = Array.prototype[key];
|
|
1025
1101
|
const rawArray = toRaw(this);
|
|
1026
1102
|
const iter = fn.call(rawArray, ...args);
|
|
1027
|
-
const
|
|
1028
|
-
const isDeep =
|
|
1103
|
+
const meta = this[Keys.Meta];
|
|
1104
|
+
const { deep: isDeep, scope } = meta;
|
|
1029
1105
|
if (isDeep) {
|
|
1030
1106
|
const rawNext = iter.next.bind(iter);
|
|
1031
1107
|
iter.next = () => {
|
|
@@ -1045,8 +1121,8 @@ const arrayMethodReWrites = {};
|
|
|
1045
1121
|
};
|
|
1046
1122
|
});
|
|
1047
1123
|
arrayMethodReWrites.filter = function(callback, thisArg) {
|
|
1048
|
-
const
|
|
1049
|
-
const isDeep =
|
|
1124
|
+
const meta = this[Keys.Meta];
|
|
1125
|
+
const { deep: isDeep, scope } = meta;
|
|
1050
1126
|
const that = toRaw(this);
|
|
1051
1127
|
const result = [];
|
|
1052
1128
|
let resultIndex = 0;
|
|
@@ -1064,8 +1140,8 @@ arrayMethodReWrites.filter = function(callback, thisArg) {
|
|
|
1064
1140
|
return result;
|
|
1065
1141
|
};
|
|
1066
1142
|
arrayMethodReWrites.slice = function(start, end) {
|
|
1067
|
-
const
|
|
1068
|
-
const isDeep =
|
|
1143
|
+
const meta = this[Keys.Meta];
|
|
1144
|
+
const { deep: isDeep, scope } = meta;
|
|
1069
1145
|
const that = toRaw(this);
|
|
1070
1146
|
const len = that.length;
|
|
1071
1147
|
let k = start || 0;
|
|
@@ -1091,8 +1167,8 @@ arrayMethodReWrites.slice = function(start, end) {
|
|
|
1091
1167
|
return result;
|
|
1092
1168
|
};
|
|
1093
1169
|
arrayMethodReWrites.toReversed = function() {
|
|
1094
|
-
const
|
|
1095
|
-
const isDeep =
|
|
1170
|
+
const meta = this[Keys.Meta];
|
|
1171
|
+
const { deep: isDeep, scope } = meta;
|
|
1096
1172
|
const that = toRaw(this);
|
|
1097
1173
|
const len = that.length;
|
|
1098
1174
|
const result = new Array(len);
|
|
@@ -1105,8 +1181,8 @@ arrayMethodReWrites.toReversed = function() {
|
|
|
1105
1181
|
return result;
|
|
1106
1182
|
};
|
|
1107
1183
|
arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
|
|
1108
|
-
const
|
|
1109
|
-
const isDeep =
|
|
1184
|
+
const meta = this[Keys.Meta];
|
|
1185
|
+
const { deep: isDeep, scope } = meta;
|
|
1110
1186
|
const that = toRaw(this);
|
|
1111
1187
|
const len = that.length;
|
|
1112
1188
|
let relativeStart = start >> 0;
|
|
@@ -1138,8 +1214,8 @@ arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
|
|
|
1138
1214
|
return result;
|
|
1139
1215
|
};
|
|
1140
1216
|
arrayMethodReWrites.with = function(index, value) {
|
|
1141
|
-
const
|
|
1142
|
-
const isDeep =
|
|
1217
|
+
const meta = this[Keys.Meta];
|
|
1218
|
+
const { deep: isDeep, scope } = meta;
|
|
1143
1219
|
const that = toRaw(this);
|
|
1144
1220
|
const len = that.length;
|
|
1145
1221
|
let relativeIndex = Number(index) || 0;
|
|
@@ -1159,8 +1235,8 @@ arrayMethodReWrites.with = function(index, value) {
|
|
|
1159
1235
|
return result;
|
|
1160
1236
|
};
|
|
1161
1237
|
arrayMethodReWrites.concat = function(...items) {
|
|
1162
|
-
const
|
|
1163
|
-
const isDeep =
|
|
1238
|
+
const meta = this[Keys.Meta];
|
|
1239
|
+
const { deep: isDeep, scope } = meta;
|
|
1164
1240
|
const that = toRaw(this);
|
|
1165
1241
|
const selfLen = that.length;
|
|
1166
1242
|
let totalLength = selfLen;
|
|
@@ -1240,9 +1316,9 @@ const GetMethodConf = {
|
|
|
1240
1316
|
})
|
|
1241
1317
|
].forEach(({ key, wrapReturn, wrapArgs }) => {
|
|
1242
1318
|
arrayMethodReWrites[key] = function(...args) {
|
|
1243
|
-
const
|
|
1319
|
+
const meta = this[Keys.Meta];
|
|
1244
1320
|
const fn = Array.prototype[key];
|
|
1245
|
-
const isDeep =
|
|
1321
|
+
const { deep: isDeep, scope } = meta;
|
|
1246
1322
|
const that = toRaw(this);
|
|
1247
1323
|
warpCallbackArgs(isDeep, args, scope, wrapArgs);
|
|
1248
1324
|
let result = fn.call(that, ...args);
|
|
@@ -1255,8 +1331,8 @@ const GetMethodConf = {
|
|
|
1255
1331
|
});
|
|
1256
1332
|
arrayMethodReWrites.toSorted = function(...args) {
|
|
1257
1333
|
const fn = Array.prototype["toSorted"];
|
|
1258
|
-
const
|
|
1259
|
-
const isDeep =
|
|
1334
|
+
const meta = this[Keys.Meta];
|
|
1335
|
+
const { deep: isDeep, scope } = meta;
|
|
1260
1336
|
const that = toRaw(this);
|
|
1261
1337
|
warpCallbackArgs(isDeep, args, scope, 3);
|
|
1262
1338
|
let result = fn.call(that, ...args);
|
|
@@ -1284,6 +1360,48 @@ function warpCallbackArgs(isDeep, args, scope, wrapArgs = 1) {
|
|
|
1284
1360
|
args[0] = wrapCb;
|
|
1285
1361
|
}
|
|
1286
1362
|
|
|
1363
|
+
var _a, _b;
|
|
1364
|
+
_b = IsStore, _a = StoreIgnoreKeys;
|
|
1365
|
+
const _Store = class _Store {
|
|
1366
|
+
constructor() {
|
|
1367
|
+
this.parent = () => null;
|
|
1368
|
+
const proxy = deepSignal(this, G.PullingSignal, true);
|
|
1369
|
+
_Store.Current = proxy;
|
|
1370
|
+
return proxy;
|
|
1371
|
+
}
|
|
1372
|
+
static new(keyMap = {}, staticMap = {}) {
|
|
1373
|
+
const parentStore = _Store.Current;
|
|
1374
|
+
const child = new this();
|
|
1375
|
+
if (parentStore) {
|
|
1376
|
+
for (const childKey in keyMap) {
|
|
1377
|
+
const parentKey = keyMap[childKey];
|
|
1378
|
+
shareSignal(parentStore, parentKey, child, childKey);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
for (const key in staticMap) {
|
|
1382
|
+
const value = staticMap[key];
|
|
1383
|
+
child[key] = value;
|
|
1384
|
+
}
|
|
1385
|
+
child.parent = () => parentStore;
|
|
1386
|
+
_Store.Current = parentStore;
|
|
1387
|
+
return child;
|
|
1388
|
+
}
|
|
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;
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
_Store[_b] = true;
|
|
1401
|
+
_Store[_a] = ["ui", "raw"];
|
|
1402
|
+
_Store.Current = null;
|
|
1403
|
+
let Store = _Store;
|
|
1404
|
+
|
|
1287
1405
|
var __defProp = Object.defineProperty;
|
|
1288
1406
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1289
1407
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -1395,5 +1513,5 @@ const isScope = (value) => {
|
|
|
1395
1513
|
return value instanceof Signal;
|
|
1396
1514
|
};
|
|
1397
1515
|
|
|
1398
|
-
export { $, Keys, Scheduler, 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 };
|
|
1399
1517
|
//# sourceMappingURL=aoye.esm.js.map
|