morph-middleware
v1.1.1
Published
Middleware implementation
Readme
Morph: Middleware
Middleware implementation module. Work in progress
Installing
You can use the command npm i morph-middleware.
Getting Started
const Middleware = require('morph-middleware');
let test = new Middleware();
test.use('First', async function() {
console.dir(this);
this.pass('wow', 'lol');
});
test.use('Second', async function(object, string, array) { // Arguments from Middleware#go
console.dir(arguments);
return { second: true };
});
test.use('Third', async function() {
this.break('this is a test');
});
test.use('Four', async () => console.log('This will never be called'));
test.pre('BEFORE EVERYTHING!', async () => {
console.log('This will be called before everything');
return { is: 'this', working: '?', of: 'course' };
});
test.go({ this: 'is' }, 'a', ['test']).then(d => console.log('Middleware done: ' + JSON.stringify(d)));You can either return an object or use
this.passto pass data. You can access it withthis.data.
If you use arrow functions you lose
thisand its functionsbreak, andpass.
Coming soon
Priority system
