aoye 0.0.53 → 0.0.54

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
@@ -767,10 +767,10 @@ const trackIterator = (cells, scope) => {
767
767
  }
768
768
  iter.get();
769
769
  };
770
- const triggerIterator = (cells, raw) => {
770
+ const triggerIterator = cells => {
771
771
  const iter = cells.get(Keys.Iterator);
772
772
  if (iter) {
773
- iter.set((raw[Keys.Iterator] || 0) + 1);
773
+ iter.set((iter.value || 0) + 1);
774
774
  }
775
775
  };
776
776
  const trackKey = (cells, scope, key) => {
@@ -822,7 +822,7 @@ const createSharedHandler = (cells, scope, deep, targetIsMap) => {
822
822
  if (had) {
823
823
  triggerKey(cells, key);
824
824
  cells.delete(key);
825
- triggerIterator(cells, target);
825
+ triggerIterator(cells);
826
826
  }
827
827
  batchEnd();
828
828
  return result;
@@ -836,7 +836,7 @@ const createSharedHandler = (cells, scope, deep, targetIsMap) => {
836
836
  cells.clear();
837
837
  if (iterCell) cells.set(Keys.Iterator, iterCell);
838
838
  if (hadItems) {
839
- triggerIterator(cells, target);
839
+ triggerIterator(cells);
840
840
  }
841
841
  batchEnd();
842
842
  },
@@ -881,7 +881,7 @@ const createMapHandler = (cells, scope, deep) => ({
881
881
  } else {
882
882
  cell.set(value);
883
883
  }
884
- triggerIterator(cells, target);
884
+ triggerIterator(cells);
885
885
  batchEnd();
886
886
  return this;
887
887
  }
@@ -901,7 +901,7 @@ const createSetHandler = (cells, scope, _deep) => ({
901
901
  cell.set(value);
902
902
  }
903
903
  if (!had) {
904
- triggerIterator(cells, target);
904
+ triggerIterator(cells);
905
905
  }
906
906
  batchEnd();
907
907
  return this;
@@ -1404,6 +1404,7 @@ function warpCallbackArgs(isDeep, args, scope, wrapArgs = 0b01) {
1404
1404
  args[0] = wrapCb;
1405
1405
  }
1406
1406
 
1407
+ const isParentKey = (parentStore, expr) => expr in parentStore[Keys.Raw];
1407
1408
  class Store {
1408
1409
  static [IsStore] = true;
1409
1410
  static [StoreIgnoreKeys] = ['ui', 'raw'];
@@ -1414,18 +1415,31 @@ class Store {
1414
1415
  return proxy;
1415
1416
  }
1416
1417
  parent = () => null;
1417
- static new(keyMap = {}, staticMap = {}) {
1418
+ static new(keyMap, staticMap) {
1418
1419
  const parentStore = Store.Current;
1419
1420
  const child = new this();
1420
- if (parentStore) {
1421
+ if (parentStore && keyMap) {
1422
+ const cells = child[Keys.Meta].cells;
1421
1423
  for (const childKey in keyMap) {
1422
- const parentKey = keyMap[childKey];
1423
- shareSignal(parentStore, parentKey, child, childKey);
1424
+ const expr = keyMap[childKey];
1425
+ if (typeof expr === 'function') {
1426
+ cells.set(childKey, new Computed(() => expr(parentStore)));
1427
+ child[Keys.Raw][childKey] = undefined;
1428
+ } else if (typeof expr === 'string') {
1429
+ if (isParentKey(parentStore, expr)) {
1430
+ shareSignal(parentStore, expr, child, childKey);
1431
+ } else {
1432
+ const fn = new Function('data', `let v;with(data){v=${expr};}return v;`);
1433
+ cells.set(childKey, new Computed(() => fn(parentStore)));
1434
+ child[Keys.Raw][childKey] = undefined;
1435
+ }
1436
+ } else {
1437
+ shareSignal(parentStore, expr, child, childKey);
1438
+ }
1424
1439
  }
1425
1440
  }
1426
1441
  for (const key in staticMap) {
1427
- const value = staticMap[key];
1428
- child[key] = value;
1442
+ child[key] = staticMap[key];
1429
1443
  }
1430
1444
  child.parent = () => parentStore;
1431
1445
  Store.Current = parentStore;