aoye 0.0.8 → 0.0.9

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
@@ -200,8 +200,10 @@
200
200
  Keys2["Raw"] = "__AOYE_RAW";
201
201
  Keys2["Deep"] = "__AOYE_DEEP";
202
202
  Keys2["Scope"] = "__AOYE_SCOPE";
203
+ Keys2["Cells"] = "__AOYE_CELLS";
203
204
  return Keys2;
204
205
  })(Keys || {});
206
+ const IsStore = /* @__PURE__ */ Symbol("__AOYE_IS_STORE"), StoreIgnoreKeys = /* @__PURE__ */ Symbol("__AOYE_IGNORE_KEYS");
205
207
 
206
208
  let channel = globalThis.MessageChannel ? new MessageChannel() : null;
207
209
  if (globalThis.MessageChannel) {
@@ -264,7 +266,7 @@
264
266
  onOneSetEffectsAdded(subQueue, queue) {
265
267
  subQueue.forEach((effect, item) => {
266
268
  effect.runIfDirty();
267
- subQueue.delete(item);
269
+ queue.delete(item);
268
270
  });
269
271
  }
270
272
  }
@@ -277,7 +279,7 @@
277
279
  const task = () => {
278
280
  subQueue.forEach((effect, item) => {
279
281
  effect.runIfDirty();
280
- subQueue.delete(item);
282
+ queue.delete(item);
281
283
  });
282
284
  return {
283
285
  finished: true,
@@ -297,7 +299,7 @@
297
299
  const task = () => {
298
300
  subQueue.forEach((effect, item) => {
299
301
  effect.runIfDirty();
300
- subQueue.delete(item);
302
+ queue.delete(item);
301
303
  });
302
304
  };
303
305
  task.time = Date.now();
@@ -313,7 +315,7 @@
313
315
  const task = () => {
314
316
  subQueue.forEach((effect, item) => {
315
317
  effect.runIfDirty();
316
- subQueue.delete(item);
318
+ queue.delete(item);
317
319
  });
318
320
  };
319
321
  task.time = Date.now();
@@ -918,11 +920,13 @@
918
920
  };
919
921
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
920
922
  const deepSignal = (target, scope, deep = true) => {
923
+ var _a;
921
924
  const isObj = typeof target === "object" && target !== null;
922
925
  if (!isObj || target[Keys.Raw]) return target;
923
926
  if (rawToProxy.has(target)) return rawToProxy.get(target);
924
927
  const cells = /* @__PURE__ */ new Map();
925
928
  const targetIsArray = Array.isArray(target);
929
+ const targetIsStore = Boolean((_a = target.constructor) == null ? void 0 : _a[IsStore]);
926
930
  const proxy = new Proxy(target, {
927
931
  get(obj, prop, receiver) {
928
932
  switch (prop) {
@@ -932,6 +936,16 @@
932
936
  return deep;
933
937
  case Keys.Scope:
934
938
  return scope;
939
+ case Keys.Cells:
940
+ return cells;
941
+ }
942
+ if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
943
+ return Reflect.get(obj, prop, receiver);
944
+ }
945
+ const desc = Reflect.getOwnPropertyDescriptor(obj, prop);
946
+ const isGetter = desc && typeof desc.get === "function";
947
+ if (isGetter) {
948
+ return handleGetterAsComputed(obj, prop, receiver, cells, scope);
935
949
  }
936
950
  const value = Reflect.get(obj, prop, receiver);
937
951
  const valueIsFn = typeof value === "function";
@@ -955,6 +969,9 @@
955
969
  return s.v;
956
970
  },
957
971
  set(obj, prop, value, receiver) {
972
+ if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
973
+ return Reflect.set(obj, prop, value, receiver);
974
+ }
958
975
  batch.start();
959
976
  const success = Reflect.set(obj, prop, value, receiver);
960
977
  if (cells.has(prop)) {
@@ -969,6 +986,9 @@
969
986
  },
970
987
  // 【核心修改】拦截 delete 操作
971
988
  deleteProperty(obj, prop) {
989
+ if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
990
+ return Reflect.deleteProperty(obj, prop);
991
+ }
972
992
  if (cells.has(prop)) {
973
993
  cells.delete(prop);
974
994
  }
@@ -986,6 +1006,47 @@
986
1006
  rawToProxy.set(target, proxy);
987
1007
  return proxy;
988
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.Cells].get(fromKey);
1017
+ const { target: toTarget, key: toKey } = getTargetAndKey(to, toPaths);
1018
+ toTarget[Keys.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 handleGetterAsComputed(obj, prop, receiver, cells, scope) {
1038
+ if (cells.has(prop)) {
1039
+ return cells.get(prop).v;
1040
+ }
1041
+ const s = Signal.create(null, {
1042
+ customPull: () => Reflect.get(obj, prop, receiver),
1043
+ scheduler: Scheduler.Sync,
1044
+ isScope: false,
1045
+ scope
1046
+ });
1047
+ cells.set(prop, s);
1048
+ return s.v;
1049
+ }
989
1050
  function handleArraySet(arr, prop, value, receiver) {
990
1051
  if (prop === "length") ; else if (bobeShared.isNatureNumStr(prop)) {
991
1052
  receiver[Keys.Iterator] = (arr[Keys.Iterator] || 0) + 1;
@@ -1288,6 +1349,38 @@
1288
1349
  args[0] = wrapCb;
1289
1350
  }
1290
1351
 
1352
+ var _a, _b;
1353
+ _b = IsStore, _a = StoreIgnoreKeys;
1354
+ const _Store = class _Store {
1355
+ constructor() {
1356
+ const proxy = deepSignal(this, G.PullingSignal, true);
1357
+ _Store.Current = proxy;
1358
+ return proxy;
1359
+ }
1360
+ static new(keyMap = {}) {
1361
+ const parentStore = _Store.Current;
1362
+ const child = new this();
1363
+ if (parentStore) {
1364
+ for (const childKey in keyMap) {
1365
+ const parentKey = keyMap[childKey];
1366
+ shareSignal(parentStore, parentKey, child, childKey);
1367
+ }
1368
+ }
1369
+ _Store.Current = parentStore;
1370
+ return child;
1371
+ }
1372
+ set(fn) {
1373
+ effect(() => {
1374
+ const props = fn();
1375
+ Object.assign(this, props);
1376
+ });
1377
+ }
1378
+ };
1379
+ _Store[_b] = true;
1380
+ _Store[_a] = ["ui", "raw"];
1381
+ _Store.Current = null;
1382
+ let Store = _Store;
1383
+
1291
1384
  var __defProp = Object.defineProperty;
1292
1385
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1293
1386
  var __hasOwnProp = Object.prototype.hasOwnProperty;
@@ -1400,8 +1493,11 @@
1400
1493
  };
1401
1494
 
1402
1495
  exports.$ = $;
1496
+ exports.IsStore = IsStore;
1403
1497
  exports.Keys = Keys;
1404
1498
  exports.Scheduler = Scheduler;
1499
+ exports.Store = Store;
1500
+ exports.StoreIgnoreKeys = StoreIgnoreKeys;
1405
1501
  exports.TaskQueue = TaskQueue;
1406
1502
  exports.batch = batch;
1407
1503
  exports.clean = clean;