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