@dedaca/deda-core-bus
v3.0.0
Published
Core DEDA (Distributed Event Driven Application) is an event based, component loader framework used to create server side (nodejs) and client side (browser).
Downloads
3
Readme
DEDA Core
DEDA Core is an event based, component loader framework used to create server side (nodejs) and client side (browser). It is responsible for loading application components defined within a JSON file and running the application.
The main design principal in this project is simplicity and less code. This simply a structure. DEDA provides a very simple, clean and straight forward way fo created modularized/componentized application.
DEDA Application JSON
The idea behind creating an application using a JSON file is to force componentization. Components can be loaded from anywhere; local file system, remote file shares, web URL (github or gitlab) etc. In DEDA an application is simply a list of components and their configurations. For example:
{
"deda": {
"dependencies": [
"deda-core",
],
"files": [
"./src/myComponent1.js",
"./src/myComponent2.js",
"./src/myComponent2.js",
],
"components": [
{
"namespace": "MyApp.Component1",
"port": 4500,
"host": "0.0.0.0"
},
{
"namespace": "MyApp.Component2",
"debug": true,
"maxUsers": 5
}
]
}
}
The JSON file has 3 sections:
- dependencies: a list of dependencies which are also DEDA components.
- files: a list of files within this project to load.
- components: a list of components to create and start.
The Module
loader starts by loading the dependencies and their dependencies, followed by the application files, then the Bus
creates the components using their namespace. Finally initializes and starts the application/components.
Project Files
The project files are split into 3;
- Common files for both node and browser.
- Node specific files.
- Browser specific files.
Classes
DEDA.Core.Component
- Is the heart of DEDA components and all components must extend this class. The constructor accepts the applicationbus
and the components configurations.DEDA.Core.Bus
- This is the application heat. All components have a reference to itthis.bus
. It is the event emitter used by components to communicate. It also loads the "components" from the JSON and provides a common API for applications such as: env, event emitter, list of all components, logging interface, and language interface.DEDA.Core.Module
- The module is similar to the JS Common where it is responsible for loading the "dependencies" and "files" for the application no matter where they are. There is a node and browser implementation of the base class.
There are 2 helper classes
DEDA.Core.Utility
- Provides general utility methods.DEDA.Core.Environment
- Provides node specified environment and command line arguments parsing and loading.
There isn't much code in any of these classes the project idea is to provide a simple structure for promoting component/module based application architecture.
Environment
The environment class provides a way to parse command line arguments and load environment files:
- Loads JSON config files for multiple components, applications, and environments. See config JSON format above.
- Create different config profiles for debug, development, release, etc. within a single file and apply them based on a command line argument.
- Loads
process.env
withinbus.env
. - Loads
process.args
withinDEDA.env
and applies commands.
Env File Format:
{
"use": "<string>|[<string>]",
"defaults": {
"base_url": "https://domain.com"
},
"dev": {
"api_url": "${env.base_url}/api/laundry/admin"
}
}
- The
use
property lists the configs to add to the env object. - The
defaults
are automatically add to the env object.
Added property values are processed and replaced with the variables within the environment. In the above example ${env.base_url}
will be replace with the actual value. This format also applies to all DEDA JSON component configs automatically when a component is loaded.
Command Line Arguments
The parser supports the following:
Key value as: -key value
Key with no value is set to true: -key
If same key exists multiple times the values are converted to an array.
-v false -dev -port 456 -host 10.10.10.4 -host 192.168.1.1
This is converted to the following object.
{
"v": false,
"dev": true,
"port": "456",
"host": [
"10.10.10.4",
"192.168.1.1"
]
}