New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

modapp

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modapp

A thin framework for building completely modular web applications.

latest
Source
npmnpm
Version
2.7.0
Version published
Maintainers
1
Created
Source

view on npm

ModApp

A thin framework for building modular web applications.

Installation

With npm:

npm install modapp

With yarn:

yarn add modapp

Example

import { App } from 'modapp';

// A module keeping track of greetings
class Greetings {
	constructor(app, params) {
		this.app = app;
		this.greetings = {};
	}

	addGreeting(lang, greeting) {
		this.greetings[lang] = greeting;
	}

	removeGreeting(lang) {
		delete this.greetlings[lang];
	}

	greet(lang) {
		let greeting = this.greetings[lang];
		console.log(greeting || "Unknown language");
	}

	dispose() {} // Nothing to dispose
}

// A module for swedish greetings
class EnglishGreeting {
	constructor(app, params) {
		this.app = app;
		this.greeting = params.greeting || "Hello";
		this.app.require(['greetings'], this._init.bind(this));
	}

	_init(module)  {
		this.module = module;
		this.module.greetings.addGreeting('english', this.greeting);
	}

	dispose() {
		this.module.greetings.removeGreeting('english');
	}
}

// Creating the app with some module configuration. These parameters may be overwritten using url queries
let app = new App({ englishGreeting: { greeting: "Hi" }});

// Bundles are usually created dynamically using tools like webpacks require context.
let bundle = {
	greetings: Greetings,
	englishGreeting: EnglishGreeting
};

app.loadBundle(bundle)
	.then(result => {
		console.log("Modules loaded: ", result);
		app.getModule('greetings').greet('english');
	});

Using modapp

Modules can be loaded, deactivate, and reactivated while the application is running, allowing hotloading of new features and functionality to the application. New modules will simply hook into the application using the register/unregister methods provided (addGreeting and removeGreeting in the example).

Try resgate-test-app to see modapp in use.

AppModule interface

For a class to be loaded by the app, it must follow the AppModule interface.
A module may expose any number of public methods, using camelCase as naming convention.
All properties should be considered private, as well as any methods starting with an underscore (_).
Any exposed method that allows other modules to register objects or callbacks, must come paired with a method for unregistering.

appModule.constructor(app, params)

The app module constructor.
It is only in the constructor that the module may call app.require(...). If app.require is called, the module must postpone registering any objects or callbacks until the require callback is called to prevent memory leaks in case the App cannot fulfill the requirements and discards the app module. (#AppModule)

ParamTypeDescription
appAppThe app instance
paramsObject.<string, *>Module parameters from the app config

appModule.dispose()

Disposes the app module, removing any items or callbacks previously registered within the constructor or in the app.require callback.
Once disposed, no more calls will be done to the module instance.

Documentation

Markdown documentation

FAQs

Package last updated on 06 Feb 2024

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