UNPKG

rich-domain

Version:

This package provide utils file and interfaces to assistant build a complex application with domain driving design

40 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Context = void 0; const platform_util_1 = require("../utils/platform.util"); const browser_event_manager_1 = require("./browser-event-manager"); const server_event_manager_1 = require("./server-event-manager"); /** * @description The Context class provides a platform-aware mechanism for * retrieving a global event manager instance. Depending on the environment * (Node.js or browser), it initializes and returns an appropriate event manager. */ class Context { static eventManager; /** * @description Retrieves the global event manager instance for the current platform. * If one does not already exist, it is created based on the detected runtime environment. * - In Node.js environments, it uses `ServerEventManager`. * - In browser environments, it uses `BrowserEventManager`. * * @throws Will throw an error if the platform cannot be determined. * @returns The platform-specific `EventManager` instance. */ static events() { if (Context.eventManager) return Context.eventManager; if (platform_util_1.default.isNodeJs(global?.process)) { Context.eventManager = server_event_manager_1.default.instance(); } else if (platform_util_1.default.isBrowser(globalThis?.window)) { Context.eventManager = browser_event_manager_1.default.instance(globalThis.window); } else { throw new Error('Could not determine the platform to initialize the event manager.'); } return Context.eventManager; } } exports.Context = Context; exports.default = Context; //# sourceMappingURL=context.js.map