@ptolemy2002/react-proxy-context 1.0.6 → 1.0.8
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/index.js +5 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -358,6 +358,7 @@ function ProxyContextProvider({ contextClass, children, value, onChange, proxyRe
|
|
|
358
358
|
const changeSubscribers = (0, import_react.useRef)({});
|
|
359
359
|
const objRef = (0, import_react.useRef)();
|
|
360
360
|
const contextRef = (0, import_react.useRef)({});
|
|
361
|
+
const forceRerender = (0, import_react_force_rerender.default)();
|
|
361
362
|
const subscribe = (0, import_react.useCallback)((callback, deps, listenReinit = true) => {
|
|
362
363
|
const id = nanoid();
|
|
363
364
|
changeSubscribers.current[id] = {
|
|
@@ -400,6 +401,8 @@ function ProxyContextProvider({ contextClass, children, value, onChange, proxyRe
|
|
|
400
401
|
return true;
|
|
401
402
|
}
|
|
402
403
|
});
|
|
404
|
+
} else {
|
|
405
|
+
objRef.current = newObj;
|
|
403
406
|
}
|
|
404
407
|
Object.values(changeSubscribers.current).forEach((subscriber) => {
|
|
405
408
|
if (subscriber.listenReinit) {
|
|
@@ -408,6 +411,7 @@ function ProxyContextProvider({ contextClass, children, value, onChange, proxyRe
|
|
|
408
411
|
});
|
|
409
412
|
proxyRef && (proxyRef.current = objRef.current);
|
|
410
413
|
if ((0, import_is_callable.default)(onChange)) onChange(null, objRef.current, prevObj);
|
|
414
|
+
forceRerender();
|
|
411
415
|
}
|
|
412
416
|
return objRef.current;
|
|
413
417
|
}, [onChange, proxyRef]);
|
|
@@ -430,6 +434,7 @@ function useProxyContext(contextClass, deps, onChange, listenReinit = true) {
|
|
|
430
434
|
forceRerender();
|
|
431
435
|
if ((0, import_is_callable.default)(onChange)) onChange(prop, current, prev);
|
|
432
436
|
}, deps, listenReinit);
|
|
437
|
+
forceRerender();
|
|
433
438
|
});
|
|
434
439
|
(0, import_react_mount_effects.useUnmountEffect)(() => {
|
|
435
440
|
context?.unsubscribe(id.current);
|