Skip to content

Commit

Permalink
Merge pull request #45 from yoshuawuyts/walk
Browse files Browse the repository at this point in the history
walk: add
  • Loading branch information
yoshuawuyts authored Aug 4, 2016
2 parents 8c426a8 + 542a431 commit 36433c3
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 189 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,29 @@ r1('/dada/child')
// => 'subrouter trix!'
```

## Walk
Sometimes it's necessary to walk the `trie` to apply transformations.
```js
const walk = require('wayfarer/walk')
const wayfarer = require('wayfarer')

const router = wayfarer()
router.on('/multiply', (x, y) => x * y)
router.on('/divide', (x, y) => x / y)

walk(router, (route, cb) => {
const y = 2
return function (params, x) {
return cb(x, y)
}
})

router('/multiply', 4)
// => 8
router('/divide', 8)
// => 4
```

## API
### router = wayfarer(default)
Initialize a router with a default route. Doesn't ignore querystrings and
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Composable trie based router",
"main": "index.js",
"scripts": {
"test": "standard && NODE_ENV=test node test",
"test-cov": "NODE_ENV=test istanbul cover test.js"
"test": "standard && NODE_ENV=test tape test/*",
"test-cov": "NODE_ENV=test istanbul cover test/*"
},
"repository": "yoshuawuyts/wayfarer",
"keywords": [
Expand Down
187 changes: 0 additions & 187 deletions test.js

This file was deleted.

Loading

0 comments on commit 36433c3

Please sign in to comment.