@openmrs/esm-state 6.3.1-pre.2961 → 6.3.1-pre.2986

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/.swcrc ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://swc.rs/schema.json",
3
+ "exclude": [".*\\.test\\..*", "setup-tests\\..*"],
4
+ "module": {
5
+ "type": "es6",
6
+ "resolveFully": true
7
+ },
8
+ "jsc": {
9
+ "parser": {
10
+ "syntax": "typescript",
11
+ "tsx": false
12
+ },
13
+ "target": "es2020",
14
+ "baseUrl": "src"
15
+ }
16
+ }
@@ -1,7 +1,3 @@
1
- asset openmrs-esm-state.js 3.26 KiB [emitted] [minimized] (name: main) 1 related asset
2
- runtime modules 670 bytes 3 modules
3
- orphan modules 6.83 KiB [orphan] 2 modules
4
- built modules 6.89 KiB [built]
5
- ./src/index.ts + 2 modules 6.85 KiB [built] [code generated]
6
- external "@openmrs/esm-utils" 42 bytes [built] [code generated]
7
- webpack 5.88.0 compiled successfully in 3689 ms
1
+ [0] Successfully compiled: 3 files with swc (89.09ms)
2
+ [0] swc --strip-leading-paths src -d dist exited with code 0
3
+ [1] tsc --project tsconfig.build.json exited with code 0
@@ -0,0 +1 @@
1
+ export * from './state';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./state.js";
@@ -0,0 +1 @@
1
+ export { createGlobalStore, getGlobalStore, subscribeTo } from './state';
package/dist/public.js ADDED
@@ -0,0 +1 @@
1
+ export { createGlobalStore, getGlobalStore, subscribeTo } from "./state.js";
@@ -0,0 +1,30 @@
1
+ import type { StoreApi } from 'zustand/vanilla';
2
+ /**
3
+ * Creates a Zustand store.
4
+ *
5
+ * @param name A name by which the store can be looked up later.
6
+ * Must be unique across the entire application.
7
+ * @param initialState An object which will be the initial state of the store.
8
+ * @returns The newly created store.
9
+ */
10
+ export declare function createGlobalStore<T>(name: string, initialState: T): StoreApi<T>;
11
+ /**
12
+ * Registers an existing Zustand store.
13
+ *
14
+ * @param name A name by which the store can be looked up later.
15
+ * Must be unique across the entire application.
16
+ * @param store The Zustand store to use for this.
17
+ * @returns The newly registered store.
18
+ */
19
+ export declare function registerGlobalStore<T>(name: string, store: StoreApi<T>): StoreApi<T>;
20
+ /**
21
+ * Returns the existing store named `name`,
22
+ * or creates a new store named `name` if none exists.
23
+ *
24
+ * @param name The name of the store to look up.
25
+ * @param fallbackState The initial value of the new store if no store named `name` exists.
26
+ * @returns The found or newly created store.
27
+ */
28
+ export declare function getGlobalStore<T>(name: string, fallbackState?: T): StoreApi<T>;
29
+ export declare function subscribeTo<T, U = T>(store: StoreApi<T>, handle: (state: T) => void): () => void;
30
+ export declare function subscribeTo<T, U>(store: StoreApi<T>, select: (state: T) => U, handle: (subState: U) => void): () => void;
package/dist/state.js ADDED
@@ -0,0 +1,92 @@
1
+ /** @module @category Store */ import { shallowEqual } from "@openmrs/esm-utils";
2
+ import { createStore } from "zustand/vanilla";
3
+ const availableStores = {};
4
+ // spaEnv isn't available immediately. Wait a bit before making stores available
5
+ // on window in development mode.
6
+ setTimeout(()=>{
7
+ if (window.spaEnv === 'development') {
8
+ window['stores'] = availableStores;
9
+ }
10
+ }, 1000);
11
+ /**
12
+ * Creates a Zustand store.
13
+ *
14
+ * @param name A name by which the store can be looked up later.
15
+ * Must be unique across the entire application.
16
+ * @param initialState An object which will be the initial state of the store.
17
+ * @returns The newly created store.
18
+ */ export function createGlobalStore(name, initialState) {
19
+ const available = availableStores[name];
20
+ if (available) {
21
+ if (available.active) {
22
+ console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
23
+ } else {
24
+ available.value.setState(initialState, true);
25
+ }
26
+ available.active = true;
27
+ return available.value;
28
+ } else {
29
+ const store = createStore()(()=>initialState);
30
+ availableStores[name] = {
31
+ value: store,
32
+ active: true
33
+ };
34
+ return store;
35
+ }
36
+ }
37
+ /**
38
+ * Registers an existing Zustand store.
39
+ *
40
+ * @param name A name by which the store can be looked up later.
41
+ * Must be unique across the entire application.
42
+ * @param store The Zustand store to use for this.
43
+ * @returns The newly registered store.
44
+ */ export function registerGlobalStore(name, store) {
45
+ const available = availableStores[name];
46
+ if (available) {
47
+ if (available.active) {
48
+ console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
49
+ } else {
50
+ available.value = store;
51
+ }
52
+ available.active = true;
53
+ return available.value;
54
+ } else {
55
+ availableStores[name] = {
56
+ value: store,
57
+ active: true
58
+ };
59
+ return store;
60
+ }
61
+ }
62
+ /**
63
+ * Returns the existing store named `name`,
64
+ * or creates a new store named `name` if none exists.
65
+ *
66
+ * @param name The name of the store to look up.
67
+ * @param fallbackState The initial value of the new store if no store named `name` exists.
68
+ * @returns The found or newly created store.
69
+ */ export function getGlobalStore(name, fallbackState) {
70
+ const available = availableStores[name];
71
+ if (!available) {
72
+ const store = createStore()(()=>fallbackState ?? {});
73
+ availableStores[name] = {
74
+ value: store,
75
+ active: false
76
+ };
77
+ return store;
78
+ }
79
+ return available.value;
80
+ }
81
+ export function subscribeTo(...args) {
82
+ const [store, select, handle] = args;
83
+ const handler = typeof handle === 'undefined' ? select : handle;
84
+ const selector = typeof handle === 'undefined' ? (state)=>state : select;
85
+ handler(selector(store.getState()));
86
+ return store.subscribe((state, previous)=>{
87
+ const current = selector(state);
88
+ if (!shallowEqual(previous, current)) {
89
+ handler(current);
90
+ }
91
+ });
92
+ }
package/mock-jest.ts ADDED
@@ -0,0 +1,68 @@
1
+ import { jest } from '@jest/globals';
2
+ import { createStore, type StoreApi } from 'zustand';
3
+ export { subscribeTo } from './src/index';
4
+
5
+ // Needed for all mocks using stores
6
+ const availableStores: Record<string, StoreEntity> = {};
7
+ const initialStates: Record<string, any> = {};
8
+
9
+ interface StoreEntity {
10
+ value: StoreApi<any>;
11
+ active: boolean;
12
+ }
13
+
14
+ export type MockedStore<T> = StoreApi<T> & {
15
+ resetMock: () => void;
16
+ };
17
+
18
+ export const mockStores = availableStores;
19
+
20
+ export function createGlobalStore<T>(name: string, initialState: T): StoreApi<T> {
21
+ // We ignore whether there's already a store with this name so that tests
22
+ // don't have to worry about clearing old stores before re-creating them.
23
+ const store = createStore<T>()(() => initialState);
24
+ initialStates[name] = initialState;
25
+
26
+ availableStores[name] = {
27
+ value: store,
28
+ active: true,
29
+ };
30
+
31
+ return instrumentedStore(name, store);
32
+ }
33
+
34
+ export function registerGlobalStore<T>(name: string, store: StoreApi<T>): StoreApi<T> {
35
+ availableStores[name] = {
36
+ value: store,
37
+ active: true,
38
+ };
39
+
40
+ return instrumentedStore(name, store);
41
+ }
42
+
43
+ export function getGlobalStore<T>(name: string, fallbackState?: T): StoreApi<T> {
44
+ const available = availableStores[name];
45
+
46
+ if (!available) {
47
+ const store = createStore<T>()(() => fallbackState ?? ({} as unknown as T));
48
+ initialStates[name] = fallbackState;
49
+ availableStores[name] = {
50
+ value: store,
51
+ active: false,
52
+ };
53
+ return instrumentedStore(name, store);
54
+ }
55
+
56
+ return instrumentedStore(name, available.value);
57
+ }
58
+
59
+ function instrumentedStore<T>(name: string, store: StoreApi<T>) {
60
+ return {
61
+ getInitialState: jest.spyOn(store, 'getInitialState'),
62
+ getState: jest.spyOn(store, 'getState'),
63
+ setState: jest.spyOn(store, 'setState'),
64
+ subscribe: jest.spyOn(store, 'subscribe'),
65
+ destroy: jest.spyOn(store, 'destroy'),
66
+ resetMock: () => store.setState(initialStates[name]),
67
+ } as unknown as MockedStore<T>;
68
+ }
package/mock.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { vi } from 'vitest';
1
2
  import { createStore, type StoreApi } from 'zustand';
2
3
  export { subscribeTo } from './src/index';
3
4
 
@@ -57,9 +58,11 @@ export function getGlobalStore<T>(name: string, fallbackState?: T): StoreApi<T>
57
58
 
58
59
  function instrumentedStore<T>(name: string, store: StoreApi<T>) {
59
60
  return {
60
- getState: jest.spyOn(store, 'getState'),
61
- setState: jest.spyOn(store, 'setState'),
62
- subscribe: jest.spyOn(store, 'subscribe'),
61
+ getInitialState: vi.spyOn(store, 'getInitialState'),
62
+ getState: vi.spyOn(store, 'getState'),
63
+ setState: vi.spyOn(store, 'setState'),
64
+ subscribe: vi.spyOn(store, 'subscribe'),
65
+ destroy: vi.spyOn(store, 'destroy'),
63
66
  resetMock: () => store.setState(initialStates[name]),
64
- } as any as MockedStore<T>;
67
+ } as unknown as MockedStore<T>;
65
68
  }
package/package.json CHANGED
@@ -1,18 +1,31 @@
1
1
  {
2
2
  "name": "@openmrs/esm-state",
3
- "version": "6.3.1-pre.2961",
3
+ "version": "6.3.1-pre.2986",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Frontend stores & state management for OpenMRS",
6
- "browser": "dist/openmrs-esm-state.js",
7
- "main": "src/index.ts",
6
+ "type": "module",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.ts",
12
+ "require": "./src/index.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./src/public": {
16
+ "types": "./src/public.ts",
17
+ "default": "./dist/public.js"
18
+ },
19
+ "./mock": {
20
+ "import": "./mock.ts",
21
+ "require": "./mock-jest.ts"
22
+ }
23
+ },
8
24
  "source": true,
9
25
  "scripts": {
10
- "test": "cross-env TZ=UTC jest --config jest.config.js --verbose false --passWithNoTests --color",
11
- "test:watch": "cross-env TZ=UTC jest --watch --config jest.config.js --color",
12
- "build": "webpack --mode=production",
13
- "build:development": "webpack --mode development",
14
- "analyze": "webpack --mode=production --env analyze=true",
15
- "typescript": "tsc",
26
+ "build": "rimraf dist && concurrently \"swc --strip-leading-paths src -d dist\" \"tsc --project tsconfig.build.json\"",
27
+ "build:development": "rimraf dist && concurrently \"swc --strip-leading-paths src -d dist\" \"tsc --project tsconfig.build.json\"",
28
+ "typescript": "tsc --project tsconfig.build.json",
16
29
  "lint": "eslint src --ext ts,tsx"
17
30
  },
18
31
  "keywords": [
@@ -45,8 +58,13 @@
45
58
  "@openmrs/esm-utils": "6.x"
46
59
  },
47
60
  "devDependencies": {
48
- "@openmrs/esm-globals": "6.3.1-pre.2961",
49
- "@openmrs/esm-utils": "6.3.1-pre.2961"
61
+ "@openmrs/esm-globals": "6.3.1-pre.2986",
62
+ "@openmrs/esm-utils": "6.3.1-pre.2986",
63
+ "@swc/cli": "^0.7.7",
64
+ "@swc/core": "^1.11.29",
65
+ "concurrently": "^9.1.2",
66
+ "cross-env": "^7.0.3",
67
+ "rimraf": "^6.0.1"
50
68
  },
51
69
  "stableVersion": "6.3.0"
52
70
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig.json",
3
+ "compilerOptions": {
4
+ "declarationDir": "dist",
5
+ "emitDeclarationOnly": true
6
+ },
7
+ "extends": "./tsconfig.json",
8
+ "exclude": ["**/*.test.*", "**/setup-tests.*"]
9
+ }
package/tsconfig.json CHANGED
@@ -1,25 +1,5 @@
1
1
  {
2
- "compilerOptions": {
3
- "esModuleInterop": true,
4
- "module": "esnext",
5
- "target": "es2015",
6
- "allowSyntheticDefaultImports": true,
7
- "jsx": "react",
8
- "strictNullChecks": true,
9
- "moduleResolution": "node",
10
- "declaration": true,
11
- "declarationDir": "dist",
12
- "emitDeclarationOnly": true,
13
- "lib": [
14
- "dom",
15
- "es5",
16
- "scripthost",
17
- "es2015",
18
- "es2015.promise",
19
- "es2016.array.include",
20
- "es2018",
21
- "esnext"
22
- ]
23
- },
24
- "include": ["src/**/*"]
2
+ "$schema": "https://json.schemastore.org/tsconfig.json",
3
+ "extends": "../tsconfig.json",
4
+ "include": ["src/**/*.ts*"]
25
5
  }
@@ -1,2 +0,0 @@
1
- System.register(["@openmrs/esm-utils"],(function(e,t){var r={};return{setters:[function(e){r.shallowEqual=e.shallowEqual}],execute:function(){e((()=>{"use strict";var e={618:e=>{e.exports=r}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var a=t[r]={exports:{}};return e[r](a,a.exports,n),a.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{n.r(o),n.d(o,{createGlobalStore:()=>i,getGlobalStore:()=>c,registerGlobalStore:()=>l,subscribeTo:()=>s});var e=n(618);const t=e=>{let t;const r=new Set,n=(e,n)=>{const o="function"==typeof e?e(t):e;if(!Object.is(o,t)){const e=t;t=(null!=n?n:"object"!=typeof o||null===o)?o:Object.assign({},t,o),r.forEach((r=>r(t,e)))}},o=()=>t,a={setState:n,getState:o,getInitialState:()=>u,subscribe:e=>(r.add(e),()=>r.delete(e)),destroy:()=>{console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),r.clear()}},u=t=e(n,o,a);return a},r=e=>e?t(e):t;function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var u={};function i(e,t){var n=u[e];if(n)return n.active?console.error("Attempted to override the existing store ".concat(e,". Make sure that stores are only created once.")):n.value.setState(t,!0),n.active=!0,n.value;var o=r()((function(){return t}));return u[e]={value:o,active:!0},o}function l(e,t){var r=u[e];return r?(r.active?console.error("Attempted to override the existing store ".concat(e,". Make sure that stores are only created once.")):r.value=t,r.active=!0,r.value):(u[e]={value:t,active:!0},t)}function c(e,t){var n=u[e];if(!n){var o=r()((function(){return null!=t?t:{}}));return u[e]={value:o,active:!1},o}return n.value}function s(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];var o,u,i=(u=3,function(e){if(Array.isArray(e))return e}(o=r)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,a=[],u=!0,i=!1;try{for(r=r.call(e);!(u=(n=r.next()).done)&&(a.push(n.value),!t||a.length!==t);u=!0);}catch(e){i=!0,o=e}finally{try{u||null==r.return||r.return()}finally{if(i)throw o}}return a}}(o,u)||function(e,t){if(e){if("string"==typeof e)return a(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(e,t):void 0}}(o,u)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),l=i[0],c=i[1],s=i[2],v=void 0===s?c:s,f=void 0===s?function(e){return e}:c;return v(f(l.getState())),l.subscribe((function(t,r){var n=f(t);(0,e.shallowEqual)(r,n)||v(n)}))}setTimeout((function(){"development"===window.spaEnv&&(window.stores=u)}),1e3)})(),o})())}}}));
2
- //# sourceMappingURL=openmrs-esm-state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openmrs-esm-state.js","mappings":"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","sources":["webpack://@openmrs/esm-state/external system \"@openmrs/esm-utils\"","webpack://@openmrs/esm-state/webpack/bootstrap","webpack://@openmrs/esm-state/webpack/runtime/define property getters","webpack://@openmrs/esm-state/webpack/runtime/hasOwnProperty shorthand","webpack://@openmrs/esm-state/webpack/runtime/make namespace object","webpack://@openmrs/esm-state/../../../node_modules/zustand/esm/vanilla.mjs","webpack://@openmrs/esm-state/./src/state.ts"],"sourcesContent":["module.exports = __WEBPACK_EXTERNAL_MODULE__618__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const createStoreImpl = (createState) => {\n let state;\n const listeners = /* @__PURE__ */ new Set();\n const setState = (partial, replace) => {\n const nextState = typeof partial === \"function\" ? partial(state) : partial;\n if (!Object.is(nextState, state)) {\n const previousState = state;\n state = (replace != null ? replace : typeof nextState !== \"object\" || nextState === null) ? nextState : Object.assign({}, state, nextState);\n listeners.forEach((listener) => listener(state, previousState));\n }\n };\n const getState = () => state;\n const getInitialState = () => initialState;\n const subscribe = (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n const destroy = () => {\n if ((import.meta.env ? import.meta.env.MODE : void 0) !== \"production\") {\n console.warn(\n \"[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected.\"\n );\n }\n listeners.clear();\n };\n const api = { setState, getState, getInitialState, subscribe, destroy };\n const initialState = state = createState(setState, getState, api);\n return api;\n};\nconst createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;\nvar vanilla = (createState) => {\n if ((import.meta.env ? import.meta.env.MODE : void 0) !== \"production\") {\n console.warn(\n \"[DEPRECATED] Default export is deprecated. Instead use import { createStore } from 'zustand/vanilla'.\"\n );\n }\n return createStore(createState);\n};\n\nexport { createStore, vanilla as default };\n","/** @module @category Store */\nimport type {} from '@openmrs/esm-globals';\nimport { shallowEqual } from '@openmrs/esm-utils';\nimport type { StoreApi } from 'zustand/vanilla';\nimport { createStore } from 'zustand/vanilla';\n\ninterface StoreEntity {\n value: StoreApi<unknown>;\n active: boolean;\n}\n\nconst availableStores: Record<string, StoreEntity> = {};\n\n// spaEnv isn't available immediately. Wait a bit before making stores available\n// on window in development mode.\nsetTimeout(() => {\n if (window.spaEnv === 'development') {\n window['stores'] = availableStores;\n }\n}, 1000);\n\n/**\n * Creates a Zustand store.\n *\n * @param name A name by which the store can be looked up later.\n * Must be unique across the entire application.\n * @param initialState An object which will be the initial state of the store.\n * @returns The newly created store.\n */\nexport function createGlobalStore<T>(name: string, initialState: T): StoreApi<T> {\n const available = availableStores[name];\n\n if (available) {\n if (available.active) {\n console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);\n } else {\n available.value.setState(initialState, true);\n }\n\n available.active = true;\n return available.value as StoreApi<T>;\n } else {\n const store = createStore<T>()(() => initialState);\n\n availableStores[name] = {\n value: store,\n active: true,\n };\n\n return store;\n }\n}\n\n/**\n * Registers an existing Zustand store.\n *\n * @param name A name by which the store can be looked up later.\n * Must be unique across the entire application.\n * @param store The Zustand store to use for this.\n * @returns The newly registered store.\n */\nexport function registerGlobalStore<T>(name: string, store: StoreApi<T>): StoreApi<T> {\n const available = availableStores[name];\n\n if (available) {\n if (available.active) {\n console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);\n } else {\n available.value = store;\n }\n\n available.active = true;\n return available.value as StoreApi<T>;\n } else {\n availableStores[name] = {\n value: store,\n active: true,\n };\n\n return store;\n }\n}\n\n/**\n * Returns the existing store named `name`,\n * or creates a new store named `name` if none exists.\n *\n * @param name The name of the store to look up.\n * @param fallbackState The initial value of the new store if no store named `name` exists.\n * @returns The found or newly created store.\n */\nexport function getGlobalStore<T>(name: string, fallbackState?: T): StoreApi<T> {\n const available = availableStores[name];\n\n if (!available) {\n const store = createStore<T>()(() => fallbackState ?? ({} as unknown as T));\n availableStores[name] = {\n value: store,\n active: false,\n };\n return store;\n }\n\n return available.value as StoreApi<T>;\n}\n\ntype SubscribeToArgs<T, U> = [StoreApi<T>, (state: T) => void] | [StoreApi<T>, (state: T) => U, (state: U) => void];\n\nexport function subscribeTo<T, U = T>(store: StoreApi<T>, handle: (state: T) => void): () => void;\nexport function subscribeTo<T, U>(\n store: StoreApi<T>,\n select: (state: T) => U,\n handle: (subState: U) => void,\n): () => void;\nexport function subscribeTo<T, U>(...args: SubscribeToArgs<T, U>): () => void {\n const [store, select, handle] = args;\n const handler = typeof handle === 'undefined' ? (select as unknown as (state: U) => void) : handle;\n const selector = typeof handle === 'undefined' ? (state: T) => state as unknown as U : (select as (state: T) => U);\n\n handler(selector(store.getState()));\n return store.subscribe((state, previous) => {\n const current = selector(state);\n\n if (!shallowEqual(previous, current)) {\n handler(current);\n }\n });\n}\n"],"names":["module","exports","__WEBPACK_EXTERNAL_MODULE__618__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","createStoreImpl","createState","state","listeners","Set","setState","partial","replace","nextState","is","previousState","assign","forEach","listener","getState","api","getInitialState","initialState","subscribe","add","delete","destroy","console","warn","clear","createStore","availableStores","createGlobalStore","name","available","active","error","store","registerGlobalStore","getGlobalStore","fallbackState","subscribeTo","args","select","handle","handler","selector","previous","current","shallowEqual","setTimeout","window","spaEnv"],"sourceRoot":""}
package/jest.config.js DELETED
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- clearMocks: true,
3
- transform: {
4
- '^.+\\.tsx?$': ['@swc/jest'],
5
- },
6
- testEnvironment: 'jsdom',
7
- testEnvironmentOptions: {
8
- url: 'http://localhost/',
9
- },
10
- };
package/webpack.config.js DELETED
@@ -1,42 +0,0 @@
1
- const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
2
- const { resolve } = require('path');
3
- const { CleanWebpackPlugin } = require('clean-webpack-plugin');
4
- const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
5
-
6
- const { peerDependencies } = require('./package.json');
7
-
8
- module.exports = (env) => ({
9
- entry: [resolve(__dirname, 'src/index.ts')],
10
- output: {
11
- filename: 'openmrs-esm-state.js',
12
- path: resolve(__dirname, 'dist'),
13
- library: { type: 'system' },
14
- },
15
- devtool: 'source-map',
16
- module: {
17
- rules: [
18
- {
19
- test: /\.m?(js|ts|tsx)$/,
20
- exclude: /node_modules/,
21
- use: 'swc-loader',
22
- },
23
- ],
24
- },
25
- externals: Object.keys(peerDependencies || {}),
26
- resolve: {
27
- extensions: ['.ts', '.js', '.tsx', '.jsx'],
28
- },
29
- plugins: [
30
- new CleanWebpackPlugin(),
31
- new ForkTsCheckerWebpackPlugin(),
32
- new BundleAnalyzerPlugin({
33
- analyzerMode: env && env.analyze ? 'static' : 'disabled',
34
- }),
35
- ],
36
- devServer: {
37
- disableHostCheck: true,
38
- headers: {
39
- 'Access-Control-Allow-Origin': '*',
40
- },
41
- },
42
- });