git ssb

16+

Dominic / patchbay



Tree: d5d67784390b67e685e8675d95cabae952961b35

Files: d5d67784390b67e685e8675d95cabae952961b35 / router / async / router.js

789 bytesRaw
1const nest = require('depnest')
2
3exports.gives = nest('router.async.router')
4
5exports.needs = nest({
6 'router.async.normalise': 'first',
7 'router.sync.routes': 'reduce'
8})
9
10exports.create = (api) => {
11 var router = null
12
13 return nest('router.async.router', (location, cb) => {
14 if (!router) {
15 router = Router(api.router.sync.routes())
16 }
17
18 api.router.async.normalise(location, (err, normLocation) => {
19 if (err) return cb(err)
20
21 debugger
22
23 router(normLocation, cb)
24 })
25
26 // return true
27 })
28}
29
30function Router (routes) {
31 return (location, cb) => {
32 debugger
33 const route = routes.find(([validator]) => validator(location))
34 // signature of a route is [ routeValidator, routeFunction ]
35
36 if (route) cb(null, route[1](location))
37 }
38}
39
40
41

Built with git-ssb-web