@openmrs/esm-state 5.8.2-pre.2389 → 5.8.2-pre.2391

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.
@@ -1,5 +1,7 @@
1
- asset openmrs-esm-state.js 1.89 KiB [emitted] [minimized] (name: main) 1 related asset
1
+ asset openmrs-esm-state.js 3.26 KiB [emitted] [minimized] (name: main) 1 related asset
2
2
  runtime modules 670 bytes 3 modules
3
- orphan modules 4.64 KiB [orphan] 2 modules
4
- ./src/index.ts + 2 modules 4.67 KiB [built] [code generated]
5
- webpack 5.88.0 compiled successfully in 9648 ms
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 2791 ms
@@ -1,2 +1,2 @@
1
- System.register([],(function(e,t){return{execute:function(){e((()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{createGlobalStore:()=>a,getGlobalStore:()=>u,registerGlobalStore:()=>i,subscribeTo:()=>c});const r=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:()=>i,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()}},i=t=e(n,o,a);return a},n=e=>e?r(e):r;var o={};function a(e,t){var r=o[e];if(r)return r.active?console.error("Cannot override an existing store. Make sure that stores are only created once."):r.value.setState(t,!0),r.active=!0,r.value;var a=n()((function(){return t}));return o[e]={value:a,active:!0},a}function i(e,t){var r=o[e];return r?(r.active?console.error("Cannot override an existing store. Make sure that stores are only created once."):r.value=t,r.active=!0,r.value):(o[e]={value:t,active:!0},t)}function u(e,t){var r=o[e];if(!r){var a=n()((function(){return null!=t?t:{}}));return o[e]={value:a,active:!1},a}return r.value}function c(e,t,r){var n=t(e.getState());return e.subscribe((function(e){var o=t(e);o!==n&&(n=o,r(o))}))}return setTimeout((function(){"development"===window.spaEnv&&(window.stores=o)}),1e3),t})())}}}));
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
2
  //# sourceMappingURL=openmrs-esm-state.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"openmrs-esm-state.js","mappings":"iFACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,GAAO,G,8GCL9D,MAAMC,EAAmBC,IACvB,IAAIC,EACJ,MAAMC,EAA4B,IAAIC,IAChCC,EAAW,CAACC,EAASC,KACzB,MAAMC,EAA+B,mBAAZF,EAAyBA,EAAQJ,GAASI,EACnE,IAAKlB,OAAOqB,GAAGD,EAAWN,GAAQ,CAChC,MAAMQ,EAAgBR,EACtBA,GAAoB,MAAXK,EAAkBA,EAA+B,iBAAdC,GAAwC,OAAdA,GAAsBA,EAAYpB,OAAOuB,OAAO,CAAC,EAAGT,EAAOM,GACjIL,EAAUS,SAASC,GAAaA,EAASX,EAAOQ,IAClD,GAEII,EAAW,IAAMZ,EAcjBa,EAAM,CAAEV,WAAUS,WAAUE,gBAbV,IAAMC,EAaqBC,UAZhCL,IACjBV,EAAUgB,IAAIN,GACP,IAAMV,EAAUiB,OAAOP,IAU8BQ,QAR9C,KAEZC,QAAQC,KACN,0MAGJpB,EAAUqB,OAAO,GAGbP,EAAef,EAAQD,EAAYI,EAAUS,EAAUC,GAC7D,OAAOA,CAAG,EAENU,EAAexB,GAAgBA,EAAcD,EAAgBC,GAAeD,EAClF,ICpBM0B,EAA+C,CAAC,EAkB/C,SAASC,EAAqBC,EAAcX,GACjD,IAAMY,EAAYH,EAAgBE,GAElC,GAAIC,EAQF,OAPIA,EAAUC,OACZR,QAAQS,MAAM,mFAEdF,EAAU9B,MAAMM,SAASY,GAAc,GAGzCY,EAAUC,QAAS,EACZD,EAAU9B,MAEjB,IAAMiC,EAAQP,KAAiB,W,OAAMR,C,IAOrC,OALAS,EAAgBE,GAAQ,CACtB7B,MAAOiC,EACPF,QAAQ,GAGHE,CAEX,CAUO,SAASC,EAAuBL,EAAcI,GACnD,IAAMH,EAAYH,EAAgBE,GAElC,OAAIC,GACEA,EAAUC,OACZR,QAAQS,MAAM,mFAEdF,EAAU9B,MAAQiC,EAGpBH,EAAUC,QAAS,EACZD,EAAU9B,QAEjB2B,EAAgBE,GAAQ,CACtB7B,MAAOiC,EACPF,QAAQ,GAGHE,EAEX,CAUO,SAASE,EAAkBN,EAAcO,GAC9C,IAAMN,EAAYH,EAAgBE,GAElC,IAAKC,EAAW,CACd,IAAMG,EAAQP,KAAiB,W,OAAMU,QAAAA,EAAkB,CAAC,C,IAKxD,OAJAT,EAAgBE,GAAQ,CACtB7B,MAAOiC,EACPF,QAAQ,GAEHE,CACT,CAEA,OAAOH,EAAU9B,KACnB,CAEO,SAASqC,EAAkBJ,EAAoBK,EAAyBC,GAC7E,IAAIC,EAAWF,EAAOL,EAAMlB,YAE5B,OAAOkB,EAAMd,WAAU,SAAChB,GACtB,IAAMsC,EAAUH,EAAOnC,GAEnBsC,IAAYD,IACdA,EAAWC,EACXF,EAAOE,GAEX,GACF,C,OAtGAC,YAAW,WACa,gBAAlBC,OAAOC,SACTD,OAAO,OAAYhB,EAEvB,GAAG,K","sources":["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":["// The require scope\nvar __webpack_require__ = {};\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 { StoreApi } from 'zustand/vanilla';\nimport { createStore } from 'zustand/vanilla';\nimport type {} from '@openmrs/esm-globals';\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('Cannot override an existing store. 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('Cannot override an existing store. 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\nexport function subscribeTo<T, U>(store: StoreApi<T>, select: (state: T) => U, handle: (subState: U) => void) {\n let previous = select(store.getState());\n\n return store.subscribe((state) => {\n const current = select(state);\n\n if (current !== previous) {\n previous = current;\n handle(current);\n }\n });\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","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","select","handle","previous","current","setTimeout","window","spaEnv"],"sourceRoot":""}
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-state",
3
- "version": "5.8.2-pre.2389",
3
+ "version": "5.8.2-pre.2391",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Frontend stores & state management for OpenMRS",
6
6
  "browser": "dist/openmrs-esm-state.js",
@@ -41,10 +41,12 @@
41
41
  "zustand": "^4.5.5"
42
42
  },
43
43
  "peerDependencies": {
44
- "@openmrs/esm-globals": "5.x"
44
+ "@openmrs/esm-globals": "5.x",
45
+ "@openmrs/esm-utils": "5.x"
45
46
  },
46
47
  "devDependencies": {
47
- "@openmrs/esm-globals": "5.8.2-pre.2389"
48
+ "@openmrs/esm-globals": "5.8.2-pre.2391",
49
+ "@openmrs/esm-utils": "5.8.2-pre.2391"
48
50
  },
49
51
  "stableVersion": "5.8.1"
50
52
  }
package/src/state.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /** @module @category Store */
2
+ import type {} from '@openmrs/esm-globals';
3
+ import { shallowEqual } from '@openmrs/esm-utils';
2
4
  import type { StoreApi } from 'zustand/vanilla';
3
5
  import { createStore } from 'zustand/vanilla';
4
- import type {} from '@openmrs/esm-globals';
5
6
 
6
7
  interface StoreEntity {
7
8
  value: StoreApi<unknown>;
@@ -31,7 +32,7 @@ export function createGlobalStore<T>(name: string, initialState: T): StoreApi<T>
31
32
 
32
33
  if (available) {
33
34
  if (available.active) {
34
- console.error('Cannot override an existing store. Make sure that stores are only created once.');
35
+ console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
35
36
  } else {
36
37
  available.value.setState(initialState, true);
37
38
  }
@@ -63,7 +64,7 @@ export function registerGlobalStore<T>(name: string, store: StoreApi<T>): StoreA
63
64
 
64
65
  if (available) {
65
66
  if (available.active) {
66
- console.error('Cannot override an existing store. Make sure that stores are only created once.');
67
+ console.error(`Attempted to override the existing store ${name}. Make sure that stores are only created once.`);
67
68
  } else {
68
69
  available.value = store;
69
70
  }
@@ -103,15 +104,25 @@ export function getGlobalStore<T>(name: string, fallbackState?: T): StoreApi<T>
103
104
  return available.value as StoreApi<T>;
104
105
  }
105
106
 
106
- export function subscribeTo<T, U>(store: StoreApi<T>, select: (state: T) => U, handle: (subState: U) => void) {
107
- let previous = select(store.getState());
108
-
109
- return store.subscribe((state) => {
110
- const current = select(state);
111
-
112
- if (current !== previous) {
113
- previous = current;
114
- handle(current);
107
+ type SubscribeToArgs<T, U> = [StoreApi<T>, (state: T) => void] | [StoreApi<T>, (state: T) => U, (state: U) => void];
108
+
109
+ export function subscribeTo<T, U = T>(store: StoreApi<T>, handle: (state: T) => void): () => void;
110
+ export function subscribeTo<T, U>(
111
+ store: StoreApi<T>,
112
+ select: (state: T) => U,
113
+ handle: (subState: U) => void,
114
+ ): () => void;
115
+ export function subscribeTo<T, U>(...args: SubscribeToArgs<T, U>): () => void {
116
+ const [store, select, handle] = args;
117
+ const handler = typeof handle === 'undefined' ? (select as unknown as (state: U) => void) : handle;
118
+ const selector = typeof handle === 'undefined' ? (state: T) => state as unknown as U : (select as (state: T) => U);
119
+
120
+ handler(selector(store.getState()));
121
+ return store.subscribe((state, previous) => {
122
+ const current = selector(state);
123
+
124
+ if (!shallowEqual(previous, current)) {
125
+ handler(current);
115
126
  }
116
127
  });
117
128
  }