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