Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

composite-modules

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

composite-modules

A module loader structure implemented using Composite Pattern.

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Welcome to Composite Modules 👋

Version Documentation

This module facilitates the usage of a Composite based module structure on your system.

Install

yarn users:

yarn add composite-modules

npm users:

npm install composite-modules

Importing:

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.

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.

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<void> {
        this.beautyLogs.info('Loading this structures...');
        
        // Your loading definitions goes here...
        ...

        this.beautyLogs.success('Loaded this structures...');
    }

    async unload (): Promise<void> {
        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):

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)

Keywords

FAQs

Package last updated on 22 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc