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

cerebral-modules

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cerebral-modules - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

68

lib/index.js

@@ -14,5 +14,6 @@ 'use strict';

function setActiveModuleAction(name) {
return function setActiveModule(input, state) {
state.set(['activeModule'], name);
if (state.get(['activeModule']) !== name) {
state.set(['activeModule'], name);
}
};

@@ -22,31 +23,54 @@ }

function load(controller, modules) {
var appChains = {};
var initChain = [];
if (!Array.isArray(modules) || !modules.length) {
console.error('No modules loaded');
} else {
(function () {
var initChain = [];
var allChains = modules.reduce(function (chains, item) {
modules.forEach(function (mod) {
if (!mod.name) {
console.error('Cannot load unnamed module', mod);
} else if (_modules[mod.name]) {
console.error('Module name clash', _modules[mod.name], mod);
} else {
(function () {
_modules[item.name] = item;
// load the module
_modules[mod.name] = mod;
var chains = typeof mod.init === 'function' ? mod.init(controller) || {} : {};
// add the module init chain to the modules init chain
if (Array.isArray(item.chains.init)) {
initChain.push.apply(initChain, _toConsumableArray(item.chains.init));
}
// add the module init chain to the modules init chain
if (Array.isArray(chains.init)) {
initChain.push.apply(initChain, _toConsumableArray(chains.init));
}
// add the modules external chains
if (item.isService) {
chains[item.name] = item.chains;
} else {
Object.keys(item.chains).forEach(function (chain) {
return chains[item.name][chain] = [setActiveModuleAction(item.name)].concat(_toConsumableArray(item.chains[chain]));
// add the module's external chains
if (mod.isService) {
appChains[mod.name] = chains;
} else {
appChains[mod.name] = {};
// all non-service modules need an opened chain
if (!Array.isArray(chains.opened)) {
chains.opened = [];
}
// non-service modules should be set as active when external chains are run
Object.keys(chains).forEach(function (chain) {
return appChains[mod.name][chain] = [setActiveModuleAction(mod.name)].concat(_toConsumableArray(chains[chain]));
});
}
})();
}
});
}
}, {});
// if one more modules had an init chain, execute the modules init chains
if (initChain.length) {
controller.signal('modules.init', initChain);
controller.signals.modules.init();
// if one or more modules had an init chain, execute the module.init signal
if (initChain.length) {
controller.signal('modules.init', initChain);
controller.signals.modules.init();
}
})();
}
return allChains;
return appChains;
}

@@ -53,0 +77,0 @@

{
"name": "cerebral-modules",
"version": "0.2.0",
"version": "0.3.0",
"description": "A library for making modular cerebral apps",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -5,2 +5,8 @@ # cerebral-modules

## Install
```
npm install cerebral-modules
```
## Creating a module

@@ -14,5 +20,10 @@

isService: false, //service modules do not affect the activeModule state
chains: {
init: [] // init chain will be execute on app start
// other exposed chains
init(controller) {
// initialise the module here
// return signal chains
return {
init: [] // init chain will be execute on app start
// other chains that can be used to setup the routing for the app
};
},

@@ -19,0 +30,0 @@ // optional root component

Sorry, the diff of this file is not supported yet

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