Last active
November 2, 2015 10:14
-
-
Save domachine/c8703a26c97a480824c7 to your computer and use it in GitHub Desktop.
A simple hash-router in a functional reactive manner. Implemented in highland.
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
| // Example for a reactive functional router implemented in highland. | |
| var router = _.pipeline( | |
| _.map(e => (parse(e.newURL).hash || '#').slice(1)), | |
| _.map(path => routes.match(path)), | |
| _.map(m => m.fn(m.params)), | |
| // Make sure that the side-effect results are resetted. | |
| _.flatMap(m => _([ | |
| {_location: window.location.hash, _view: null} | |
| ]).concat([m])) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment