@openmrs/esm-react-utils 6.3.1-pre.3105 → 6.3.1-pre.3119
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/.turbo/turbo-build.log +1 -1
- package/dist/OpenmrsContext.d.ts +2 -2
- package/dist/useAppContext.d.ts +1 -1
- package/dist/useDefineAppContext.d.ts +1 -1
- package/dist/useSession.js +8 -4
- package/package.json +12 -12
- package/src/OpenmrsContext.ts +6 -2
- package/src/useAppContext.ts +7 -2
- package/src/useDefineAppContext.ts +3 -1
- package/src/useSession.ts +8 -4
package/.turbo/turbo-build.log
CHANGED
package/dist/OpenmrsContext.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface OpenmrsAppContextProps<T
|
|
1
|
+
export interface OpenmrsAppContextProps<T extends Record<string | symbol | number, unknown> = Record<string | symbol | number, any>> {
|
|
2
2
|
/** the namespace that this component defines */
|
|
3
3
|
namespace: string;
|
|
4
4
|
/** used to control the value associated with the namespace */
|
|
@@ -17,4 +17,4 @@ export interface OpenmrsAppContextProps<T = unknown> {
|
|
|
17
17
|
* context component, the `OpenmrsAppContext` is inherently global in scope. That means that _all applications_
|
|
18
18
|
* will see the values that you set for the namespace if they load the value of the namespace.
|
|
19
19
|
*/
|
|
20
|
-
export declare function OpenmrsAppContext<T extends
|
|
20
|
+
export declare function OpenmrsAppContext<T extends Record<string | symbol | number, unknown> = Record<string | symbol | number, any>>({ namespace, value }: OpenmrsAppContextProps<T>): null;
|
package/dist/useAppContext.d.ts
CHANGED
|
@@ -18,4 +18,4 @@
|
|
|
18
18
|
* @typeParam T The type of the value stored in the namespace
|
|
19
19
|
* @param namespace The namespace to load properties from
|
|
20
20
|
*/
|
|
21
|
-
export declare function useAppContext<T extends
|
|
21
|
+
export declare function useAppContext<T extends Record<string | symbol | number, unknown> = Record<string | symbol | number, any>>(namespace: string): Readonly<T> | undefined;
|
|
@@ -29,4 +29,4 @@
|
|
|
29
29
|
* the namespace value.
|
|
30
30
|
* @returns A function which can be used to update the state associated with the namespace
|
|
31
31
|
*/
|
|
32
|
-
export declare function useDefineAppContext<T extends
|
|
32
|
+
export declare function useDefineAppContext<T extends Record<string | symbol | number, unknown> = Record<string | symbol | number, any>>(namespace: string, value?: T): (update: (state: T) => T) => void;
|
package/dist/useSession.js
CHANGED
|
@@ -45,8 +45,10 @@ let promise;
|
|
|
45
45
|
if (loaded) {
|
|
46
46
|
resolve(newSession);
|
|
47
47
|
session = newSession;
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
if (unsubscribe.current) {
|
|
49
|
+
unsubscribe.current();
|
|
50
|
+
unsubscribe.current = undefined;
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
};
|
|
52
54
|
handleNewSession(getSessionStore().getState());
|
|
@@ -86,8 +88,10 @@ let promise;
|
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
90
|
return ()=>{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
if (unsubscribe.current) {
|
|
92
|
+
unsubscribe.current();
|
|
93
|
+
unsubscribe.current = undefined;
|
|
94
|
+
}
|
|
91
95
|
};
|
|
92
96
|
}, []);
|
|
93
97
|
const result = stateSession || session;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-react-utils",
|
|
3
|
-
"version": "6.3.1-pre.
|
|
3
|
+
"version": "6.3.1-pre.3119",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "React utilities for OpenMRS.",
|
|
6
6
|
"type": "module",
|
|
@@ -78,17 +78,17 @@
|
|
|
78
78
|
"swr": "2.x"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@openmrs/esm-api": "6.3.1-pre.
|
|
82
|
-
"@openmrs/esm-config": "6.3.1-pre.
|
|
83
|
-
"@openmrs/esm-context": "6.3.1-pre.
|
|
84
|
-
"@openmrs/esm-emr-api": "6.3.1-pre.
|
|
85
|
-
"@openmrs/esm-error-handling": "6.3.1-pre.
|
|
86
|
-
"@openmrs/esm-extensions": "6.3.1-pre.
|
|
87
|
-
"@openmrs/esm-feature-flags": "6.3.1-pre.
|
|
88
|
-
"@openmrs/esm-globals": "6.3.1-pre.
|
|
89
|
-
"@openmrs/esm-navigation": "6.3.1-pre.
|
|
90
|
-
"@openmrs/esm-state": "6.3.1-pre.
|
|
91
|
-
"@openmrs/esm-utils": "6.3.1-pre.
|
|
81
|
+
"@openmrs/esm-api": "6.3.1-pre.3119",
|
|
82
|
+
"@openmrs/esm-config": "6.3.1-pre.3119",
|
|
83
|
+
"@openmrs/esm-context": "6.3.1-pre.3119",
|
|
84
|
+
"@openmrs/esm-emr-api": "6.3.1-pre.3119",
|
|
85
|
+
"@openmrs/esm-error-handling": "6.3.1-pre.3119",
|
|
86
|
+
"@openmrs/esm-extensions": "6.3.1-pre.3119",
|
|
87
|
+
"@openmrs/esm-feature-flags": "6.3.1-pre.3119",
|
|
88
|
+
"@openmrs/esm-globals": "6.3.1-pre.3119",
|
|
89
|
+
"@openmrs/esm-navigation": "6.3.1-pre.3119",
|
|
90
|
+
"@openmrs/esm-state": "6.3.1-pre.3119",
|
|
91
|
+
"@openmrs/esm-utils": "6.3.1-pre.3119",
|
|
92
92
|
"@swc/cli": "^0.7.7",
|
|
93
93
|
"@swc/core": "^1.11.29",
|
|
94
94
|
"concurrently": "^9.1.2",
|
package/src/OpenmrsContext.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/** @module @category Context */
|
|
2
2
|
import { useDefineAppContext } from './useDefineAppContext';
|
|
3
3
|
|
|
4
|
-
export interface OpenmrsAppContextProps<
|
|
4
|
+
export interface OpenmrsAppContextProps<
|
|
5
|
+
T extends Record<string | symbol | number, unknown> = Record<string | symbol | number, any>,
|
|
6
|
+
> {
|
|
5
7
|
/** the namespace that this component defines */
|
|
6
8
|
namespace: string;
|
|
7
9
|
/** used to control the value associated with the namespace */
|
|
@@ -21,7 +23,9 @@ export interface OpenmrsAppContextProps<T = unknown> {
|
|
|
21
23
|
* context component, the `OpenmrsAppContext` is inherently global in scope. That means that _all applications_
|
|
22
24
|
* will see the values that you set for the namespace if they load the value of the namespace.
|
|
23
25
|
*/
|
|
24
|
-
export function OpenmrsAppContext<
|
|
26
|
+
export function OpenmrsAppContext<
|
|
27
|
+
T extends Record<string | symbol | number, unknown> = Record<string | symbol | number, any>,
|
|
28
|
+
>({ namespace, value }: OpenmrsAppContextProps<T>) {
|
|
25
29
|
useDefineAppContext<T>(namespace, value);
|
|
26
30
|
|
|
27
31
|
return null;
|
package/src/useAppContext.ts
CHANGED
|
@@ -23,7 +23,9 @@ import { shallowEqual } from '@openmrs/esm-utils';
|
|
|
23
23
|
* @typeParam T The type of the value stored in the namespace
|
|
24
24
|
* @param namespace The namespace to load properties from
|
|
25
25
|
*/
|
|
26
|
-
export function useAppContext<
|
|
26
|
+
export function useAppContext<
|
|
27
|
+
T extends Record<string | symbol | number, unknown> = Record<string | symbol | number, any>,
|
|
28
|
+
>(namespace: string): Readonly<T> | undefined;
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* This hook is used to access a namespace within the overall AppContext, so that a component can
|
|
@@ -47,7 +49,10 @@ export function useAppContext<T extends {} = {}>(namespace: string): Readonly<T>
|
|
|
47
49
|
* @param namespace The namespace to load properties from
|
|
48
50
|
* @param selector An optional function which extracts the relevant part of the state
|
|
49
51
|
*/
|
|
50
|
-
export function useAppContext<
|
|
52
|
+
export function useAppContext<
|
|
53
|
+
T extends Record<string | symbol | number, unknown> = Record<string | symbol | number, any>,
|
|
54
|
+
U = T,
|
|
55
|
+
>(
|
|
51
56
|
namespace: string,
|
|
52
57
|
selector: (state: Readonly<T> | null) => Readonly<U> = (state) => (state ?? {}) as Readonly<U>,
|
|
53
58
|
): Readonly<U> | undefined {
|
|
@@ -34,7 +34,9 @@ import { shallowEqual } from '@openmrs/esm-utils';
|
|
|
34
34
|
* the namespace value.
|
|
35
35
|
* @returns A function which can be used to update the state associated with the namespace
|
|
36
36
|
*/
|
|
37
|
-
export function useDefineAppContext<
|
|
37
|
+
export function useDefineAppContext<
|
|
38
|
+
T extends Record<string | symbol | number, unknown> = Record<string | symbol | number, any>,
|
|
39
|
+
>(namespace: string, value?: T) {
|
|
38
40
|
const previousValue = useRef<T>(value ?? ({} as T));
|
|
39
41
|
const updateFunction = useRef((update: (state: T) => T) => updateContext<T>(namespace, update));
|
|
40
42
|
|
package/src/useSession.ts
CHANGED
|
@@ -51,8 +51,10 @@ export function useSession(): Session {
|
|
|
51
51
|
if (loaded) {
|
|
52
52
|
resolve(newSession);
|
|
53
53
|
session = newSession;
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
if (unsubscribe.current) {
|
|
55
|
+
unsubscribe.current();
|
|
56
|
+
unsubscribe.current = undefined;
|
|
57
|
+
}
|
|
56
58
|
}
|
|
57
59
|
};
|
|
58
60
|
handleNewSession(getSessionStore().getState());
|
|
@@ -94,8 +96,10 @@ export function useSession(): Session {
|
|
|
94
96
|
});
|
|
95
97
|
}
|
|
96
98
|
return () => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
if (unsubscribe.current) {
|
|
100
|
+
unsubscribe.current();
|
|
101
|
+
unsubscribe.current = undefined;
|
|
102
|
+
}
|
|
99
103
|
};
|
|
100
104
|
}, []);
|
|
101
105
|
|