core-stack
Create an object implementing:
- An event emitter (Evemit, only 1 kb).
- A plugin system that handles the asynchronous loading.
- A stack handler.
- And some useful methods for handling a core and config object.
core-stack was implemented with performance and lightness in mind.
Install
npm install core-stack
or with Yarn:
yarn add core-stack
Usage
See the source code for the JS doc.
Create a core
import CoreStack from 'core-stack';
const core = new CoreStack();
core.foo = {};
core.bar = 'bar';
export default core;
Plugins
Create a plugin
export default function myPlugin(core, args, done) {
done(args);
};
Use a plugin
On the fly:
core.use(plugin, pluginArgs, function(done ) {
console.log('plugin loaded!');
done();
});
or a reusable plugin:
import myPlugin from './plug/myPlugin';
core.use(myPlugin);
Example, create a simple logger plugin (reusable):
export default function loggerPlugin(core, args, done) {
core.log = function() {
console.log(...arguments);
};
core.logWarn = function() {
console.warn(...arguments);
};
core.logError = function() {
console.error(...arguments);
};
done();
};
Load and use the logger plugin:
import logger from './plug/logger';
core.use(logger);
core.boot(function() {
core.log('Hello');
core.logWarn('Warning!');
core.logError('Ooops! An error occurred.');
})
Full example
import CoreStack from 'core-stack';
import logger from './plug/logger/';
import config from './plug/config/';
import router from './plug/router/';
import react from './plug/react/';
const app = new CoreStack();
app
.use(logger)
.use(config)
.use(router)
.use(react)
.boot(function() {
app.log('all plugins are loaded');
app.emit('app.booted');
router.init();
})
;
LICENSE
MIT (c) 2016, Nicolas Tallefourtane.
Author