mol_wire_lib 1.0.1341 → 1.0.1343

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.mjs CHANGED
@@ -1934,18 +1934,42 @@ var $;
1934
1934
  factories.set(val, make);
1935
1935
  return make;
1936
1936
  }
1937
+ const getters = new WeakMap();
1938
+ function get_prop(host, field) {
1939
+ let props = getters.get(host);
1940
+ let get_val = props?.[field];
1941
+ if (get_val)
1942
+ return get_val;
1943
+ get_val = (next) => {
1944
+ if (next !== undefined)
1945
+ host[field] = next;
1946
+ return host[field];
1947
+ };
1948
+ Object.defineProperty(get_val, 'name', { value: field });
1949
+ if (!props) {
1950
+ props = {};
1951
+ getters.set(host, props);
1952
+ }
1953
+ props[field] = get_val;
1954
+ return get_val;
1955
+ }
1937
1956
  function $mol_wire_sync(obj) {
1938
1957
  return new Proxy(obj, {
1939
1958
  get(obj, field) {
1940
1959
  let val = obj[field];
1960
+ const temp = $mol_wire_task.getter(typeof val === 'function' ? val : get_prop(obj, field));
1941
1961
  if (typeof val !== 'function')
1942
- return val;
1943
- const temp = $mol_wire_task.getter(val);
1962
+ return temp(obj, []).sync();
1944
1963
  return function $mol_wire_sync(...args) {
1945
1964
  const fiber = temp(obj, args);
1946
1965
  return fiber.sync();
1947
1966
  };
1948
1967
  },
1968
+ set(obj, field, next) {
1969
+ const temp = $mol_wire_task.getter(get_prop(obj, field));
1970
+ temp(obj, [next]).sync();
1971
+ return true;
1972
+ },
1949
1973
  construct(obj, args) {
1950
1974
  const temp = $mol_wire_task.getter(factory(obj));
1951
1975
  return temp(obj, args).sync();
package/node.test.js CHANGED
@@ -1925,18 +1925,42 @@ var $;
1925
1925
  factories.set(val, make);
1926
1926
  return make;
1927
1927
  }
1928
+ const getters = new WeakMap();
1929
+ function get_prop(host, field) {
1930
+ let props = getters.get(host);
1931
+ let get_val = props?.[field];
1932
+ if (get_val)
1933
+ return get_val;
1934
+ get_val = (next) => {
1935
+ if (next !== undefined)
1936
+ host[field] = next;
1937
+ return host[field];
1938
+ };
1939
+ Object.defineProperty(get_val, 'name', { value: field });
1940
+ if (!props) {
1941
+ props = {};
1942
+ getters.set(host, props);
1943
+ }
1944
+ props[field] = get_val;
1945
+ return get_val;
1946
+ }
1928
1947
  function $mol_wire_sync(obj) {
1929
1948
  return new Proxy(obj, {
1930
1949
  get(obj, field) {
1931
1950
  let val = obj[field];
1951
+ const temp = $mol_wire_task.getter(typeof val === 'function' ? val : get_prop(obj, field));
1932
1952
  if (typeof val !== 'function')
1933
- return val;
1934
- const temp = $mol_wire_task.getter(val);
1953
+ return temp(obj, []).sync();
1935
1954
  return function $mol_wire_sync(...args) {
1936
1955
  const fiber = temp(obj, args);
1937
1956
  return fiber.sync();
1938
1957
  };
1939
1958
  },
1959
+ set(obj, field, next) {
1960
+ const temp = $mol_wire_task.getter(get_prop(obj, field));
1961
+ temp(obj, [next]).sync();
1962
+ return true;
1963
+ },
1940
1964
  construct(obj, args) {
1941
1965
  const temp = $mol_wire_task.getter(factory(obj));
1942
1966
  return temp(obj, args).sync();