Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iagocalazans/composite-modules
A module loader structure implemented using Composite Pattern.
https://github.com/iagocalazans/composite-modules
base composite-pattern framework module modules pattern simple typescript
Last synced: 7 days ago
JSON representation
A module loader structure implemented using Composite Pattern.
- Host: GitHub
- URL: https://github.com/iagocalazans/composite-modules
- Owner: iagocalazans
- License: mit
- Created: 2021-09-17T18:52:13.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-09-22T16:20:52.000Z (about 3 years ago)
- Last Synced: 2024-02-10T00:04:03.478Z (9 months ago)
- Topics: base, composite-pattern, framework, module, modules, pattern, simple, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/composite-modules
- Size: 56.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Welcome to Composite Modules 👋
### This module facilitates the usage of a Composite based module structure on your system.
## Install
yarn users:
```sh
yarn add composite-modules
```
npm users:
```sh
npm install composite-modules
```Importing:
```js
import { ModulesContainer } from 'composite-modules'
```---
## Usage:
### Common application, normal structure.
You should use the default ModuleContainer and add all the modules you created to it.
```js
const unamedComposite = new ModuleUnamed('unamed');
const anotherUnamedComposite = new AnotherModuleUnamed('anotherUnamed');
const simpleModule = new SimpleUnamedModule('simpleUnamed');anotherUnamedComposite.add(simpleModule);
unamedComposite.add(anotherUnamedComposite);
ModulesContainer.add(unamedComposite);void ModulesContainer.init();
ModulesContainer.events.on('ready', (modules) => {
// Here we ensure that all of your modules have been loaded and you can access them.
modules.collection.use('anotherUnamed').anotherFunction()...
})```
### To create your Module, extend the CompositeModule or the SimpleModule.
You need to extend the CompositeModule or SimpleModule modules, creating from them the modules you want to add to the module tree.
Remembering that the CompositeModule can have child modules. These will normally be loaded into the structure, as long as they are added correctly.
```js
export class ModuleUnamed extends CompositeModule {
// You can add as many properties as you need...
private myProperty: any;
public myPropertyTwo: any;// As a standard you always need to pass a name as parameter.
constructor(name: string, yourParams: any) {
super(name); // Must always pass name as super call.// Your constructor definitions goes here...
...
}async load (): Promise {
this.beautyLogs.info('Loading this structures...');
// Your loading definitions goes here...
...this.beautyLogs.success('Loaded this structures...');
}async unload (): Promise {
this.beautyLogs.info('Unoading this structures...');// Your unload definitions goes here...
...this.beautyLogs.success('Unloaded this structures...');
}
}
```I recommend using `this.beautyLogs` for logs, it displays logs in a pattern and pretty like this (with colors):
```sh
2021-09-22T15:28:41.218Z (system) [Container]: [*] System is starting...
2021-09-22T15:28:41.220Z (info) [SimpleUnamedModule]: Loading this structures...
2021-09-22T15:28:41.220Z (success) [SimpleUnamedModule]: Loaded this structures...
2021-09-22T15:28:41.220Z (info) [AnotherModuleUnamed]: Loading this structures...
2021-09-22T15:28:41.221Z (info) [ModuleUnamed]: Loading this structures...
2021-09-22T15:28:41.221Z (success) [ModuleUnamed]: Loaded this structures...
```---
## Author
👤 **Iago Calazans** (💼 *Senior Node | TypeScript Developer*)
* Website: https://iagocalazans.github.io/
* GitHub: https://github.com/iagocalazans/