A simple middleware module that you know and love. Using the "next" pattern means you can have async/sync middleware!
npm install @parkhub/circe-middleware
import circeMiddleware from '@parkhub/circe-middleware';
const middlewareFnOne = (value, next) => {
// value is 'starting value'
// Call next and pass params with any arity(as long as next middleware expects the same arity)
next('Satsuki!');
};
const middlewareFnTwo = (value, next) => {
// Value is 'Satsuki!'
// Call next and pass params with any arity(as long as next middleware expects the same arity)
next({ going: 'gone' }, 1);
};
const middlewareFnThree = (obj, int, next) => {
// obj is { going: 'gone' } and int is 1
next('done');
}
// The middleware is executed in the order of the passed array
const middleware = circeMiddleware([middlewareFnOne, middlewareFnTwo]);
// This middleware will be executed after the first two passed into the middleware factory
middleware.use(middlewareFnThree);
middleware.run('starting value', (finalValue) => {
// finalValue is 'done'
});
A middleware is a function that receives an arbitrary number of parameters with the last one being the next function. You have to be conscious of the order of the middlware and what it accepts as parameters
Adds a middleware to the middleware stack.