mol_tree2 1.0.1009 → 1.0.1010

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
@@ -3970,18 +3970,42 @@ var $;
3970
3970
  factories.set(val, make);
3971
3971
  return make;
3972
3972
  }
3973
+ const getters = new WeakMap();
3974
+ function get_prop(host, field) {
3975
+ let props = getters.get(host);
3976
+ let get_val = props?.[field];
3977
+ if (get_val)
3978
+ return get_val;
3979
+ get_val = (next) => {
3980
+ if (next !== undefined)
3981
+ host[field] = next;
3982
+ return host[field];
3983
+ };
3984
+ Object.defineProperty(get_val, 'name', { value: field });
3985
+ if (!props) {
3986
+ props = {};
3987
+ getters.set(host, props);
3988
+ }
3989
+ props[field] = get_val;
3990
+ return get_val;
3991
+ }
3973
3992
  function $mol_wire_sync(obj) {
3974
3993
  return new Proxy(obj, {
3975
3994
  get(obj, field) {
3976
3995
  let val = obj[field];
3996
+ const temp = $mol_wire_task.getter(typeof val === 'function' ? val : get_prop(obj, field));
3977
3997
  if (typeof val !== 'function')
3978
- return val;
3979
- const temp = $mol_wire_task.getter(val);
3998
+ return temp(obj, []).sync();
3980
3999
  return function $mol_wire_sync(...args) {
3981
4000
  const fiber = temp(obj, args);
3982
4001
  return fiber.sync();
3983
4002
  };
3984
4003
  },
4004
+ set(obj, field, next) {
4005
+ const temp = $mol_wire_task.getter(get_prop(obj, field));
4006
+ temp(obj, [next]).sync();
4007
+ return true;
4008
+ },
3985
4009
  construct(obj, args) {
3986
4010
  const temp = $mol_wire_task.getter(factory(obj));
3987
4011
  return temp(obj, args).sync();