Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //middleware parttner (chain of responsability)
- const passo1 = ( ctx, next) =>{
- ctx.valor1 = 'mid1'
- next()
- }
- const passo2 = (ctx, next) =>{
- ctx.valor2 = 'mid'
- next()
- }
- const passo3 = ctx => ctx.valor3 = 'mid3'
- const exec = (ctx, ...midlewares) =>{
- const execPassso = indice =>{
- midlewares && indice < midlewares.length &&
- midlewares[indice](ctx, () => execPassso(indice + 1))
- }
- execPassso(0)
- }
- const ctx = {}
- exec(ctx, passo1, passo2, passo3)
- console.log(ctx)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement