aboutsummaryrefslogtreecommitdiff
path: root/node_modules/app-builder/README.md
blob: a12feab753aad7bbb5c2256882a213a209036fee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# app-builder

[![Actions Status](https://github.com/calebboyd/app-builder/workflows/app-builder-ci/badge.svg)](https://github.com/calebboyd/app-builder/actions)

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

## Install:

`npm install app-builder`

## Example

```javascript
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.

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