Last active
December 22, 2015 06:18
-
-
Save SimonRichardson/6429554 to your computer and use it in GitHub Desktop.
Building a router using partials.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var squishy = require('squishy-pants/bin/squishy-pants.min'), | |
| log = squishy.IO(squishy.constant( | |
| function(x) { | |
| console.log(x); | |
| } | |
| )), | |
| logger = squishy.curry( | |
| function(prefix, value) { | |
| log.ap(squishy.IO.of(prefix + ' > ' + value)).unsafePerform(); | |
| } | |
| ), | |
| router = squishy.router().add( | |
| function(a) { | |
| return "/search/:query/:name"; | |
| }, | |
| function() { | |
| return 'Hello World'; | |
| } | |
| ).add( | |
| function(a) { | |
| return "/ducky" | |
| }, | |
| function(){ | |
| return 'Rubber Ducky'; | |
| } | |
| ), | |
| result = squishy.fill( | |
| 10, | |
| function(index) { | |
| return router.route(squishy.isEven(index) ? '/ducky/' : '/search/hello/world'); | |
| } | |
| ); | |
| logger('Output', result); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Even better I've implemented this via partial routing and therefore it's just built on constructs that already exist.