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/index.umd.js CHANGED
@@ -198,9 +198,7 @@
198
198
  var Keys = /* @__PURE__ */ ((Keys2) => {
199
199
  Keys2["Iterator"] = "__AOYE_ITERATOR";
200
200
  Keys2["Raw"] = "__AOYE_RAW";
201
- Keys2["Deep"] = "__AOYE_DEEP";
202
- Keys2["Scope"] = "__AOYE_SCOPE";
203
- Keys2["Cells"] = "__AOYE_CELLS";
201
+ Keys2["Meta"] = "__AOYE_META";
204
202
  return Keys2;
205
203
  })(Keys || {});
206
204
  const IsStore = /* @__PURE__ */ Symbol("__AOYE_IS_STORE"), StoreIgnoreKeys = /* @__PURE__ */ Symbol("__AOYE_IGNORE_KEYS");
@@ -927,19 +925,20 @@
927
925
  const cells = /* @__PURE__ */ new Map();
928
926
  const targetIsArray = Array.isArray(target);
929
927
  const targetIsStore = Boolean((_a = target.constructor) == null ? void 0 : _a[IsStore]);
928
+ const meta = {
929
+ deep,
930
+ scope,
931
+ cells
932
+ };
930
933
  const proxy = new Proxy(target, {
931
934
  get(obj, prop, receiver) {
932
935
  switch (prop) {
933
936
  case Keys.Raw:
934
937
  return target;
935
- case Keys.Deep:
936
- return deep;
937
- case Keys.Scope:
938
- return scope;
939
- case Keys.Cells:
940
- return cells;
938
+ case Keys.Meta:
939
+ return meta;
941
940
  }
942
- if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
941
+ if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
943
942
  return Reflect.get(obj, prop, receiver);
944
943
  }
945
944
  const desc = Reflect.getOwnPropertyDescriptor(obj, prop);
@@ -969,7 +968,7 @@
969
968
  return s.v;
970
969
  },
971
970
  set(obj, prop, value, receiver) {
972
- if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
971
+ if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
973
972
  return Reflect.set(obj, prop, value, receiver);
974
973
  }
975
974
  batch.start();
@@ -980,18 +979,21 @@
980
979
  }
981
980
  if (targetIsArray) {
982
981
  handleArraySet(obj, prop, value, receiver);
982
+ } else {
983
+ triggerIter(obj, prop, value, receiver);
983
984
  }
984
985
  batch.end();
985
986
  return success;
986
987
  },
987
988
  // 【核心修改】拦截 delete 操作
988
989
  deleteProperty(obj, prop) {
989
- if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
990
+ if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
990
991
  return Reflect.deleteProperty(obj, prop);
991
992
  }
992
993
  if (cells.has(prop)) {
993
994
  cells.delete(prop);
994
995
  }
996
+ triggerIter(obj, prop, void 0, proxy);
995
997
  return Reflect.deleteProperty(obj, prop);
996
998
  },
997
999
  ownKeys(obj) {
@@ -1013,9 +1015,9 @@
1013
1015
  runWithPulling(() => {
1014
1016
  const { target: fromTarget, key: fromKey } = getTargetAndKey(from, formPaths);
1015
1017
  fromTarget[fromKey];
1016
- const fromSignal = fromTarget[Keys.Cells].get(fromKey);
1018
+ const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
1017
1019
  const { target: toTarget, key: toKey } = getTargetAndKey(to, toPaths);
1018
- toTarget[Keys.Cells].set(toKey, fromSignal);
1020
+ toTarget[Keys.Meta].cells.set(toKey, fromSignal);
1019
1021
  }, null);
1020
1022
  } catch (error) {
1021
1023
  console.error("\u6620\u5C04\u4E86\u4E0D\u5B58\u5728\u7684Key\uFF01");
@@ -1034,6 +1036,12 @@
1034
1036
  }
1035
1037
  return { target, key };
1036
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
+ }
1037
1045
  function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
1038
1046
  if (cells.has(prop)) {
1039
1047
  return cells.get(prop).v;
@@ -1050,7 +1058,14 @@
1050
1058
  function handleArraySet(arr, prop, value, receiver) {
1051
1059
  if (prop === "length") ; else if (bobeShared.isNatureNumStr(prop)) {
1052
1060
  receiver[Keys.Iterator] = (arr[Keys.Iterator] || 0) + 1;
1053
- } 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
+ }
1054
1069
  }
1055
1070
  const arrayMethodReWrites = {};
1056
1071
  ["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach((key) => {
@@ -1089,8 +1104,8 @@
1089
1104
  const fn = Array.prototype[key];
1090
1105
  const rawArray = toRaw(this);
1091
1106
  const iter = fn.call(rawArray, ...args);
1092
- const scope = this[Keys.Scope];
1093
- const isDeep = this[Keys.Deep];
1107
+ const meta = this[Keys.Meta];
1108
+ const { deep: isDeep, scope } = meta;
1094
1109
  if (isDeep) {
1095
1110
  const rawNext = iter.next.bind(iter);
1096
1111
  iter.next = () => {
@@ -1110,8 +1125,8 @@
1110
1125
  };
1111
1126
  });
1112
1127
  arrayMethodReWrites.filter = function(callback, thisArg) {
1113
- const scope = this[Keys.Scope];
1114
- const isDeep = this[Keys.Deep];
1128
+ const meta = this[Keys.Meta];
1129
+ const { deep: isDeep, scope } = meta;
1115
1130
  const that = toRaw(this);
1116
1131
  const result = [];
1117
1132
  let resultIndex = 0;
@@ -1129,8 +1144,8 @@
1129
1144
  return result;
1130
1145
  };
1131
1146
  arrayMethodReWrites.slice = function(start, end) {
1132
- const scope = this[Keys.Scope];
1133
- const isDeep = this[Keys.Deep];
1147
+ const meta = this[Keys.Meta];
1148
+ const { deep: isDeep, scope } = meta;
1134
1149
  const that = toRaw(this);
1135
1150
  const len = that.length;
1136
1151
  let k = start || 0;
@@ -1156,8 +1171,8 @@
1156
1171
  return result;
1157
1172
  };
1158
1173
  arrayMethodReWrites.toReversed = function() {
1159
- const scope = this[Keys.Scope];
1160
- const isDeep = this[Keys.Deep];
1174
+ const meta = this[Keys.Meta];
1175
+ const { deep: isDeep, scope } = meta;
1161
1176
  const that = toRaw(this);
1162
1177
  const len = that.length;
1163
1178
  const result = new Array(len);
@@ -1170,8 +1185,8 @@
1170
1185
  return result;
1171
1186
  };
1172
1187
  arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
1173
- const scope = this[Keys.Scope];
1174
- const isDeep = this[Keys.Deep];
1188
+ const meta = this[Keys.Meta];
1189
+ const { deep: isDeep, scope } = meta;
1175
1190
  const that = toRaw(this);
1176
1191
  const len = that.length;
1177
1192
  let relativeStart = start >> 0;
@@ -1203,8 +1218,8 @@
1203
1218
  return result;
1204
1219
  };
1205
1220
  arrayMethodReWrites.with = function(index, value) {
1206
- const scope = this[Keys.Scope];
1207
- const isDeep = this[Keys.Deep];
1221
+ const meta = this[Keys.Meta];
1222
+ const { deep: isDeep, scope } = meta;
1208
1223
  const that = toRaw(this);
1209
1224
  const len = that.length;
1210
1225
  let relativeIndex = Number(index) || 0;
@@ -1224,8 +1239,8 @@
1224
1239
  return result;
1225
1240
  };
1226
1241
  arrayMethodReWrites.concat = function(...items) {
1227
- const scope = this[Keys.Scope];
1228
- const isDeep = this[Keys.Deep];
1242
+ const meta = this[Keys.Meta];
1243
+ const { deep: isDeep, scope } = meta;
1229
1244
  const that = toRaw(this);
1230
1245
  const selfLen = that.length;
1231
1246
  let totalLength = selfLen;
@@ -1305,9 +1320,9 @@
1305
1320
  })
1306
1321
  ].forEach(({ key, wrapReturn, wrapArgs }) => {
1307
1322
  arrayMethodReWrites[key] = function(...args) {
1308
- const scope = this[Keys.Scope];
1323
+ const meta = this[Keys.Meta];
1309
1324
  const fn = Array.prototype[key];
1310
- const isDeep = this[Keys.Deep];
1325
+ const { deep: isDeep, scope } = meta;
1311
1326
  const that = toRaw(this);
1312
1327
  warpCallbackArgs(isDeep, args, scope, wrapArgs);
1313
1328
  let result = fn.call(that, ...args);
@@ -1320,8 +1335,8 @@
1320
1335
  });
1321
1336
  arrayMethodReWrites.toSorted = function(...args) {
1322
1337
  const fn = Array.prototype["toSorted"];
1323
- const scope = this[Keys.Scope];
1324
- const isDeep = this[Keys.Deep];
1338
+ const meta = this[Keys.Meta];
1339
+ const { deep: isDeep, scope } = meta;
1325
1340
  const that = toRaw(this);
1326
1341
  warpCallbackArgs(isDeep, args, scope, 3);
1327
1342
  let result = fn.call(that, ...args);
@@ -1353,11 +1368,12 @@
1353
1368
  _b = IsStore, _a = StoreIgnoreKeys;
1354
1369
  const _Store = class _Store {
1355
1370
  constructor() {
1371
+ this.parent = () => null;
1356
1372
  const proxy = deepSignal(this, G.PullingSignal, true);
1357
1373
  _Store.Current = proxy;
1358
1374
  return proxy;
1359
1375
  }
1360
- static new(keyMap = {}) {
1376
+ static new(keyMap = {}, staticMap = {}) {
1361
1377
  const parentStore = _Store.Current;
1362
1378
  const child = new this();
1363
1379
  if (parentStore) {
@@ -1366,14 +1382,23 @@
1366
1382
  shareSignal(parentStore, parentKey, child, childKey);
1367
1383
  }
1368
1384
  }
1385
+ for (const key in staticMap) {
1386
+ const value = staticMap[key];
1387
+ child[key] = value;
1388
+ }
1389
+ child.parent = () => parentStore;
1369
1390
  _Store.Current = parentStore;
1370
1391
  return child;
1371
1392
  }
1372
- set(fn) {
1373
- effect(() => {
1374
- const props = fn();
1375
- Object.assign(this, props);
1376
- });
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;
1377
1402
  }
1378
1403
  };
1379
1404
  _Store[_b] = true;
@@ -1508,6 +1533,7 @@
1508
1533
  exports.registerScheduler = registerScheduler;
1509
1534
  exports.runWithPulling = runWithPulling;
1510
1535
  exports.scope = scope;
1536
+ exports.shareSignal = shareSignal;
1511
1537
 
1512
1538
  }));
1513
1539
  //# sourceMappingURL=index.umd.js.map