mol_mutable 0.0.836 → 0.0.838

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/node.test.js CHANGED
@@ -1691,18 +1691,42 @@ var $;
1691
1691
  factories.set(val, make);
1692
1692
  return make;
1693
1693
  }
1694
+ const getters = new WeakMap();
1695
+ function get_prop(host, field) {
1696
+ let props = getters.get(host);
1697
+ let get_val = props?.[field];
1698
+ if (get_val)
1699
+ return get_val;
1700
+ get_val = (next) => {
1701
+ if (next !== undefined)
1702
+ host[field] = next;
1703
+ return host[field];
1704
+ };
1705
+ Object.defineProperty(get_val, 'name', { value: field });
1706
+ if (!props) {
1707
+ props = {};
1708
+ getters.set(host, props);
1709
+ }
1710
+ props[field] = get_val;
1711
+ return get_val;
1712
+ }
1694
1713
  function $mol_wire_sync(obj) {
1695
1714
  return new Proxy(obj, {
1696
1715
  get(obj, field) {
1697
1716
  let val = obj[field];
1717
+ const temp = $mol_wire_task.getter(typeof val === 'function' ? val : get_prop(obj, field));
1698
1718
  if (typeof val !== 'function')
1699
- return val;
1700
- const temp = $mol_wire_task.getter(val);
1719
+ return temp(obj, []).sync();
1701
1720
  return function $mol_wire_sync(...args) {
1702
1721
  const fiber = temp(obj, args);
1703
1722
  return fiber.sync();
1704
1723
  };
1705
1724
  },
1725
+ set(obj, field, next) {
1726
+ const temp = $mol_wire_task.getter(get_prop(obj, field));
1727
+ temp(obj, [next]).sync();
1728
+ return true;
1729
+ },
1706
1730
  construct(obj, args) {
1707
1731
  const temp = $mol_wire_task.getter(factory(obj));
1708
1732
  return temp(obj, args).sync();