aoye 0.0.9 → 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 CHANGED
@@ -196,9 +196,7 @@ class TaskQueue {
196
196
  var Keys = /* @__PURE__ */ ((Keys2) => {
197
197
  Keys2["Iterator"] = "__AOYE_ITERATOR";
198
198
  Keys2["Raw"] = "__AOYE_RAW";
199
- Keys2["Deep"] = "__AOYE_DEEP";
200
- Keys2["Scope"] = "__AOYE_SCOPE";
201
- Keys2["Cells"] = "__AOYE_CELLS";
199
+ Keys2["Meta"] = "__AOYE_META";
202
200
  return Keys2;
203
201
  })(Keys || {});
204
202
  const IsStore = /* @__PURE__ */ Symbol("__AOYE_IS_STORE"), StoreIgnoreKeys = /* @__PURE__ */ Symbol("__AOYE_IGNORE_KEYS");
@@ -925,19 +923,20 @@ const deepSignal = (target, scope, deep = true) => {
925
923
  const cells = /* @__PURE__ */ new Map();
926
924
  const targetIsArray = Array.isArray(target);
927
925
  const targetIsStore = Boolean((_a = target.constructor) == null ? void 0 : _a[IsStore]);
926
+ const meta = {
927
+ deep,
928
+ scope,
929
+ cells
930
+ };
928
931
  const proxy = new Proxy(target, {
929
932
  get(obj, prop, receiver) {
930
933
  switch (prop) {
931
934
  case Keys.Raw:
932
935
  return target;
933
- case Keys.Deep:
934
- return deep;
935
- case Keys.Scope:
936
- return scope;
937
- case Keys.Cells:
938
- return cells;
936
+ case Keys.Meta:
937
+ return meta;
939
938
  }
940
- if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
939
+ if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
941
940
  return Reflect.get(obj, prop, receiver);
942
941
  }
943
942
  const desc = Reflect.getOwnPropertyDescriptor(obj, prop);
@@ -967,7 +966,7 @@ const deepSignal = (target, scope, deep = true) => {
967
966
  return s.v;
968
967
  },
969
968
  set(obj, prop, value, receiver) {
970
- if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
969
+ if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
971
970
  return Reflect.set(obj, prop, value, receiver);
972
971
  }
973
972
  batch.start();
@@ -978,18 +977,21 @@ const deepSignal = (target, scope, deep = true) => {
978
977
  }
979
978
  if (targetIsArray) {
980
979
  handleArraySet(obj, prop, value, receiver);
980
+ } else {
981
+ triggerIter(obj, prop, value, receiver);
981
982
  }
982
983
  batch.end();
983
984
  return success;
984
985
  },
985
986
  // 【核心修改】拦截 delete 操作
986
987
  deleteProperty(obj, prop) {
987
- if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
988
+ if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
988
989
  return Reflect.deleteProperty(obj, prop);
989
990
  }
990
991
  if (cells.has(prop)) {
991
992
  cells.delete(prop);
992
993
  }
994
+ triggerIter(obj, prop, void 0, proxy);
993
995
  return Reflect.deleteProperty(obj, prop);
994
996
  },
995
997
  ownKeys(obj) {
@@ -1011,9 +1013,9 @@ const shareSignal = (from, fromPath, to, toPath) => {
1011
1013
  runWithPulling(() => {
1012
1014
  const { target: fromTarget, key: fromKey } = getTargetAndKey(from, formPaths);
1013
1015
  fromTarget[fromKey];
1014
- const fromSignal = fromTarget[Keys.Cells].get(fromKey);
1016
+ const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
1015
1017
  const { target: toTarget, key: toKey } = getTargetAndKey(to, toPaths);
1016
- toTarget[Keys.Cells].set(toKey, fromSignal);
1018
+ toTarget[Keys.Meta].cells.set(toKey, fromSignal);
1017
1019
  }, null);
1018
1020
  } catch (error) {
1019
1021
  console.error("\u6620\u5C04\u4E86\u4E0D\u5B58\u5728\u7684Key\uFF01");
@@ -1032,6 +1034,12 @@ function getTargetAndKey(obj, paths) {
1032
1034
  }
1033
1035
  return { target, key };
1034
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
+ }
1035
1043
  function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
1036
1044
  if (cells.has(prop)) {
1037
1045
  return cells.get(prop).v;
@@ -1048,7 +1056,14 @@ function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
1048
1056
  function handleArraySet(arr, prop, value, receiver) {
1049
1057
  if (prop === "length") ; else if (bobeShared.isNatureNumStr(prop)) {
1050
1058
  receiver[Keys.Iterator] = (arr[Keys.Iterator] || 0) + 1;
1051
- } 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
+ }
1052
1067
  }
1053
1068
  const arrayMethodReWrites = {};
1054
1069
  ["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach((key) => {
@@ -1087,8 +1102,8 @@ const arrayMethodReWrites = {};
1087
1102
  const fn = Array.prototype[key];
1088
1103
  const rawArray = toRaw(this);
1089
1104
  const iter = fn.call(rawArray, ...args);
1090
- const scope = this[Keys.Scope];
1091
- const isDeep = this[Keys.Deep];
1105
+ const meta = this[Keys.Meta];
1106
+ const { deep: isDeep, scope } = meta;
1092
1107
  if (isDeep) {
1093
1108
  const rawNext = iter.next.bind(iter);
1094
1109
  iter.next = () => {
@@ -1108,8 +1123,8 @@ const arrayMethodReWrites = {};
1108
1123
  };
1109
1124
  });
1110
1125
  arrayMethodReWrites.filter = function(callback, thisArg) {
1111
- const scope = this[Keys.Scope];
1112
- const isDeep = this[Keys.Deep];
1126
+ const meta = this[Keys.Meta];
1127
+ const { deep: isDeep, scope } = meta;
1113
1128
  const that = toRaw(this);
1114
1129
  const result = [];
1115
1130
  let resultIndex = 0;
@@ -1127,8 +1142,8 @@ arrayMethodReWrites.filter = function(callback, thisArg) {
1127
1142
  return result;
1128
1143
  };
1129
1144
  arrayMethodReWrites.slice = function(start, end) {
1130
- const scope = this[Keys.Scope];
1131
- const isDeep = this[Keys.Deep];
1145
+ const meta = this[Keys.Meta];
1146
+ const { deep: isDeep, scope } = meta;
1132
1147
  const that = toRaw(this);
1133
1148
  const len = that.length;
1134
1149
  let k = start || 0;
@@ -1154,8 +1169,8 @@ arrayMethodReWrites.slice = function(start, end) {
1154
1169
  return result;
1155
1170
  };
1156
1171
  arrayMethodReWrites.toReversed = function() {
1157
- const scope = this[Keys.Scope];
1158
- const isDeep = this[Keys.Deep];
1172
+ const meta = this[Keys.Meta];
1173
+ const { deep: isDeep, scope } = meta;
1159
1174
  const that = toRaw(this);
1160
1175
  const len = that.length;
1161
1176
  const result = new Array(len);
@@ -1168,8 +1183,8 @@ arrayMethodReWrites.toReversed = function() {
1168
1183
  return result;
1169
1184
  };
1170
1185
  arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
1171
- const scope = this[Keys.Scope];
1172
- const isDeep = this[Keys.Deep];
1186
+ const meta = this[Keys.Meta];
1187
+ const { deep: isDeep, scope } = meta;
1173
1188
  const that = toRaw(this);
1174
1189
  const len = that.length;
1175
1190
  let relativeStart = start >> 0;
@@ -1201,8 +1216,8 @@ arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
1201
1216
  return result;
1202
1217
  };
1203
1218
  arrayMethodReWrites.with = function(index, value) {
1204
- const scope = this[Keys.Scope];
1205
- const isDeep = this[Keys.Deep];
1219
+ const meta = this[Keys.Meta];
1220
+ const { deep: isDeep, scope } = meta;
1206
1221
  const that = toRaw(this);
1207
1222
  const len = that.length;
1208
1223
  let relativeIndex = Number(index) || 0;
@@ -1222,8 +1237,8 @@ arrayMethodReWrites.with = function(index, value) {
1222
1237
  return result;
1223
1238
  };
1224
1239
  arrayMethodReWrites.concat = function(...items) {
1225
- const scope = this[Keys.Scope];
1226
- const isDeep = this[Keys.Deep];
1240
+ const meta = this[Keys.Meta];
1241
+ const { deep: isDeep, scope } = meta;
1227
1242
  const that = toRaw(this);
1228
1243
  const selfLen = that.length;
1229
1244
  let totalLength = selfLen;
@@ -1303,9 +1318,9 @@ const GetMethodConf = {
1303
1318
  })
1304
1319
  ].forEach(({ key, wrapReturn, wrapArgs }) => {
1305
1320
  arrayMethodReWrites[key] = function(...args) {
1306
- const scope = this[Keys.Scope];
1321
+ const meta = this[Keys.Meta];
1307
1322
  const fn = Array.prototype[key];
1308
- const isDeep = this[Keys.Deep];
1323
+ const { deep: isDeep, scope } = meta;
1309
1324
  const that = toRaw(this);
1310
1325
  warpCallbackArgs(isDeep, args, scope, wrapArgs);
1311
1326
  let result = fn.call(that, ...args);
@@ -1318,8 +1333,8 @@ const GetMethodConf = {
1318
1333
  });
1319
1334
  arrayMethodReWrites.toSorted = function(...args) {
1320
1335
  const fn = Array.prototype["toSorted"];
1321
- const scope = this[Keys.Scope];
1322
- const isDeep = this[Keys.Deep];
1336
+ const meta = this[Keys.Meta];
1337
+ const { deep: isDeep, scope } = meta;
1323
1338
  const that = toRaw(this);
1324
1339
  warpCallbackArgs(isDeep, args, scope, 3);
1325
1340
  let result = fn.call(that, ...args);
@@ -1351,11 +1366,12 @@ var _a, _b;
1351
1366
  _b = IsStore, _a = StoreIgnoreKeys;
1352
1367
  const _Store = class _Store {
1353
1368
  constructor() {
1369
+ this.parent = () => null;
1354
1370
  const proxy = deepSignal(this, G.PullingSignal, true);
1355
1371
  _Store.Current = proxy;
1356
1372
  return proxy;
1357
1373
  }
1358
- static new(keyMap = {}) {
1374
+ static new(keyMap = {}, staticMap = {}) {
1359
1375
  const parentStore = _Store.Current;
1360
1376
  const child = new this();
1361
1377
  if (parentStore) {
@@ -1364,14 +1380,23 @@ const _Store = class _Store {
1364
1380
  shareSignal(parentStore, parentKey, child, childKey);
1365
1381
  }
1366
1382
  }
1383
+ for (const key in staticMap) {
1384
+ const value = staticMap[key];
1385
+ child[key] = value;
1386
+ }
1387
+ child.parent = () => parentStore;
1367
1388
  _Store.Current = parentStore;
1368
1389
  return child;
1369
1390
  }
1370
- set(fn) {
1371
- effect(() => {
1372
- const props = fn();
1373
- Object.assign(this, props);
1374
- });
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;
1375
1400
  }
1376
1401
  };
1377
1402
  _Store[_b] = true;
@@ -1506,4 +1531,5 @@ exports.isSignal = isSignal;
1506
1531
  exports.registerScheduler = registerScheduler;
1507
1532
  exports.runWithPulling = runWithPulling;
1508
1533
  exports.scope = scope;
1534
+ exports.shareSignal = shareSignal;
1509
1535
  //# sourceMappingURL=aoye.cjs.js.map