@openmrs/esm-context 9.0.3-pre.4558 → 9.0.3-pre.4622
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/context.d.ts.map +1 -1
- package/dist/context.js +6 -4
- package/package.json +5 -5
- package/src/context.ts +7 -4
package/.turbo/turbo-build.log
CHANGED
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAMA,UAAU,iBAAiB;IACzB,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;CAC1C;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,uDAA+C,CAAC;AAMzE;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,EACjF,SAAS,EAAE,MAAM,EACjB,YAAY,GAAE,CAAW,QAW1B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,QAOlD;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AAsBvH;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,EAC/E,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,QAUxB;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CACjF,KAA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IAAI,GAAG,SAAS,KAClC,IAAI,CAAC;AAEV;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,EACpF,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,cAc7B"}
|
package/dist/context.js
CHANGED
|
@@ -69,13 +69,15 @@ const nothing = Object();
|
|
|
69
69
|
* @returns A function to unsubscribe from the context
|
|
70
70
|
*/ export function subscribeToContext(namespace, callback) {
|
|
71
71
|
let previous = getContext(namespace);
|
|
72
|
-
|
|
73
|
-
callback(Object.freeze(Object.assign({}, previous)));
|
|
72
|
+
callback(snapshot(previous));
|
|
74
73
|
return contextStore.subscribe((state)=>{
|
|
75
|
-
|
|
74
|
+
const current = namespace in state ? state[namespace] : null;
|
|
76
75
|
if (current !== previous) {
|
|
77
76
|
previous = current;
|
|
78
|
-
callback(
|
|
77
|
+
callback(snapshot(current));
|
|
79
78
|
}
|
|
80
79
|
});
|
|
81
80
|
}
|
|
81
|
+
function snapshot(value) {
|
|
82
|
+
return value === null ? null : Object.freeze(Object.assign({}, value));
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-context",
|
|
3
|
-
"version": "9.0.3-pre.
|
|
3
|
+
"version": "9.0.3-pre.4622",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Utilities for managing the current execution context",
|
|
6
6
|
"type": "module",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"source": true,
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"scripts": {
|
|
22
|
-
"test": "cross-env TZ=UTC vitest run --passWithNoTests",
|
|
23
|
-
"test:watch": "cross-env TZ=UTC vitest watch --passWithNoTests",
|
|
24
22
|
"build": "rimraf dist && concurrently \"swc --strip-leading-paths src -d dist\" \"tsc --project tsconfig.build.json\"",
|
|
25
23
|
"build:development": "rimraf dist && concurrently \"swc --strip-leading-paths src -d dist\" \"tsc --project tsconfig.build.json\"",
|
|
26
24
|
"typescript": "tsc --project tsconfig.build.json",
|
|
27
25
|
"lint": "eslint src --ext ts,tsx",
|
|
26
|
+
"test": "cross-env TZ=UTC vitest run --passWithNoTests",
|
|
27
|
+
"test:watch": "cross-env TZ=UTC vitest watch --passWithNoTests",
|
|
28
28
|
"coverage": "cross-env TZ=UTC vitest run --coverage --passWithNoTests"
|
|
29
29
|
},
|
|
30
30
|
"keywords": [
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@openmrs/esm-state": "9.x"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@openmrs/esm-globals": "9.0.3-pre.
|
|
58
|
-
"@openmrs/esm-state": "9.0.3-pre.
|
|
57
|
+
"@openmrs/esm-globals": "9.0.3-pre.4622",
|
|
58
|
+
"@openmrs/esm-state": "9.0.3-pre.4622",
|
|
59
59
|
"@swc/cli": "0.8.1",
|
|
60
60
|
"@swc/core": "1.15.21",
|
|
61
61
|
"@vitest/coverage-v8": "^4.1.2",
|
package/src/context.ts
CHANGED
|
@@ -117,15 +117,18 @@ export function subscribeToContext<T extends NonNullable<object> = NonNullable<o
|
|
|
117
117
|
) {
|
|
118
118
|
let previous = getContext<T>(namespace);
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
callback(Object.freeze(Object.assign({}, previous)));
|
|
120
|
+
callback(snapshot(previous));
|
|
122
121
|
|
|
123
122
|
return contextStore.subscribe((state) => {
|
|
124
|
-
|
|
123
|
+
const current: Readonly<T> | null = namespace in state ? (state[namespace] as T) : null;
|
|
125
124
|
|
|
126
125
|
if (current !== previous) {
|
|
127
126
|
previous = current;
|
|
128
|
-
callback(
|
|
127
|
+
callback(snapshot(current));
|
|
129
128
|
}
|
|
130
129
|
});
|
|
131
130
|
}
|
|
131
|
+
|
|
132
|
+
function snapshot<T extends NonNullable<object> = NonNullable<object>>(value: Readonly<T> | null): Readonly<T> | null {
|
|
133
|
+
return value === null ? null : Object.freeze(Object.assign({}, value));
|
|
134
|
+
}
|