UNPKG

@openmrs/esm-extensions

Version:

Coordinates extensions and extension points in the OpenMRS Frontend

29 lines (28 loc) 1.26 kB
import { createGlobalStore } from "@openmrs/esm-state"; import { getExtensionRegistration } from "./index.js"; const modalRegistryStore = createGlobalStore('modalRegistry', { modals: {} }); /** @internal */ export function registerModal(modalRegistration) { modalRegistryStore.setState((state)=>{ state.modals[modalRegistration.name] = modalRegistration; return state; }); } /** @internal */ export function getModalRegistration(modalName) { let modalRegistration = modalRegistryStore.getState().modals[modalName]; if (!modalRegistration) { const extensionRegistration = getExtensionRegistration(modalName); if (extensionRegistration) { modalRegistration = { name: modalName, load: extensionRegistration.load, moduleName: extensionRegistration.moduleName }; console.warn(`Modal ${modalName} was registered as an extension. This is deprecated and will be removed in the future. Please register it in the "modals" section of routes.json instead of the "extensions" section.`); // Register it so the warning only appears once registerModal(modalRegistration); } } return modalRegistration; }