@ptolemy2002/react-proxy-context 1.2.0 → 2.0.0
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 +7 -8
- package/dist/main.d.ts +30 -0
- package/dist/main.js +721 -0
- package/package.json +74 -45
- package/index.js +0 -872
package/README.md
CHANGED
|
@@ -51,16 +51,15 @@ A hook that uses the context provided by the `ProxyContextProvider` component. T
|
|
|
51
51
|
#### Returns
|
|
52
52
|
Array - An array with the first element being the current value of the context and the second element being a setter function to reassign the context.
|
|
53
53
|
|
|
54
|
-
## Meta
|
|
55
|
-
This is a React Library Created by Ptolemy2002's [cra-template-react-library](https://www.npmjs.com/package/@ptolemy2002/cra-template-react-library) template in combination with [create-react-app](https://www.npmjs.com/package/create-react-app). It contains methods of building and publishing your library to npm.
|
|
56
|
-
For now, the library makes use of React 18 and does not use TypeScript.
|
|
57
|
-
|
|
58
54
|
## Peer Dependencies
|
|
59
55
|
These should be installed in order to use the library, as npm does not automatically add peer dependencies to your project.
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
- react-
|
|
56
|
+
- `react^18.3.1`
|
|
57
|
+
- `react-dom^18.3.1`
|
|
58
|
+
- `@ptolemy2002/js-utils^3.0.2`
|
|
59
|
+
- `@ptolemy2002/react-utils^3.0.0`
|
|
60
|
+
- `@ptolemy2002/react-force-rerender^2.0.0`
|
|
61
|
+
- `@ptolemy2002/react-hook-result^2.1.1`
|
|
62
|
+
- `@ptolemy2002/react-mount-effects^2.0.0`
|
|
64
63
|
|
|
65
64
|
## Commands
|
|
66
65
|
The following commands exist in the project:
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Context, ReactNode } from 'react';
|
|
2
|
+
import { HookResultData } from '@ptolemy2002/react-hook-result';
|
|
3
|
+
export type ContextWithName<T> = Context<T> & {
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
export type OnChangePropCallback<T> = <K extends keyof T>(prop: K, current: T[K], prev?: T[K]) => void;
|
|
7
|
+
export type OnChangeReinitCallback<T> = (current: T, prev?: T) => void;
|
|
8
|
+
export type ProxyContextValue<T> = {
|
|
9
|
+
obj: T;
|
|
10
|
+
set: (newObj: T) => T;
|
|
11
|
+
subscribe: (propCallback: OnChangePropCallback<T>, reinitCallback: OnChangeReinitCallback<T>, deps: Dependency<T>[]) => string;
|
|
12
|
+
unsubscribe: (id: string) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare function createProxyContext<T>(name: string): ContextWithName<ProxyContextValue<T> | undefined>;
|
|
15
|
+
export type Dependency<T> = keyof T | (<K extends keyof T>(prop: K, current: T[K], prev: T[K], obj: T) => boolean) | null | undefined | false;
|
|
16
|
+
export type ProxyContextProviderProps<T> = {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
value: T;
|
|
19
|
+
onChangeProp?: OnChangePropCallback<T>;
|
|
20
|
+
onChangeReinit?: OnChangeReinitCallback<T>;
|
|
21
|
+
proxyRef?: React.MutableRefObject<T>;
|
|
22
|
+
};
|
|
23
|
+
export declare function createProxyContextProvider<T extends object>(contextClass: ContextWithName<ProxyContextValue<T> | undefined>): import('react').MemoExoticComponent<import('react').FunctionComponent<ProxyContextProviderProps<T> & {
|
|
24
|
+
renderDeps?: any[];
|
|
25
|
+
}>>;
|
|
26
|
+
export type UseProxyContextResult<T> = HookResultData<{
|
|
27
|
+
value: T;
|
|
28
|
+
set: (newObj: T) => T;
|
|
29
|
+
}, readonly [T, (newObj: T) => T]>;
|
|
30
|
+
export declare function useProxyContext<T>(contextClass: ContextWithName<ProxyContextValue<T> | undefined>, deps?: Dependency<T>[], onChangeProp?: OnChangePropCallback<T>, onChangeReinit?: OnChangeReinitCallback<T>, listenReinit?: boolean): UseProxyContextResult<T>;
|