morph-middleware

1.1.1 • Public • Published

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.pass to pass data. You can access it with this.data.

If you use arrow functions you lose this and its functions break, and pass.

Coming soon

Priority system

Readme

Keywords

Package Sidebar

Install

npm i morph-middleware

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

3.83 kB

Total Files

5

Last publish

Collaborators

  • ryzzzen