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