@ptolemy2002/react-proxy-context 1.0.4 → 1.0.6
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/README.md +2 -1
- package/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ A component that provides context of the specified class to its children using p
|
|
|
33
33
|
#### Props
|
|
34
34
|
- `contextClass` (Object): The class of the context to provide. This is the class that was created using `createProxyContext`.
|
|
35
35
|
- `value` (Object): The value of the context. This is what is reported when the context is not provided.
|
|
36
|
-
- `onChange` (Function): A function that is called whenever the context is changed. The first parameter is the property that was changed (null if it was reassignment), the second parameter is the current value of the
|
|
36
|
+
- `onChange` (Function): A function that is called whenever the context is changed. The first parameter is the property that was changed (null if it was reassignment), the second parameter is the current value of the property, and the third parameter is the previous value of the property. This is useful for listening to changes in the provider's parent component.
|
|
37
37
|
- `proxyRef` (Object): A ref object that is assigned the proxy object of the context. This is useful for accessing the proxy object directly by the provider's parent component.
|
|
38
38
|
|
|
39
39
|
## Hooks
|
|
@@ -45,6 +45,7 @@ A hook that uses the context provided by the `ProxyContextProvider` component. T
|
|
|
45
45
|
#### Parameters
|
|
46
46
|
- `contextClass` (Object): The class of the context to use. This is the class that was created using `createProxyContext`.
|
|
47
47
|
- `deps` (Array): An array of dependencies to listen to. If any of these properties on the context change, the hook will re-render. If this is falsy, any mutation will trigger a re-render. You can also specify a function that returns a boolean to determine whether to re-render (provided with the same arguments as `onChange` would be and a 4th argument that is the current value of the context).
|
|
48
|
+
- `onChange` (Function): A function that is called whenever the context is changed. The first parameter is the property that was changed (null if it was reassignment), the second parameter is the current value of the property, and the third parameter is the previous value of the property. This is useful for listening to changes in the provider's parent component.
|
|
48
49
|
- `listenReinit` (Boolean): Whether to listen to full reassignments of the context and re-render when they occur. Default is `true`.
|
|
49
50
|
|
|
50
51
|
#### Returns
|
package/index.js
CHANGED
|
@@ -389,7 +389,7 @@ function ProxyContextProvider({ contextClass, children, value, onChange, proxyRe
|
|
|
389
389
|
Reflect.set(target, prop, value2, newObj);
|
|
390
390
|
value2 = target[prop];
|
|
391
391
|
Object.values(changeSubscribers.current).forEach((subscriber) => {
|
|
392
|
-
if (!subscriber.deps || subscriber.deps.includes(prop) && prevValue !== value2 || subscriber.deps.some((subProp) => (0, import_is_callable.default)(subProp) && subProp(prop, value2, prevValue,
|
|
392
|
+
if (!subscriber.deps || subscriber.deps.includes(prop) && prevValue !== value2 || subscriber.deps.some((subProp) => (0, import_is_callable.default)(subProp) && subProp(prop, value2, prevValue, newObj))) {
|
|
393
393
|
subscriber.callback(prop, value2, prevValue);
|
|
394
394
|
}
|
|
395
395
|
});
|