@openmrs/esm-context 5.7.3-pre.2204 → 5.8.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.
@@ -1,7 +1,7 @@
1
- asset openmrs-esm-context.js 2.32 KiB [emitted] [minimized] (name: main) 1 related asset
1
+ asset openmrs-esm-context.js 2.42 KiB [emitted] [minimized] (name: main) 1 related asset
2
2
  runtime modules 670 bytes 3 modules
3
- orphan modules 4.97 KiB [orphan] 2 modules
4
- built modules 5.04 KiB [built]
5
- ./src/index.ts + 2 modules 4.99 KiB [built] [code generated]
3
+ orphan modules 5.26 KiB [orphan] 2 modules
4
+ built modules 5.33 KiB [built]
5
+ ./src/index.ts + 2 modules 5.28 KiB [built] [code generated]
6
6
  external "@openmrs/esm-state" 42 bytes [built] [code generated]
7
- webpack 5.88.0 compiled successfully in 9418 ms
7
+ webpack 5.88.0 compiled successfully in 9214 ms
@@ -1,2 +1,2 @@
1
- System.register(["@openmrs/esm-state"],(function(e,t){var r={};return{setters:[function(e){r.registerGlobalStore=e.registerGlobalStore}],execute:function(){e((()=>{"use strict";var e={685:e=>{e.exports=r}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.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,{contextStore:()=>s,getContext:()=>u,registerContext:()=>c,subscribeToContext:()=>l,unregisterContext:()=>a,updateContext:()=>b});const e=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)?o:Object.assign({},t,o),r.forEach((r=>r(t,e)))}},o=()=>t,s={setState:n,getState:o,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()}};return t=e(n,o,s),s};var t,r=n(685),s=(t?e(t):e)((function(){return{}}));(0,r.registerGlobalStore)("openmrs-app-context",s);var i=Object();function c(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i;s.setState((function(r){if(e in r)throw new Error("Attempted to re-register namespace ".concat(e," in the app context. Each namespace must be unregistered before the name can be registered again."));return Object.assign({},r,{namespace:t===i?{}:t})}))}function a(e){s.setState((function(t){return e in t&&delete t[e],t}))}function u(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(e){return e},r=s.getState();return e in r?Object.freeze(Object.assign({},t?t(r[e]):r[e])):null}function b(e,t){s.setState((function(r){return e in r||(r[e]={}),r[e]=t(r[e]),Object.assign({},r)}))}function l(e,t){var r=u(e);return t(Object.freeze(Object.assign({},r))),s.subscribe((function(n){var o=e in n?n[e]:null;o!==r&&(r=o,t(Object.freeze(Object.assign({},o))))}))}})(),o})())}}}));
1
+ System.register(["@openmrs/esm-state"],(function(e,t){var r={};return{setters:[function(e){r.registerGlobalStore=e.registerGlobalStore}],execute:function(){e((()=>{"use strict";var e={685:e=>{e.exports=r}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.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,{contextStore:()=>i,getContext:()=>u,registerContext:()=>a,subscribeToContext:()=>l,unregisterContext:()=>c,updateContext:()=>b});const e=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)?o:Object.assign({},t,o),r.forEach((r=>r(t,e)))}},o=()=>t,i={setState:n,getState:o,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()}};return t=e(n,o,i),i};var t,r=n(685),i=(t?e(t):e)((function(){return{}}));(0,r.registerGlobalStore)("openmrs-app-context",i);var s=Object();function a(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;i.setState((function(r){if(e in r)throw new Error("Attempted to re-register namespace ".concat(e," in the app context. Each namespace must be unregistered before the name can be registered again."));return Object.assign({},r,(i=t===s?{}:t,(o=e)in(n={})?Object.defineProperty(n,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[o]=i,n));var n,o,i}))}function c(e){i.setState((function(t){return e in t&&delete t[e],t}))}function u(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(e){return e},r=i.getState();return e in r?Object.freeze(Object.assign({},t?t(r[e]):r[e])):null}function b(e,t){i.setState((function(r){return e in r||(r[e]={}),r[e]=t(r[e]),Object.assign({},r)}))}function l(e,t){var r=u(e);return t(Object.freeze(Object.assign({},r))),i.subscribe((function(n){var o=e in n?n[e]:null;o!==r&&(r=o,t(Object.freeze(Object.assign({},o))))}))}})(),o})())}}}));
2
2
  //# sourceMappingURL=openmrs-esm-context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"openmrs-esm-context.js","mappings":"gMAAAA,EAAOC,QAAUC,C,GCCbC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,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,KAE7C,GACF,C","sources":["webpack://@openmrs/esm-context/external system \"@openmrs/esm-state\"","webpack://@openmrs/esm-context/webpack/bootstrap","webpack://@openmrs/esm-context/webpack/runtime/define property getters","webpack://@openmrs/esm-context/webpack/runtime/hasOwnProperty shorthand","webpack://@openmrs/esm-context/webpack/runtime/make namespace object","webpack://@openmrs/esm-context/../../../node_modules/zustand/esm/vanilla.mjs","webpack://@openmrs/esm-context/./src/context.ts"],"sourcesContent":["module.exports = __WEBPACK_EXTERNAL_MODULE__685__;","// 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 : Object.assign({}, state, nextState);\n listeners.forEach((listener) => listener(state, previousState));\n }\n };\n const getState = () => state;\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) !== \"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, subscribe, destroy };\n 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) !== \"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 Context */\n'use strict';\n\nimport { createStore } from 'zustand/vanilla';\nimport { registerGlobalStore } from '@openmrs/esm-state';\n\ninterface OpenmrsAppContext {\n [namespace: string]: unknown;\n}\n\n/**\n * @internal\n *\n * The application context store, using immer to potentially simplify updates\n */\nexport const contextStore = createStore<OpenmrsAppContext>()(() => ({}));\n\nregisterGlobalStore<OpenmrsAppContext>('openmrs-app-context', contextStore);\n\nconst nothing = Object();\n\n/**\n * Used by callers to register a new namespace in the application context. Attempting to register\n * an already-registered namespace will display a warning and make no modifications to the state.\n *\n * @param namespace the namespace to register\n * @param initialValue the initial value of the namespace\n */\nexport function registerContext<T extends {} = {}>(namespace: string, initialValue: T = nothing) {\n contextStore.setState((state) => {\n if (namespace in state) {\n throw new Error(\n `Attempted to re-register namespace ${namespace} in the app context. Each namespace must be unregistered before the name can be registered again.`,\n );\n }\n\n return Object.assign({}, state, { namespace: initialValue === nothing ? {} : initialValue });\n });\n}\n\n/**\n * Used by caller to unregister a namespace in the application context. Unregistering a namespace\n * will remove the namespace and all associated data.\n */\nexport function unregisterContext(namespace: string) {\n contextStore.setState((state) => {\n if (namespace in state) {\n delete state[namespace];\n }\n return state;\n });\n}\n\nexport function getContext<T extends {} = {}>(namespace: string): Readonly<T> | null;\n/**\n * Returns an _immutable_ version of the state of the namespace as it is currently\n *\n * @typeParam T The type of the value stored in the namespace\n * @typeParam U The return type of this hook which is mostly relevant when using a selector\n * @param namespace The namespace to load properties from\n * @param selector An optional function which extracts the relevant part of the state\n */\nexport function getContext<T extends {} = {}, U extends {} = T>(\n namespace: string,\n selector: (state: Readonly<T>) => U = (state) => state as unknown as U,\n): Readonly<U> | null {\n const state = contextStore.getState();\n if (namespace in state) {\n return Object.freeze(Object.assign({}, (selector ? selector(state[namespace] as T) : state[namespace]) as U));\n }\n\n return null;\n}\n\n/**\n * Updates a namespace in the global context. If the namespace does not exist, it is registered.\n */\nexport function updateContext<T extends {} = {}>(namespace: string, update: (state: T) => T) {\n contextStore.setState((state) => {\n if (!(namespace in state)) {\n state[namespace] = {};\n }\n\n state[namespace] = update(state[namespace] as T);\n return Object.assign({}, state);\n });\n}\n\nexport type ContextCallback<T extends {} = {}> = (state: Readonly<T> | null | undefined) => void;\n\n/**\n * Subscribes to updates of a given namespace. Note that the returned object is immutable.\n *\n * @param namespace the namespace to subscribe to\n * @param callback a function invoked with the current context whenever\n * @returns A function to unsubscribe from the context\n */\nexport function subscribeToContext<T extends {} = {}>(namespace: string, callback: ContextCallback<T>) {\n let previous = getContext<T>(namespace);\n\n // set initial value\n callback(Object.freeze(Object.assign({}, previous)));\n\n return contextStore.subscribe((state) => {\n let current: Readonly<T> | null | undefined = namespace in state ? (state[namespace] as T) : null;\n\n if (current !== previous) {\n previous = current;\n callback(Object.freeze(Object.assign({}, current)));\n }\n });\n}\n"],"names":["module","exports","__WEBPACK_EXTERNAL_MODULE__685__","__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","subscribe","add","delete","destroy","console","warn","clear","contextStore","registerGlobalStore","nothing","registerContext","namespace","initialValue","Error","unregisterContext","getContext","selector","freeze","updateContext","update","subscribeToContext","callback","previous","current"],"sourceRoot":""}
1
+ {"version":3,"file":"openmrs-esm-context.js","mappings":"gMAAAA,EAAOC,QAAUC,C,GCCbC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaL,QAGrB,IAAID,EAASG,EAAyBE,GAAY,CAGjDJ,QAAS,CAAC,GAOX,OAHAO,EAAoBH,GAAUL,EAAQA,EAAOC,QAASG,GAG/CJ,EAAOC,OACf,CCrBAG,EAAoBK,EAAI,CAACR,EAASS,KACjC,IAAI,IAAIC,KAAOD,EACXN,EAAoBQ,EAAEF,EAAYC,KAASP,EAAoBQ,EAAEX,EAASU,IAC5EE,OAAOC,eAAeb,EAASU,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDP,EAAoBQ,EAAI,CAACK,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFd,EAAoBkB,EAAKrB,IACH,oBAAXsB,QAA0BA,OAAOC,aAC1CX,OAAOC,eAAeb,EAASsB,OAAOC,YAAa,CAAEC,MAAO,WAE7DZ,OAAOC,eAAeb,EAAS,aAAc,CAAEwB,OAAO,GAAO,E,oKCL9D,MAAMC,EAAmBC,IACvB,IAAIC,EACJ,MAAMC,EAA4B,IAAIC,IAChCC,EAAW,CAACC,EAASC,KACzB,MAAMC,EAA+B,mBAAZF,EAAyBA,EAAQJ,GAASI,EACnE,IAAKnB,OAAOsB,GAAGD,EAAWN,GAAQ,CAChC,MAAMQ,EAAgBR,EACtBA,GAAoB,MAAXK,EAAkBA,EAA+B,iBAAdC,GAA0BA,EAAYrB,OAAOwB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GtBzB,EAAMyB,GAAaQ,EAAOjC,EAAMyB,IACzBxC,OAAOwB,OAAO,CAAC,EAAGT,EAC3B,GACF,CAWO,SAASkC,EAAsCT,EAAmBU,GACvE,IAAIC,EAAWP,EAAcJ,GAK7B,OAFAU,EAASlD,OAAO8C,OAAO9C,OAAOwB,OAAO,CAAC,EAAG2B,KAElCf,EAAaP,WAAU,SAACd,GAC7B,IAAIqC,EAA0CZ,KAAazB,EAASA,EAAMyB,GAAmB,KAEzFY,IAAYD,IACdA,EAAWC,EACXF,EAASlD,OAAO8C,OAAO9C,OAAOwB,OAAO,CAAC,EAAG4B,KAE7C,GACF,C","sources":["webpack://@openmrs/esm-context/external system \"@openmrs/esm-state\"","webpack://@openmrs/esm-context/webpack/bootstrap","webpack://@openmrs/esm-context/webpack/runtime/define property getters","webpack://@openmrs/esm-context/webpack/runtime/hasOwnProperty shorthand","webpack://@openmrs/esm-context/webpack/runtime/make namespace object","webpack://@openmrs/esm-context/../../../node_modules/zustand/esm/vanilla.mjs","webpack://@openmrs/esm-context/./src/context.ts"],"sourcesContent":["module.exports = __WEBPACK_EXTERNAL_MODULE__685__;","// 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 : Object.assign({}, state, nextState);\n listeners.forEach((listener) => listener(state, previousState));\n }\n };\n const getState = () => state;\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) !== \"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, subscribe, destroy };\n 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) !== \"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 Context */\n'use strict';\n\nimport { createStore } from 'zustand/vanilla';\nimport { registerGlobalStore } from '@openmrs/esm-state';\n\ninterface OpenmrsAppContext {\n [namespace: string]: unknown;\n}\n\n/**\n * @internal\n *\n * The application context store, using immer to potentially simplify updates\n */\nexport const contextStore = createStore<OpenmrsAppContext>()(() => ({}));\n\nregisterGlobalStore<OpenmrsAppContext>('openmrs-app-context', contextStore);\n\nconst nothing = Object();\n\n/**\n * Used by callers to register a new namespace in the application context. Attempting to register\n * an already-registered namespace will display a warning and make no modifications to the state.\n *\n * @param namespace the namespace to register\n * @param initialValue the initial value of the namespace\n */\nexport function registerContext<T extends {} = {}>(namespace: string, initialValue: T = nothing) {\n contextStore.setState((state) => {\n if (namespace in state) {\n throw new Error(\n `Attempted to re-register namespace ${namespace} in the app context. Each namespace must be unregistered before the name can be registered again.`,\n );\n }\n\n return Object.assign({}, state, { [namespace]: initialValue === nothing ? {} : initialValue });\n });\n}\n\n/**\n * Used by caller to unregister a namespace in the application context. Unregistering a namespace\n * will remove the namespace and all associated data.\n */\nexport function unregisterContext(namespace: string) {\n contextStore.setState((state) => {\n if (namespace in state) {\n delete state[namespace];\n }\n return state;\n });\n}\n\nexport function getContext<T extends {} = {}>(namespace: string): Readonly<T> | null;\n/**\n * Returns an _immutable_ version of the state of the namespace as it is currently\n *\n * @typeParam T The type of the value stored in the namespace\n * @typeParam U The return type of this hook which is mostly relevant when using a selector\n * @param namespace The namespace to load properties from\n * @param selector An optional function which extracts the relevant part of the state\n */\nexport function getContext<T extends {} = {}, U extends {} = T>(\n namespace: string,\n selector: (state: Readonly<T>) => U = (state) => state as unknown as U,\n): Readonly<U> | null {\n const state = contextStore.getState();\n if (namespace in state) {\n return Object.freeze(Object.assign({}, (selector ? selector(state[namespace] as T) : state[namespace]) as U));\n }\n\n return null;\n}\n\n/**\n * Updates a namespace in the global context. If the namespace does not exist, it is registered.\n */\nexport function updateContext<T extends {} = {}>(namespace: string, update: (state: T) => T) {\n contextStore.setState((state) => {\n if (!(namespace in state)) {\n state[namespace] = {};\n }\n\n state[namespace] = update(state[namespace] as T);\n return Object.assign({}, state);\n });\n}\n\nexport type ContextCallback<T extends {} = {}> = (state: Readonly<T> | null | undefined) => void;\n\n/**\n * Subscribes to updates of a given namespace. Note that the returned object is immutable.\n *\n * @param namespace the namespace to subscribe to\n * @param callback a function invoked with the current context whenever\n * @returns A function to unsubscribe from the context\n */\nexport function subscribeToContext<T extends {} = {}>(namespace: string, callback: ContextCallback<T>) {\n let previous = getContext<T>(namespace);\n\n // set initial value\n callback(Object.freeze(Object.assign({}, previous)));\n\n return contextStore.subscribe((state) => {\n let current: Readonly<T> | null | undefined = namespace in state ? (state[namespace] as T) : null;\n\n if (current !== previous) {\n previous = current;\n callback(Object.freeze(Object.assign({}, current)));\n }\n });\n}\n"],"names":["module","exports","__WEBPACK_EXTERNAL_MODULE__685__","__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","subscribe","add","delete","destroy","console","warn","clear","contextStore","registerGlobalStore","nothing","registerContext","namespace","initialValue","Error","unregisterContext","getContext","selector","freeze","updateContext","update","subscribeToContext","callback","previous","current"],"sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-context",
3
- "version": "5.7.3-pre.2204",
3
+ "version": "5.8.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Utilities for managing the current execution context",
6
6
  "browser": "dist/openmrs-esm-context.js",
@@ -43,11 +43,10 @@
43
43
  "@openmrs/esm-state": "5.x"
44
44
  },
45
45
  "devDependencies": {
46
- "@openmrs/esm-globals": "5.7.3-pre.2204",
47
- "@openmrs/esm-state": "5.7.3-pre.2204"
46
+ "@openmrs/esm-globals": "5.8.0",
47
+ "@openmrs/esm-state": "5.8.0"
48
48
  },
49
49
  "dependencies": {
50
50
  "immer": "^10.0.4"
51
- },
52
- "stableVersion": "5.7.2"
51
+ }
53
52
  }
package/src/context.ts CHANGED
@@ -34,7 +34,7 @@ export function registerContext<T extends {} = {}>(namespace: string, initialVal
34
34
  );
35
35
  }
36
36
 
37
- return Object.assign({}, state, { namespace: initialValue === nothing ? {} : initialValue });
37
+ return Object.assign({}, state, { [namespace]: initialValue === nothing ? {} : initialValue });
38
38
  });
39
39
  }
40
40