Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

walk: add #45

Merged
merged 1 commit into from
Aug 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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