@openmrs/esm-context 3.1.3 → 5.5.1-pre.1752
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 +8 -0
- package/README.md +1 -40
- package/dist/openmrs-esm-context.js +1 -1
- package/dist/openmrs-esm-context.js.map +1 -1
- package/jest.config.js +9 -0
- package/mock.ts +24 -0
- package/package.json +17 -17
- package/src/context.ts +106 -13
- package/src/index.ts +1 -2
- package/src/public.ts +1 -0
- package/tsconfig.json +3 -1
- package/webpack.config.js +23 -22
- package/.babelrc +0 -8
- package/LICENSE +0 -401
- package/src/react-root-decorator.test.tsx +0 -44
- package/src/react-root-decorator.tsx +0 -120
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
[36m@openmrs/esm-context:build[0m: cache hit, replaying output [2mca9a34bb0e2a39dc[0m
|
|
2
|
+
[36m@openmrs/esm-context:build: [0masset [1m[32mopenmrs-esm-context.js[39m[22m 2.24 KiB [1m[32m[emitted][39m[22m [1m[32m[minimized][39m[22m (name: main) 1 related asset
|
|
3
|
+
[36m@openmrs/esm-context:build: [0mruntime modules 670 bytes 3 modules
|
|
4
|
+
[36m@openmrs/esm-context:build: [0morphan modules 4.84 KiB [1m[33m[orphan][39m[22m 2 modules
|
|
5
|
+
[36m@openmrs/esm-context:build: [0mbuilt modules 4.91 KiB [1m[33m[built][39m[22m
|
|
6
|
+
[36m@openmrs/esm-context:build: [0m [1m./src/index.ts + 2 modules[39m[22m 4.87 KiB [1m[33m[built][39m[22m [1m[33m[code generated][39m[22m
|
|
7
|
+
[36m@openmrs/esm-context:build: [0m [1mexternal "@openmrs/esm-state"[39m[22m 42 bytes [1m[33m[built][39m[22m [1m[33m[code generated][39m[22m
|
|
8
|
+
[36m@openmrs/esm-context:build: [0mwebpack 5.88.0 compiled [1m[32msuccessfully[39m[22m in 8633 ms
|
package/README.md
CHANGED
|
@@ -1,42 +1,3 @@
|
|
|
1
1
|
# openmrs-esm-context
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
openmrs-esm-context is an
|
|
6
|
-
[in-browser javascript module](https://github.com/openmrs/openmrs-rfc-frontend/blob/master/text/0002-modules.md)
|
|
7
|
-
that provides React [Context](https://reactjs.org/docs/context.html)
|
|
8
|
-
that can be shared between modules, as well as the OpenMRS React Root Decorator.
|
|
9
|
-
|
|
10
|
-
## Usage
|
|
11
|
-
|
|
12
|
-
```js
|
|
13
|
-
import openmrsRootDecorator from "@openmrs/esm-context";
|
|
14
|
-
|
|
15
|
-
// Exported only for testing the component without the decorator being there.
|
|
16
|
-
// You should use the default export for everything but tests.
|
|
17
|
-
export function MyRoot(props) {
|
|
18
|
-
return <div>My component</div>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default openmrsRootDecorator({
|
|
22
|
-
// The featureName is shown to users! Make it human-friendly.
|
|
23
|
-
featureName: "A user-facing thing",
|
|
24
|
-
// moduleName is the name of your in-browser module, as it appears in the import map
|
|
25
|
-
moduleName: "@openmrs/esm-login-app",
|
|
26
|
-
})(MyRoot);
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## API
|
|
30
|
-
|
|
31
|
-
`@openmrs/react-root-decorator` exports a function as the default export. That function must
|
|
32
|
-
be called with an `opts` object with the following properties:
|
|
33
|
-
|
|
34
|
-
- `featureName` (required): A string describing the feature. Example is `patient search`. This string is shown to users.
|
|
35
|
-
- `moduleName` (required): The string name of your in-browser module, as it appears in the import map. Example: `"@openmrs/esm-login-app"`
|
|
36
|
-
- `strictMode` (optional): A boolean that turns on [React strict mode](https://reactjs.org/docs/strict-mode.html).
|
|
37
|
-
Defaults to `true`.
|
|
38
|
-
- `throwErrorsToConsole` (optional): A boolean that indicates whether React errors should be thrown to the window via
|
|
39
|
-
`setTimeout(() => {throw err})`. This is so that an automatic error logging library will be able to pick up the errors.
|
|
40
|
-
Defaults to `true`.
|
|
41
|
-
|
|
42
|
-
The decorator returns a function that should then be called with your root react component.
|
|
3
|
+
openmrs-esm-context provides the AppContext that is useful for sharing contextual state across the application.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
System.register(["
|
|
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:()=>a,registerContext:()=>c,subscribeToContext:()=>l,unregisterContext:()=>u,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 c(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 r[e]=t===s?{}:t,r}))}function u(e){i.setState((function(t){return e in t&&delete t[e],t}))}function a(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]),r}))}function l(e,t){var r=a(e);return 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,"sources":["webpack:///webpack/bootstrap","webpack:///external \"react\"","webpack:///external \"i18next\"","webpack:///external \"react-i18next\"","webpack:///./src/context.ts","webpack:///./src/react-root-decorator.tsx"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","__WEBPACK_EXTERNAL_MODULE__0__","__WEBPACK_EXTERNAL_MODULE__1__","__WEBPACK_EXTERNAL_MODULE__2__","ExtensionContext","React","createContext","actualExtensionSlotName","attachedExtensionSlotName","extensionId","extensionModuleName","ModuleNameContext","i18n","_i18n","default","defaultOpts","strictMode","throwErrorsToConsole","disableTranslations","openmrsRootDecorator","userOpts","featureName","moduleName","Error","opts","assign","Comp","Component","caughtError","caughtErrorInfo","render","this","state","rootComponent","Provider","Suspense","fallback","props","I18nextLoadNamespace","forceUpdate","defaultNS","StrictMode","componentDidCatch","err","info","componentStack","extra","setTimeout","setState","useEffect","on","off","loadNamespaceErrRef","useRef","current","hasLoadedNamespace","timeoutId","console","warn","loadNamespaces","then","clearTimeout","catch","children"],"mappings":"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","file":"openmrs-esm-context.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 3);\n","module.exports = __WEBPACK_EXTERNAL_MODULE__0__;","module.exports = __WEBPACK_EXTERNAL_MODULE__1__;","module.exports = __WEBPACK_EXTERNAL_MODULE__2__;","import React from \"react\";\n\nexport interface ExtensionContextData {\n actualExtensionSlotName: string;\n attachedExtensionSlotName: string;\n extensionId: string;\n extensionModuleName: string;\n}\n\nexport const ExtensionContext = React.createContext<ExtensionContextData>({\n actualExtensionSlotName: \"\",\n attachedExtensionSlotName: \"\",\n extensionId: \"\",\n extensionModuleName: \"\",\n});\n\nexport const ModuleNameContext = React.createContext<string | null>(null);\n","import React from \"react\";\nimport { I18nextProvider } from \"react-i18next\";\nimport _i18n from \"i18next\";\nimport { ModuleNameContext } from \"./context\";\n\nconst i18n = (_i18n as any).default || _i18n;\n\nconst defaultOpts = {\n strictMode: true,\n throwErrorsToConsole: true,\n disableTranslations: false,\n};\n\nexport function openmrsRootDecorator(userOpts) {\n if (\n typeof userOpts !== \"object\" ||\n typeof userOpts.featureName !== \"string\" ||\n typeof userOpts.moduleName !== \"string\"\n ) {\n throw new Error(\n \"openmrs-react-root-decorator should be called with an opts object that has \" +\n \"1. a featureName string that will be displayed to users, and 2. a moduleName string. \" +\n \"The moduleName string will be used to look up configuration. \" +\n \"e.g. openmrsRootDecorator({featureName: 'nice feature', moduleName: '@openmrs/esm-nice-feature' })\"\n );\n }\n\n const opts = Object.assign({}, defaultOpts, userOpts);\n\n return function decorateComponent(Comp) {\n return class OpenmrsReactRoot extends React.Component {\n static displayName = `OpenmrsReactRoot(${opts.featureName})`;\n state = {\n caughtError: null,\n caughtErrorInfo: null,\n };\n render() {\n if (this.state.caughtError) {\n // TO-DO have a UX designed for when a catastrophic error occurs\n return null;\n } else {\n const rootComponent = (\n <ModuleNameContext.Provider value={opts.moduleName}>\n <React.Suspense fallback={null}>\n {opts.disableTranslations ? (\n <Comp {...this.props} />\n ) : (\n <I18nextLoadNamespace\n ns={opts.moduleName}\n forceUpdate={() => this.forceUpdate()}\n >\n <I18nextProvider i18n={i18n} defaultNS={opts.moduleName}>\n <Comp {...this.props} />\n </I18nextProvider>\n </I18nextLoadNamespace>\n )}\n </React.Suspense>\n </ModuleNameContext.Provider>\n );\n if (opts.strictMode || !React.StrictMode) {\n return rootComponent;\n } else {\n return <React.StrictMode>{rootComponent}</React.StrictMode>;\n }\n }\n }\n componentDidCatch(err, info) {\n if (info && info.componentStack) {\n err.extra = Object.assign(err.extra || {}, {\n componentStack: info.componentStack,\n });\n }\n\n if (opts.throwErrorsToConsole) {\n setTimeout(() => {\n throw err;\n });\n }\n\n this.setState({\n caughtError: err,\n caughtErrorInfo: info,\n });\n }\n };\n };\n}\n\nfunction I18nextLoadNamespace(props) {\n React.useEffect(() => {\n i18n.on(\"languageChanged\", props.forceUpdate);\n return () => i18n.off(\"languageChanged\", props.forceUpdate);\n }, [props.forceUpdate]);\n\n const loadNamespaceErrRef = React.useRef(null);\n\n if (loadNamespaceErrRef.current) {\n throw loadNamespaceErrRef.current;\n }\n\n if (!i18n.hasLoadedNamespace(props.ns)) {\n const timeoutId = setTimeout(() => {\n console.warn(\n `openmrs-react-root-decorator: the React suspense promise for i18next.loadNamespaces(['${props.ns}']) did not resolve nor reject after three seconds. This could mean you have multiple versions of i18next and haven't made i18next a webpack external in all projects.`\n );\n }, 3000);\n\n throw i18n\n .loadNamespaces([props.ns])\n .then(() => {\n clearTimeout(timeoutId);\n })\n .catch((err) => {\n clearTimeout(timeoutId);\n loadNamespaceErrRef.current = err;\n });\n }\n\n return props.children;\n}\n"],"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,OAAO,CAAC,EAAGT,EAAOM,GAC3GL,EAAUS,SAASC,GAAaA,EAASX,EAAOQ,IAClD,GAEII,EAAW,IAAMZ,EAajBa,EAAM,CAAEV,WAAUS,WAAUE,UAZfH,IACjBV,EAAUc,IAAIJ,GACP,IAAMV,EAAUe,OAAOL,IAUaM,QAR7B,KAEZC,QAAQC,KACN,0MAGJlB,EAAUmB,OAAO,GAInB,OADApB,EAAQD,EAAYI,EAAUS,EAAUC,GACjCA,CAAG,EAGZ,IADqBd,E,SCbRsB,GDawBtB,EAAcD,EAAgBC,GAAeD,ICbrB,W,MAAO,CAAC,C,KAErEwB,EAAAA,EAAAA,qBAAuC,sBAAuBD,GAE9D,IAAME,EAAUtC,SAST,SAASuC,EAAmCC,G,IAAmBC,EAAAA,UAAAA,OAAAA,QAAAA,IAAAA,UAAAA,GAAAA,UAAAA,GAAkBH,EACtFF,EAAalB,UAAS,SAACH,GACrB,GAAIyB,KAAazB,EACf,MAAM,IAAI2B,MACR,sCAAgD,OAAVF,EAAU,sGAKpD,OADAzB,EAAMyB,GAAaC,IAAiBH,EAAU,CAAC,EAAIG,EAC5C1B,CACT,GACF,CAMO,SAAS4B,EAAkBH,GAChCJ,EAAalB,UAAS,SAACH,GAIrB,OAHIyB,KAAazB,UACRA,EAAMyB,GAERzB,CACT,GACF,CAWO,SAAS6B,EACdJ,G,IACAK,EAAAA,UAAAA,OAAAA,QAAAA,IAAAA,UAAAA,GAAAA,UAAAA,GAAsC,SAAC9B,G,OAAUA,C,EAE3CA,EAAQqB,EAAaT,WAC3B,OAAIa,KAAazB,EACRf,OAAO8C,OAAO9C,OAAOwB,OAAO,CAAC,EAAIqB,EAAWA,EAAS9B,EAAMyB,IAAmBzB,EAAMyB,KAGtF,IACT,CAKO,SAASO,EAAiCP,EAAmBQ,GAClEZ,EAAalB,UAAS,SAACH,GAMrB,OALMyB,KAAazB,IACjBA,EAAMyB,GAAa,CAAC,GAGtBzB,EAAMyB,GAAaQ,EAAOjC,EAAMyB,IACzBzB,CACT,GACF,CAWO,SAASkC,EAAsCT,EAAmBU,GACvE,IAAIC,EAAWP,EAAcJ,GAE7B,OAAOJ,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 state[namespace] = initialValue === nothing ? {} : initialValue;\n return state;\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 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 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/jest.config.js
ADDED
package/mock.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const appContext = {};
|
|
2
|
+
|
|
3
|
+
const nothing = Object();
|
|
4
|
+
|
|
5
|
+
export function registerContext<T extends {} = {}>(namespace: string, initialValue: T = nothing) {
|
|
6
|
+
appContext[namespace] = initialValue ?? {};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getContext<T extends {} = {}, U extends {} = T>(
|
|
10
|
+
namespace: string,
|
|
11
|
+
selector: (state: Readonly<T>) => U = (state) => state as unknown as U,
|
|
12
|
+
): Readonly<U> | null {
|
|
13
|
+
const value = appContext[namespace];
|
|
14
|
+
|
|
15
|
+
if (!value) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return Object.freeze(Object.assign({}, selector ? selector(value) : value));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function updateContext<T extends {} = {}>(namespace: string, update: (state: T) => T) {
|
|
23
|
+
appContext[namespace] = update(appContext[namespace] ?? {});
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-context",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.5.1-pre.1752",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Utilities for managing the current execution context",
|
|
6
6
|
"browser": "dist/openmrs-esm-context.js",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
8
|
"source": true,
|
|
9
|
+
"sideEffects": false,
|
|
9
10
|
"scripts": {
|
|
10
|
-
"test": "jest --passWithNoTests",
|
|
11
|
+
"test": "cross-env TZ=UTC jest --config jest.config.js --verbose false --passWithNoTests --color",
|
|
12
|
+
"test:watch": "cross-env TZ=UTC jest --watch --config jest.config.js --color",
|
|
11
13
|
"build": "webpack --mode=production",
|
|
14
|
+
"build:development": "webpack --mode development",
|
|
15
|
+
"analyze": "webpack --mode=production --env analyze=true",
|
|
12
16
|
"typescript": "tsc",
|
|
13
17
|
"lint": "eslint src --ext ts,tsx"
|
|
14
18
|
},
|
|
@@ -31,23 +35,19 @@
|
|
|
31
35
|
"url": "https://github.com/openmrs/openmrs-esm-core/issues"
|
|
32
36
|
},
|
|
33
37
|
"homepage": "https://github.com/openmrs/openmrs-esm-core#readme",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
36
40
|
},
|
|
37
41
|
"peerDependencies": {
|
|
38
|
-
"@openmrs/esm-
|
|
39
|
-
"
|
|
40
|
-
"react": "16.x",
|
|
41
|
-
"react-i18next": "11.x"
|
|
42
|
+
"@openmrs/esm-globals": "5.x",
|
|
43
|
+
"@openmrs/esm-state": "5.x"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
|
-
"@openmrs/esm-
|
|
45
|
-
"
|
|
46
|
-
"react": "^16.13.1",
|
|
47
|
-
"react-i18next": "^11.7.0"
|
|
46
|
+
"@openmrs/esm-globals": "5.5.1-pre.1752",
|
|
47
|
+
"@openmrs/esm-state": "5.5.1-pre.1752"
|
|
48
48
|
},
|
|
49
|
-
"
|
|
50
|
-
"
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"immer": "^10.0.4"
|
|
51
51
|
},
|
|
52
|
-
"
|
|
53
|
-
}
|
|
52
|
+
"stableVersion": "5.5.0"
|
|
53
|
+
}
|
package/src/context.ts
CHANGED
|
@@ -1,17 +1,110 @@
|
|
|
1
|
-
|
|
1
|
+
/** @module @category Context */
|
|
2
|
+
'use strict';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { createStore } from 'zustand/vanilla';
|
|
5
|
+
import { registerGlobalStore } from '@openmrs/esm-state';
|
|
6
|
+
|
|
7
|
+
interface OpenmrsAppContext {
|
|
8
|
+
[namespace: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*
|
|
14
|
+
* The application context store, using immer to potentially simplify updates
|
|
15
|
+
*/
|
|
16
|
+
export const contextStore = createStore<OpenmrsAppContext>()(() => ({}));
|
|
17
|
+
|
|
18
|
+
registerGlobalStore<OpenmrsAppContext>('openmrs-app-context', contextStore);
|
|
19
|
+
|
|
20
|
+
const nothing = Object();
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Used by callers to register a new namespace in the application context. Attempting to register
|
|
24
|
+
* an already-registered namespace will display a warning and make no modifications to the state.
|
|
25
|
+
*
|
|
26
|
+
* @param namespace the namespace to register
|
|
27
|
+
* @param initialValue the initial value of the namespace
|
|
28
|
+
*/
|
|
29
|
+
export function registerContext<T extends {} = {}>(namespace: string, initialValue: T = nothing) {
|
|
30
|
+
contextStore.setState((state) => {
|
|
31
|
+
if (namespace in state) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Attempted to re-register namespace ${namespace} in the app context. Each namespace must be unregistered before the name can be registered again.`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
state[namespace] = initialValue === nothing ? {} : initialValue;
|
|
38
|
+
return state;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Used by caller to unregister a namespace in the application context. Unregistering a namespace
|
|
44
|
+
* will remove the namespace and all associated data.
|
|
45
|
+
*/
|
|
46
|
+
export function unregisterContext(namespace: string) {
|
|
47
|
+
contextStore.setState((state) => {
|
|
48
|
+
if (namespace in state) {
|
|
49
|
+
delete state[namespace];
|
|
50
|
+
}
|
|
51
|
+
return state;
|
|
52
|
+
});
|
|
8
53
|
}
|
|
9
54
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
55
|
+
export function getContext<T extends {} = {}>(namespace: string): Readonly<T> | null;
|
|
56
|
+
/**
|
|
57
|
+
* Returns an _immutable_ version of the state of the namespace as it is currently
|
|
58
|
+
*
|
|
59
|
+
* @typeParam T The type of the value stored in the namespace
|
|
60
|
+
* @typeParam U The return type of this hook which is mostly relevant when using a selector
|
|
61
|
+
* @param namespace The namespace to load properties from
|
|
62
|
+
* @param selector An optional function which extracts the relevant part of the state
|
|
63
|
+
*/
|
|
64
|
+
export function getContext<T extends {} = {}, U extends {} = T>(
|
|
65
|
+
namespace: string,
|
|
66
|
+
selector: (state: Readonly<T>) => U = (state) => state as unknown as U,
|
|
67
|
+
): Readonly<U> | null {
|
|
68
|
+
const state = contextStore.getState();
|
|
69
|
+
if (namespace in state) {
|
|
70
|
+
return Object.freeze(Object.assign({}, (selector ? selector(state[namespace] as T) : state[namespace]) as U));
|
|
71
|
+
}
|
|
16
72
|
|
|
17
|
-
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Updates a namespace in the global context. If the namespace does not exist, it is registered.
|
|
78
|
+
*/
|
|
79
|
+
export function updateContext<T extends {} = {}>(namespace: string, update: (state: T) => T) {
|
|
80
|
+
contextStore.setState((state) => {
|
|
81
|
+
if (!(namespace in state)) {
|
|
82
|
+
state[namespace] = {};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
state[namespace] = update(state[namespace] as T);
|
|
86
|
+
return state;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type ContextCallback<T extends {} = {}> = (state: Readonly<T> | null | undefined) => void;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Subscribes to updates of a given namespace. Note that the returned object is immutable.
|
|
94
|
+
*
|
|
95
|
+
* @param namespace the namespace to subscribe to
|
|
96
|
+
* @param callback a function invoked with the current context whenever
|
|
97
|
+
* @returns A function to unsubscribe from the context
|
|
98
|
+
*/
|
|
99
|
+
export function subscribeToContext<T extends {} = {}>(namespace: string, callback: ContextCallback<T>) {
|
|
100
|
+
let previous = getContext<T>(namespace);
|
|
101
|
+
|
|
102
|
+
return contextStore.subscribe((state) => {
|
|
103
|
+
let current: Readonly<T> | null | undefined = namespace in state ? (state[namespace] as T) : null;
|
|
104
|
+
|
|
105
|
+
if (current !== previous) {
|
|
106
|
+
previous = current;
|
|
107
|
+
callback(Object.freeze(Object.assign({}, current)));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from "./react-root-decorator";
|
|
1
|
+
export * from './context';
|
package/src/public.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './context';
|
package/tsconfig.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"esModuleInterop": true,
|
|
4
4
|
"module": "esnext",
|
|
5
|
+
"target": "es2015",
|
|
5
6
|
"allowSyntheticDefaultImports": true,
|
|
6
7
|
"jsx": "react",
|
|
7
8
|
"strictNullChecks": true,
|
|
@@ -16,7 +17,8 @@
|
|
|
16
17
|
"es2015",
|
|
17
18
|
"es2015.promise",
|
|
18
19
|
"es2016.array.include",
|
|
19
|
-
"es2018"
|
|
20
|
+
"es2018",
|
|
21
|
+
"esnext"
|
|
20
22
|
]
|
|
21
23
|
},
|
|
22
24
|
"include": ["src/**/*"]
|
package/webpack.config.js
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
1
|
+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
|
2
|
+
const { resolve, basename } = require('path');
|
|
3
|
+
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
4
|
+
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
|
4
5
|
|
|
5
|
-
const { peerDependencies } = require('./package.json');
|
|
6
|
+
const { browser, peerDependencies } = require('./package.json');
|
|
6
7
|
|
|
7
|
-
module.exports = {
|
|
8
|
-
entry: [resolve(__dirname,
|
|
8
|
+
module.exports = (env) => ({
|
|
9
|
+
entry: [resolve(__dirname, 'src/index.ts')],
|
|
9
10
|
output: {
|
|
10
|
-
filename:
|
|
11
|
-
path: resolve(__dirname,
|
|
12
|
-
|
|
11
|
+
filename: basename(browser),
|
|
12
|
+
path: resolve(__dirname, 'dist'),
|
|
13
|
+
library: { type: 'system' },
|
|
13
14
|
},
|
|
14
|
-
devtool:
|
|
15
|
+
devtool: 'source-map',
|
|
15
16
|
module: {
|
|
16
17
|
rules: [
|
|
17
|
-
{
|
|
18
|
-
parser: {
|
|
19
|
-
system: false,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
18
|
{
|
|
23
19
|
test: /\.m?(js|ts|tsx)$/,
|
|
24
20
|
exclude: /node_modules/,
|
|
25
|
-
use:
|
|
21
|
+
use: 'swc-loader',
|
|
26
22
|
},
|
|
27
23
|
],
|
|
28
24
|
},
|
|
25
|
+
externals: Object.keys(peerDependencies || {}),
|
|
29
26
|
resolve: {
|
|
30
|
-
extensions: [
|
|
31
|
-
modules: ["node_modules", resolve(__dirname, "node_modules")],
|
|
27
|
+
extensions: ['.ts', '.js', '.tsx', '.jsx'],
|
|
32
28
|
},
|
|
33
|
-
plugins: [
|
|
34
|
-
|
|
29
|
+
plugins: [
|
|
30
|
+
new CleanWebpackPlugin(),
|
|
31
|
+
new ForkTsCheckerWebpackPlugin(),
|
|
32
|
+
new BundleAnalyzerPlugin({
|
|
33
|
+
analyzerMode: env && env.analyze ? 'static' : 'disabled',
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
35
36
|
devServer: {
|
|
36
37
|
disableHostCheck: true,
|
|
37
38
|
headers: {
|
|
38
|
-
|
|
39
|
+
'Access-Control-Allow-Origin': '*',
|
|
39
40
|
},
|
|
40
41
|
},
|
|
41
|
-
};
|
|
42
|
+
});
|
package/.babelrc
DELETED
package/LICENSE
DELETED
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
Mozilla Public License, version 2.0
|
|
2
|
-
|
|
3
|
-
1. Definitions
|
|
4
|
-
|
|
5
|
-
1.1. "Contributor"
|
|
6
|
-
|
|
7
|
-
means each individual or legal entity that creates, contributes to the
|
|
8
|
-
creation of, or owns Covered Software.
|
|
9
|
-
|
|
10
|
-
1.2. "Contributor Version"
|
|
11
|
-
|
|
12
|
-
means the combination of the Contributions of others (if any) used by a
|
|
13
|
-
Contributor and that particular Contributor's Contribution.
|
|
14
|
-
|
|
15
|
-
1.3. "Contribution"
|
|
16
|
-
|
|
17
|
-
means Covered Software of a particular Contributor.
|
|
18
|
-
|
|
19
|
-
1.4. "Covered Software"
|
|
20
|
-
|
|
21
|
-
means Source Code Form to which the initial Contributor has attached the
|
|
22
|
-
notice in Exhibit A, the Executable Form of such Source Code Form, and
|
|
23
|
-
Modifications of such Source Code Form, in each case including portions
|
|
24
|
-
thereof.
|
|
25
|
-
|
|
26
|
-
1.5. "Incompatible With Secondary Licenses"
|
|
27
|
-
means
|
|
28
|
-
|
|
29
|
-
a. that the initial Contributor has attached the notice described in
|
|
30
|
-
Exhibit B to the Covered Software; or
|
|
31
|
-
|
|
32
|
-
b. that the Covered Software was made available under the terms of
|
|
33
|
-
version 1.1 or earlier of the License, but not also under the terms of
|
|
34
|
-
a Secondary License.
|
|
35
|
-
|
|
36
|
-
1.6. "Executable Form"
|
|
37
|
-
|
|
38
|
-
means any form of the work other than Source Code Form.
|
|
39
|
-
|
|
40
|
-
1.7. "Larger Work"
|
|
41
|
-
|
|
42
|
-
means a work that combines Covered Software with other material, in a
|
|
43
|
-
separate file or files, that is not Covered Software.
|
|
44
|
-
|
|
45
|
-
1.8. "License"
|
|
46
|
-
|
|
47
|
-
means this document.
|
|
48
|
-
|
|
49
|
-
1.9. "Licensable"
|
|
50
|
-
|
|
51
|
-
means having the right to grant, to the maximum extent possible, whether
|
|
52
|
-
at the time of the initial grant or subsequently, any and all of the
|
|
53
|
-
rights conveyed by this License.
|
|
54
|
-
|
|
55
|
-
1.10. "Modifications"
|
|
56
|
-
|
|
57
|
-
means any of the following:
|
|
58
|
-
|
|
59
|
-
a. any file in Source Code Form that results from an addition to,
|
|
60
|
-
deletion from, or modification of the contents of Covered Software; or
|
|
61
|
-
|
|
62
|
-
b. any new file in Source Code Form that contains any Covered Software.
|
|
63
|
-
|
|
64
|
-
1.11. "Patent Claims" of a Contributor
|
|
65
|
-
|
|
66
|
-
means any patent claim(s), including without limitation, method,
|
|
67
|
-
process, and apparatus claims, in any patent Licensable by such
|
|
68
|
-
Contributor that would be infringed, but for the grant of the License,
|
|
69
|
-
by the making, using, selling, offering for sale, having made, import,
|
|
70
|
-
or transfer of either its Contributions or its Contributor Version.
|
|
71
|
-
|
|
72
|
-
1.12. "Secondary License"
|
|
73
|
-
|
|
74
|
-
means either the GNU General Public License, Version 2.0, the GNU Lesser
|
|
75
|
-
General Public License, Version 2.1, the GNU Affero General Public
|
|
76
|
-
License, Version 3.0, or any later versions of those licenses.
|
|
77
|
-
|
|
78
|
-
1.13. "Source Code Form"
|
|
79
|
-
|
|
80
|
-
means the form of the work preferred for making modifications.
|
|
81
|
-
|
|
82
|
-
1.14. "You" (or "Your")
|
|
83
|
-
|
|
84
|
-
means an individual or a legal entity exercising rights under this
|
|
85
|
-
License. For legal entities, "You" includes any entity that controls, is
|
|
86
|
-
controlled by, or is under common control with You. For purposes of this
|
|
87
|
-
definition, "control" means (a) the power, direct or indirect, to cause
|
|
88
|
-
the direction or management of such entity, whether by contract or
|
|
89
|
-
otherwise, or (b) ownership of more than fifty percent (50%) of the
|
|
90
|
-
outstanding shares or beneficial ownership of such entity.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
2. License Grants and Conditions
|
|
94
|
-
|
|
95
|
-
2.1. Grants
|
|
96
|
-
|
|
97
|
-
Each Contributor hereby grants You a world-wide, royalty-free,
|
|
98
|
-
non-exclusive license:
|
|
99
|
-
|
|
100
|
-
a. under intellectual property rights (other than patent or trademark)
|
|
101
|
-
Licensable by such Contributor to use, reproduce, make available,
|
|
102
|
-
modify, display, perform, distribute, and otherwise exploit its
|
|
103
|
-
Contributions, either on an unmodified basis, with Modifications, or
|
|
104
|
-
as part of a Larger Work; and
|
|
105
|
-
|
|
106
|
-
b. under Patent Claims of such Contributor to make, use, sell, offer for
|
|
107
|
-
sale, have made, import, and otherwise transfer either its
|
|
108
|
-
Contributions or its Contributor Version.
|
|
109
|
-
|
|
110
|
-
2.2. Effective Date
|
|
111
|
-
|
|
112
|
-
The licenses granted in Section 2.1 with respect to any Contribution
|
|
113
|
-
become effective for each Contribution on the date the Contributor first
|
|
114
|
-
distributes such Contribution.
|
|
115
|
-
|
|
116
|
-
2.3. Limitations on Grant Scope
|
|
117
|
-
|
|
118
|
-
The licenses granted in this Section 2 are the only rights granted under
|
|
119
|
-
this License. No additional rights or licenses will be implied from the
|
|
120
|
-
distribution or licensing of Covered Software under this License.
|
|
121
|
-
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
|
122
|
-
Contributor:
|
|
123
|
-
|
|
124
|
-
a. for any code that a Contributor has removed from Covered Software; or
|
|
125
|
-
|
|
126
|
-
b. for infringements caused by: (i) Your and any other third party's
|
|
127
|
-
modifications of Covered Software, or (ii) the combination of its
|
|
128
|
-
Contributions with other software (except as part of its Contributor
|
|
129
|
-
Version); or
|
|
130
|
-
|
|
131
|
-
c. under Patent Claims infringed by Covered Software in the absence of
|
|
132
|
-
its Contributions.
|
|
133
|
-
|
|
134
|
-
This License does not grant any rights in the trademarks, service marks,
|
|
135
|
-
or logos of any Contributor (except as may be necessary to comply with
|
|
136
|
-
the notice requirements in Section 3.4).
|
|
137
|
-
|
|
138
|
-
2.4. Subsequent Licenses
|
|
139
|
-
|
|
140
|
-
No Contributor makes additional grants as a result of Your choice to
|
|
141
|
-
distribute the Covered Software under a subsequent version of this
|
|
142
|
-
License (see Section 10.2) or under the terms of a Secondary License (if
|
|
143
|
-
permitted under the terms of Section 3.3).
|
|
144
|
-
|
|
145
|
-
2.5. Representation
|
|
146
|
-
|
|
147
|
-
Each Contributor represents that the Contributor believes its
|
|
148
|
-
Contributions are its original creation(s) or it has sufficient rights to
|
|
149
|
-
grant the rights to its Contributions conveyed by this License.
|
|
150
|
-
|
|
151
|
-
2.6. Fair Use
|
|
152
|
-
|
|
153
|
-
This License is not intended to limit any rights You have under
|
|
154
|
-
applicable copyright doctrines of fair use, fair dealing, or other
|
|
155
|
-
equivalents.
|
|
156
|
-
|
|
157
|
-
2.7. Conditions
|
|
158
|
-
|
|
159
|
-
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
|
|
160
|
-
Section 2.1.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
3. Responsibilities
|
|
164
|
-
|
|
165
|
-
3.1. Distribution of Source Form
|
|
166
|
-
|
|
167
|
-
All distribution of Covered Software in Source Code Form, including any
|
|
168
|
-
Modifications that You create or to which You contribute, must be under
|
|
169
|
-
the terms of this License. You must inform recipients that the Source
|
|
170
|
-
Code Form of the Covered Software is governed by the terms of this
|
|
171
|
-
License, and how they can obtain a copy of this License. You may not
|
|
172
|
-
attempt to alter or restrict the recipients' rights in the Source Code
|
|
173
|
-
Form.
|
|
174
|
-
|
|
175
|
-
3.2. Distribution of Executable Form
|
|
176
|
-
|
|
177
|
-
If You distribute Covered Software in Executable Form then:
|
|
178
|
-
|
|
179
|
-
a. such Covered Software must also be made available in Source Code Form,
|
|
180
|
-
as described in Section 3.1, and You must inform recipients of the
|
|
181
|
-
Executable Form how they can obtain a copy of such Source Code Form by
|
|
182
|
-
reasonable means in a timely manner, at a charge no more than the cost
|
|
183
|
-
of distribution to the recipient; and
|
|
184
|
-
|
|
185
|
-
b. You may distribute such Executable Form under the terms of this
|
|
186
|
-
License, or sublicense it under different terms, provided that the
|
|
187
|
-
license for the Executable Form does not attempt to limit or alter the
|
|
188
|
-
recipients' rights in the Source Code Form under this License.
|
|
189
|
-
|
|
190
|
-
3.3. Distribution of a Larger Work
|
|
191
|
-
|
|
192
|
-
You may create and distribute a Larger Work under terms of Your choice,
|
|
193
|
-
provided that You also comply with the requirements of this License for
|
|
194
|
-
the Covered Software. If the Larger Work is a combination of Covered
|
|
195
|
-
Software with a work governed by one or more Secondary Licenses, and the
|
|
196
|
-
Covered Software is not Incompatible With Secondary Licenses, this
|
|
197
|
-
License permits You to additionally distribute such Covered Software
|
|
198
|
-
under the terms of such Secondary License(s), so that the recipient of
|
|
199
|
-
the Larger Work may, at their option, further distribute the Covered
|
|
200
|
-
Software under the terms of either this License or such Secondary
|
|
201
|
-
License(s).
|
|
202
|
-
|
|
203
|
-
3.4. Notices
|
|
204
|
-
|
|
205
|
-
You may not remove or alter the substance of any license notices
|
|
206
|
-
(including copyright notices, patent notices, disclaimers of warranty, or
|
|
207
|
-
limitations of liability) contained within the Source Code Form of the
|
|
208
|
-
Covered Software, except that You may alter any license notices to the
|
|
209
|
-
extent required to remedy known factual inaccuracies.
|
|
210
|
-
|
|
211
|
-
3.5. Application of Additional Terms
|
|
212
|
-
|
|
213
|
-
You may choose to offer, and to charge a fee for, warranty, support,
|
|
214
|
-
indemnity or liability obligations to one or more recipients of Covered
|
|
215
|
-
Software. However, You may do so only on Your own behalf, and not on
|
|
216
|
-
behalf of any Contributor. You must make it absolutely clear that any
|
|
217
|
-
such warranty, support, indemnity, or liability obligation is offered by
|
|
218
|
-
You alone, and You hereby agree to indemnify every Contributor for any
|
|
219
|
-
liability incurred by such Contributor as a result of warranty, support,
|
|
220
|
-
indemnity or liability terms You offer. You may include additional
|
|
221
|
-
disclaimers of warranty and limitations of liability specific to any
|
|
222
|
-
jurisdiction.
|
|
223
|
-
|
|
224
|
-
4. Inability to Comply Due to Statute or Regulation
|
|
225
|
-
|
|
226
|
-
If it is impossible for You to comply with any of the terms of this License
|
|
227
|
-
with respect to some or all of the Covered Software due to statute,
|
|
228
|
-
judicial order, or regulation then You must: (a) comply with the terms of
|
|
229
|
-
this License to the maximum extent possible; and (b) describe the
|
|
230
|
-
limitations and the code they affect. Such description must be placed in a
|
|
231
|
-
text file included with all distributions of the Covered Software under
|
|
232
|
-
this License. Except to the extent prohibited by statute or regulation,
|
|
233
|
-
such description must be sufficiently detailed for a recipient of ordinary
|
|
234
|
-
skill to be able to understand it.
|
|
235
|
-
|
|
236
|
-
5. Termination
|
|
237
|
-
|
|
238
|
-
5.1. The rights granted under this License will terminate automatically if You
|
|
239
|
-
fail to comply with any of its terms. However, if You become compliant,
|
|
240
|
-
then the rights granted under this License from a particular Contributor
|
|
241
|
-
are reinstated (a) provisionally, unless and until such Contributor
|
|
242
|
-
explicitly and finally terminates Your grants, and (b) on an ongoing
|
|
243
|
-
basis, if such Contributor fails to notify You of the non-compliance by
|
|
244
|
-
some reasonable means prior to 60 days after You have come back into
|
|
245
|
-
compliance. Moreover, Your grants from a particular Contributor are
|
|
246
|
-
reinstated on an ongoing basis if such Contributor notifies You of the
|
|
247
|
-
non-compliance by some reasonable means, this is the first time You have
|
|
248
|
-
received notice of non-compliance with this License from such
|
|
249
|
-
Contributor, and You become compliant prior to 30 days after Your receipt
|
|
250
|
-
of the notice.
|
|
251
|
-
|
|
252
|
-
5.2. If You initiate litigation against any entity by asserting a patent
|
|
253
|
-
infringement claim (excluding declaratory judgment actions,
|
|
254
|
-
counter-claims, and cross-claims) alleging that a Contributor Version
|
|
255
|
-
directly or indirectly infringes any patent, then the rights granted to
|
|
256
|
-
You by any and all Contributors for the Covered Software under Section
|
|
257
|
-
2.1 of this License shall terminate.
|
|
258
|
-
|
|
259
|
-
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
|
|
260
|
-
license agreements (excluding distributors and resellers) which have been
|
|
261
|
-
validly granted by You or Your distributors under this License prior to
|
|
262
|
-
termination shall survive termination.
|
|
263
|
-
|
|
264
|
-
6. Disclaimer of Warranty
|
|
265
|
-
|
|
266
|
-
Covered Software is provided under this License on an "as is" basis,
|
|
267
|
-
without warranty of any kind, either expressed, implied, or statutory,
|
|
268
|
-
including, without limitation, warranties that the Covered Software is free
|
|
269
|
-
of defects, merchantable, fit for a particular purpose or non-infringing.
|
|
270
|
-
The entire risk as to the quality and performance of the Covered Software
|
|
271
|
-
is with You. Should any Covered Software prove defective in any respect,
|
|
272
|
-
You (not any Contributor) assume the cost of any necessary servicing,
|
|
273
|
-
repair, or correction. This disclaimer of warranty constitutes an essential
|
|
274
|
-
part of this License. No use of any Covered Software is authorized under
|
|
275
|
-
this License except under this disclaimer.
|
|
276
|
-
|
|
277
|
-
7. Limitation of Liability
|
|
278
|
-
|
|
279
|
-
Under no circumstances and under no legal theory, whether tort (including
|
|
280
|
-
negligence), contract, or otherwise, shall any Contributor, or anyone who
|
|
281
|
-
distributes Covered Software as permitted above, be liable to You for any
|
|
282
|
-
direct, indirect, special, incidental, or consequential damages of any
|
|
283
|
-
character including, without limitation, damages for lost profits, loss of
|
|
284
|
-
goodwill, work stoppage, computer failure or malfunction, or any and all
|
|
285
|
-
other commercial damages or losses, even if such party shall have been
|
|
286
|
-
informed of the possibility of such damages. This limitation of liability
|
|
287
|
-
shall not apply to liability for death or personal injury resulting from
|
|
288
|
-
such party's negligence to the extent applicable law prohibits such
|
|
289
|
-
limitation. Some jurisdictions do not allow the exclusion or limitation of
|
|
290
|
-
incidental or consequential damages, so this exclusion and limitation may
|
|
291
|
-
not apply to You.
|
|
292
|
-
|
|
293
|
-
8. Litigation
|
|
294
|
-
|
|
295
|
-
Any litigation relating to this License may be brought only in the courts
|
|
296
|
-
of a jurisdiction where the defendant maintains its principal place of
|
|
297
|
-
business and such litigation shall be governed by laws of that
|
|
298
|
-
jurisdiction, without reference to its conflict-of-law provisions. Nothing
|
|
299
|
-
in this Section shall prevent a party's ability to bring cross-claims or
|
|
300
|
-
counter-claims.
|
|
301
|
-
|
|
302
|
-
9. Miscellaneous
|
|
303
|
-
|
|
304
|
-
This License represents the complete agreement concerning the subject
|
|
305
|
-
matter hereof. If any provision of this License is held to be
|
|
306
|
-
unenforceable, such provision shall be reformed only to the extent
|
|
307
|
-
necessary to make it enforceable. Any law or regulation which provides that
|
|
308
|
-
the language of a contract shall be construed against the drafter shall not
|
|
309
|
-
be used to construe this License against a Contributor.
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
10. Versions of the License
|
|
313
|
-
|
|
314
|
-
10.1. New Versions
|
|
315
|
-
|
|
316
|
-
Mozilla Foundation is the license steward. Except as provided in Section
|
|
317
|
-
10.3, no one other than the license steward has the right to modify or
|
|
318
|
-
publish new versions of this License. Each version will be given a
|
|
319
|
-
distinguishing version number.
|
|
320
|
-
|
|
321
|
-
10.2. Effect of New Versions
|
|
322
|
-
|
|
323
|
-
You may distribute the Covered Software under the terms of the version
|
|
324
|
-
of the License under which You originally received the Covered Software,
|
|
325
|
-
or under the terms of any subsequent version published by the license
|
|
326
|
-
steward.
|
|
327
|
-
|
|
328
|
-
10.3. Modified Versions
|
|
329
|
-
|
|
330
|
-
If you create software not governed by this License, and you want to
|
|
331
|
-
create a new license for such software, you may create and use a
|
|
332
|
-
modified version of this License if you rename the license and remove
|
|
333
|
-
any references to the name of the license steward (except to note that
|
|
334
|
-
such modified license differs from this License).
|
|
335
|
-
|
|
336
|
-
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
|
337
|
-
Licenses If You choose to distribute Source Code Form that is
|
|
338
|
-
Incompatible With Secondary Licenses under the terms of this version of
|
|
339
|
-
the License, the notice described in Exhibit B of this License must be
|
|
340
|
-
attached.
|
|
341
|
-
|
|
342
|
-
Exhibit A - Source Code Form License Notice
|
|
343
|
-
|
|
344
|
-
This Source Code Form is subject to the
|
|
345
|
-
terms of the Mozilla Public License, v.
|
|
346
|
-
2.0. If a copy of the MPL was not
|
|
347
|
-
distributed with this file, You can
|
|
348
|
-
obtain one at
|
|
349
|
-
http://mozilla.org/MPL/2.0/.
|
|
350
|
-
|
|
351
|
-
If it is not possible or desirable to put the notice in a particular file,
|
|
352
|
-
then You may include the notice in a location (such as a LICENSE file in a
|
|
353
|
-
relevant directory) where a recipient would be likely to look for such a
|
|
354
|
-
notice.
|
|
355
|
-
|
|
356
|
-
You may add additional accurate notices of copyright ownership.
|
|
357
|
-
|
|
358
|
-
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
|
359
|
-
|
|
360
|
-
This Source Code Form is "Incompatible
|
|
361
|
-
With Secondary Licenses", as defined by
|
|
362
|
-
the Mozilla Public License, v. 2.0.
|
|
363
|
-
|
|
364
|
-
---------------------
|
|
365
|
-
|
|
366
|
-
Healthcare Disclaimer
|
|
367
|
-
|
|
368
|
-
In the United States, or any other jurisdictions where they may apply, the
|
|
369
|
-
following additional disclaimer of warranty and limitation of liability are
|
|
370
|
-
hereby incorporated into the terms and conditions of MPL 2.0:
|
|
371
|
-
|
|
372
|
-
1. No warranties of any kind whatsoever are made as to the results that
|
|
373
|
-
You will obtain from relying upon the covered code (or any information
|
|
374
|
-
or content obtained by way of the covered code), including but not
|
|
375
|
-
limited to compliance with privacy laws or regulations or clinical
|
|
376
|
-
care industry standards and protocols. Use of the covered code is not
|
|
377
|
-
a substitute for a health care providers standard practice or
|
|
378
|
-
professional judgment. Any decision with regard to the appropriateness
|
|
379
|
-
of treatment, or the validity or reliability of information or content
|
|
380
|
-
made available by the covered code, is the sole responsibility of the
|
|
381
|
-
health care provider. Consequently, it is incumbent upon each health
|
|
382
|
-
care provider to verify all medical history and treatment plans with
|
|
383
|
-
each patient.
|
|
384
|
-
|
|
385
|
-
2. Under no circumstances and under no legal theory, whether tort
|
|
386
|
-
(including negligence), contract, or otherwise, shall any Contributor,
|
|
387
|
-
or anyone who distributes Covered Software as permitted by the
|
|
388
|
-
license, be liable to You for any indirect, special, incidental,
|
|
389
|
-
consequential damages of any character including, without limitation,
|
|
390
|
-
damages for loss of goodwill, work stoppage, computer failure or
|
|
391
|
-
malfunction, or any and all other damages or losses, of any nature
|
|
392
|
-
whatsoever (direct or otherwise) on account of or associated with the
|
|
393
|
-
use or inability to use the covered content (including, without
|
|
394
|
-
limitation, the use of information or content made available by the
|
|
395
|
-
covered code, all documentation associated therewith, and the failure
|
|
396
|
-
of the covered code to comply with privacy laws and regulations or
|
|
397
|
-
clinical care industry standards and protocols), even if such party
|
|
398
|
-
shall have been informed of the possibility of such damages.
|
|
399
|
-
|
|
400
|
-
Copyright (c) OpenMRS Inc.
|
|
401
|
-
OpenMRS is a registered trademark and the OpenMRS graphic logo is a trademark of OpenMRS Inc.
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { openmrsRootDecorator } from "./react-root-decorator";
|
|
3
|
-
import { render, screen, waitFor } from "@testing-library/react";
|
|
4
|
-
import { ModuleNameContext } from "./context";
|
|
5
|
-
|
|
6
|
-
describe("openmrs-react-root-decorator", () => {
|
|
7
|
-
const opts = {
|
|
8
|
-
featureName: "Test",
|
|
9
|
-
throwErrorsToConsole: false,
|
|
10
|
-
moduleName: "test",
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
it("renders a component", () => {
|
|
14
|
-
const DecoratedComp = openmrsRootDecorator(opts)(CompThatWorks);
|
|
15
|
-
render(<DecoratedComp />);
|
|
16
|
-
waitFor(() => {
|
|
17
|
-
expect(screen.getByText("The button")).toBeTruthy();
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("catches any errors in the component tree and renders a ui explaining something bad happened", () => {
|
|
22
|
-
const DecoratedComp = openmrsRootDecorator(opts)(CompThatThrows);
|
|
23
|
-
render(<DecoratedComp />);
|
|
24
|
-
// TO-DO assert the UX for broken react app is showing
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("provides ModuleNameContext", () => {
|
|
28
|
-
const DecoratedComp = openmrsRootDecorator(opts)(CompWithConfig);
|
|
29
|
-
render(<DecoratedComp />);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
function CompThatWorks() {
|
|
34
|
-
return <button>The button</button>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function CompThatThrows() {
|
|
38
|
-
throw Error("ahahaa");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function CompWithConfig() {
|
|
42
|
-
const moduleName = React.useContext(ModuleNameContext);
|
|
43
|
-
return <div>{moduleName}</div>;
|
|
44
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { I18nextProvider } from "react-i18next";
|
|
3
|
-
import _i18n from "i18next";
|
|
4
|
-
import { ModuleNameContext } from "./context";
|
|
5
|
-
|
|
6
|
-
const i18n = (_i18n as any).default || _i18n;
|
|
7
|
-
|
|
8
|
-
const defaultOpts = {
|
|
9
|
-
strictMode: true,
|
|
10
|
-
throwErrorsToConsole: true,
|
|
11
|
-
disableTranslations: false,
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export function openmrsRootDecorator(userOpts) {
|
|
15
|
-
if (
|
|
16
|
-
typeof userOpts !== "object" ||
|
|
17
|
-
typeof userOpts.featureName !== "string" ||
|
|
18
|
-
typeof userOpts.moduleName !== "string"
|
|
19
|
-
) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
"openmrs-react-root-decorator should be called with an opts object that has " +
|
|
22
|
-
"1. a featureName string that will be displayed to users, and 2. a moduleName string. " +
|
|
23
|
-
"The moduleName string will be used to look up configuration. " +
|
|
24
|
-
"e.g. openmrsRootDecorator({featureName: 'nice feature', moduleName: '@openmrs/esm-nice-feature' })"
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const opts = Object.assign({}, defaultOpts, userOpts);
|
|
29
|
-
|
|
30
|
-
return function decorateComponent(Comp) {
|
|
31
|
-
return class OpenmrsReactRoot extends React.Component {
|
|
32
|
-
static displayName = `OpenmrsReactRoot(${opts.featureName})`;
|
|
33
|
-
state = {
|
|
34
|
-
caughtError: null,
|
|
35
|
-
caughtErrorInfo: null,
|
|
36
|
-
};
|
|
37
|
-
render() {
|
|
38
|
-
if (this.state.caughtError) {
|
|
39
|
-
// TO-DO have a UX designed for when a catastrophic error occurs
|
|
40
|
-
return null;
|
|
41
|
-
} else {
|
|
42
|
-
const rootComponent = (
|
|
43
|
-
<ModuleNameContext.Provider value={opts.moduleName}>
|
|
44
|
-
<React.Suspense fallback={null}>
|
|
45
|
-
{opts.disableTranslations ? (
|
|
46
|
-
<Comp {...this.props} />
|
|
47
|
-
) : (
|
|
48
|
-
<I18nextLoadNamespace
|
|
49
|
-
ns={opts.moduleName}
|
|
50
|
-
forceUpdate={() => this.forceUpdate()}
|
|
51
|
-
>
|
|
52
|
-
<I18nextProvider i18n={i18n} defaultNS={opts.moduleName}>
|
|
53
|
-
<Comp {...this.props} />
|
|
54
|
-
</I18nextProvider>
|
|
55
|
-
</I18nextLoadNamespace>
|
|
56
|
-
)}
|
|
57
|
-
</React.Suspense>
|
|
58
|
-
</ModuleNameContext.Provider>
|
|
59
|
-
);
|
|
60
|
-
if (opts.strictMode || !React.StrictMode) {
|
|
61
|
-
return rootComponent;
|
|
62
|
-
} else {
|
|
63
|
-
return <React.StrictMode>{rootComponent}</React.StrictMode>;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
componentDidCatch(err, info) {
|
|
68
|
-
if (info && info.componentStack) {
|
|
69
|
-
err.extra = Object.assign(err.extra || {}, {
|
|
70
|
-
componentStack: info.componentStack,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (opts.throwErrorsToConsole) {
|
|
75
|
-
setTimeout(() => {
|
|
76
|
-
throw err;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
this.setState({
|
|
81
|
-
caughtError: err,
|
|
82
|
-
caughtErrorInfo: info,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function I18nextLoadNamespace(props) {
|
|
90
|
-
React.useEffect(() => {
|
|
91
|
-
i18n.on("languageChanged", props.forceUpdate);
|
|
92
|
-
return () => i18n.off("languageChanged", props.forceUpdate);
|
|
93
|
-
}, [props.forceUpdate]);
|
|
94
|
-
|
|
95
|
-
const loadNamespaceErrRef = React.useRef(null);
|
|
96
|
-
|
|
97
|
-
if (loadNamespaceErrRef.current) {
|
|
98
|
-
throw loadNamespaceErrRef.current;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (!i18n.hasLoadedNamespace(props.ns)) {
|
|
102
|
-
const timeoutId = setTimeout(() => {
|
|
103
|
-
console.warn(
|
|
104
|
-
`openmrs-react-root-decorator: the React suspense promise for i18next.loadNamespaces(['${props.ns}']) did not resolve nor reject after three seconds. This could mean you have multiple versions of i18next and haven't made i18next a webpack external in all projects.`
|
|
105
|
-
);
|
|
106
|
-
}, 3000);
|
|
107
|
-
|
|
108
|
-
throw i18n
|
|
109
|
-
.loadNamespaces([props.ns])
|
|
110
|
-
.then(() => {
|
|
111
|
-
clearTimeout(timeoutId);
|
|
112
|
-
})
|
|
113
|
-
.catch((err) => {
|
|
114
|
-
clearTimeout(timeoutId);
|
|
115
|
-
loadNamespaceErrRef.current = err;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return props.children;
|
|
120
|
-
}
|