In the vast realm of software development, each programmer possesses a distinct…
- User
In the vast realm of software development, each programmer possesses a distinct programming style. Some styles stand out as unique creations, while others represent a harmonious blend of existing approaches or serve as replicas of established norms. Among these diverse styles, one that stands apart is the MDR Programming style, a unique concept built upon the foundational principles of Event-Based programming in JavaScript.
Conceived by the visionary programmer BlueLatios on April 26th, 2024, this programming style embraces a simple yet powerful motto: “Monitor, Dispatch, Response.” Its goal is to create a modular event-driven system that exhibits exceptional scalability and ease of use that readily takes advantage of JavaScript’s many features. It heavily leans on JavaScript’s event-based API, such as the browser level CustomAPI or the NodeJS EventEmitter.
The underlying philosophy of Event-Based programming is to decouple the event handling logic from the core application code. This approach offers numerous benefits. First, it promotes modularity, as different parts of the system can be easily isolated and maintained. Second, it enhances scalability, as event handling can be distributed across multiple servers or processes. Third, it simplifies debugging, as errors can be traced back to specific events. And finally, it’s very well suited for asynchronous operations, due to JavaScript’s event-driven nature.
Programmers who embrace this style start with a solid modular base that constantly monitors for changes in the system. Once a change is detected, the system dispatches an appropriate event. This event is then handled by a corresponding response, which takes necessary actions to address the change.
The MDR Programming style can be modeled as a hub-like system consisting of three interconnected hubs, each with its own distinct purpose and separate components. These components work together in a specific order to achieve the overall goals of the programming style.
Initiation Gateway
The Initiation Gateway serves as the initial start / gateway to the event-driven system. Its primary role is to help initiate the system and any other relevant processes that may be required. Components of Initiation Gateway: Initialization Unit: Responsible for initialising the event-driven system and setting up any necessary configurations or initial state. Startup Coordinator: Coordinates the startup process of the system, ensuring that all required components are initialised in the correct order. Dependency Injector: Manages the injection of dependencies into various components of the system, ensuring that they have access to the resources they need. Configuration Manager: Handles system-wide configurations, including settings for different environments and modules. Bootstrapper: Facilitates the bootstrapping process by preparing the system for execution and launching the necessary processes.
Dispatch Hub
The Dispatch Hub serves as the central monitoring and analysis center of the system. Its primary role is to monitor and analyze system and user actions, as well as environmental changes. Based on its analysis, the Dispatch Hub emits certain events to trigger subsequent actions.
- Assistant
Yes, I understand the description of the MDR Programming style you provided. This style primarily focuses on creating a modular, event-driven architecture using JavaScript, designed to handle system events efficiently and in an organized manner. Let me summarize the key components and flow based on your explanation:
- User
class GameEventHandler { constructor(debugManager) { this.debugManager = debugManager; }
handleEvent = (event) => { const { type, value, valuePercent, oldValue, change, updatedProperties } = event.detail; const player = game.ui.getPlayerTick(); if (!player || !game.getInWorld()) return; const eventHandlers = { "PlayerDied": this.handlePlayerDied, "PlayerRespawned": this.handlePlayerRespawned, "PlayerInvulnerable": this.handlePlayerInvulnerable, "PlayerHealthChange": this.handlePlayerHealthChange, "PlayerPositionChange": this.handlePlayerPositionChange, "PlayerDamaged": this.handlePlayerDamaged, "PlayerAimingYawChange": this.handlePlayerAimingYawChange, "PlayerResourceUpdate": this.handlePlayerResourceUpdate, "ServerEntityUpdate": this.handleServerEntityUpdate, "ServerPlayerCreated": this.handleServerPlayerCreated, "ServerPlayerDeleted": this.handleServerPlayerDeleted, "LocalEntityCreated": this.handleLocalEntityCreated, "LocalEntityDeleted": this.handleLocalEntityDeleted, "LocalEntityPropertiesUpdated": this.handleLocalEntityPropertiesUpdated, "LocalBuildingCreated": this.handleLocalBuildingCreated, "LocalBuildingDeleted": this.handleLocalBuildingDeleted, "LocalBuildingUpdated": this.handleLocalBuildingUpdated, }; const handler = eventHandlers[type]; if (handler) { handler({ value, valuePercent, oldValue, change, updatedProperties }); } } - Assistant
- User
So the large amounts of methods are just something I have to deal with in this programming style, is this right?
- Assistant
- User
const initiationGateway = { bootstrap: function () { this.startup(); }, startup: function () { const debugManager = new DebugManager(); globalThis.debug = debugManager; globalThis.scriptProperties = ScriptProperties;
const rpcEventDispatcher = new RpcEventDispatcher(debugManager); rpcEventDispatcher.init(); // Control Centers game.eventEmitter.on("EntityUpdate", new EntityUpdateHandler().handleEntityUpdate); document.addEventListener("GameEvent", new GameControlCenter(debugManager).handleEvent); document.addEventListener("RpcEvent", new RpcControlCenter(debugManager).handleEvent); const scriptContainerManager = new ScriptContainerManager(); scriptContainerManager.initialize(); }};
initiationGateway.bootstrap();
Do you think this is a valid implementation of an object literal
- Assistant