app-builder
TypeScript icon, indicating that this package has built-in type declarations

7.0.4 • Public • Published

app-builder

Actions Status

Create composable promise based middleware pipelines, using the "onion" middleware model.

Install:

npm install app-builder

Example

import { compose } from 'app-builder'

const app = compose([
  async function (ctx, next) {
    ctx.value += 1
    await next()
    ctx.value += 4
  },
  async function (ctx, next) {
    ctx.value += 2
    await next()
    ctx.value += 3
  }
]);

const context = { value: '' }
app(context).then(() => console.log(context.value)) // --> '1234'

All composed functions are also valid middleware functions.

const superApp = compose(
  async function (ctx, next) {
    ctx.value += 'first'
    await next()
    ctx.value += 'last'
  },
  app
)

Package Sidebar

Install

npm i app-builder

Weekly Downloads

4,985

Version

7.0.4

License

MIT

Unpacked Size

18.3 kB

Total Files

14

Last publish

Collaborators

  • calebboyd