@ptolemy2002/react-proxy-context 1.0.8 → 1.0.10

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.
Files changed (2) hide show
  1. package/index.js +2 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -359,6 +359,7 @@ function ProxyContextProvider({ contextClass, children, value, onChange, proxyRe
359
359
  const objRef = (0, import_react.useRef)();
360
360
  const contextRef = (0, import_react.useRef)({});
361
361
  const forceRerender = (0, import_react_force_rerender.default)();
362
+ (0, import_react.useImperativeHandle)(proxyRef, () => objRef.current, [objRef.current]);
362
363
  const subscribe = (0, import_react.useCallback)((callback, deps, listenReinit = true) => {
363
364
  const id = nanoid();
364
365
  changeSubscribers.current[id] = {
@@ -391,13 +392,11 @@ function ProxyContextProvider({ contextClass, children, value, onChange, proxyRe
391
392
  value2 = target[prop];
392
393
  Object.values(changeSubscribers.current).forEach((subscriber) => {
393
394
  if (!subscriber.deps || subscriber.deps.includes(prop) && prevValue !== value2 || subscriber.deps.some((subProp) => (0, import_is_callable.default)(subProp) && subProp(prop, value2, prevValue, newObj))) {
395
+ console.log("Calling subscriber:", subscriber);
394
396
  subscriber.callback(prop, value2, prevValue);
395
397
  }
396
398
  });
397
399
  if ((0, import_is_callable.default)(onChange)) onChange(prop, value2, prevValue);
398
- Object.values(changeSubscribers.current).forEach((subscriber) => {
399
- subscriber.callback(prop, value2, prevValue);
400
- });
401
400
  return true;
402
401
  }
403
402
  });
@@ -409,7 +408,6 @@ function ProxyContextProvider({ contextClass, children, value, onChange, proxyRe
409
408
  subscriber.callback(null, objRef.current, prevObj);
410
409
  }
411
410
  });
412
- proxyRef && (proxyRef.current = objRef.current);
413
411
  if ((0, import_is_callable.default)(onChange)) onChange(null, objRef.current, prevObj);
414
412
  forceRerender();
415
413
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/react-proxy-context",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js"