Skip to content

Instantly share code, notes, and snippets.

@domachine
Last active November 2, 2015 10:14
Show Gist options
  • Select an option

  • Save domachine/c8703a26c97a480824c7 to your computer and use it in GitHub Desktop.

Select an option

Save domachine/c8703a26c97a480824c7 to your computer and use it in GitHub Desktop.
A simple hash-router in a functional reactive manner. Implemented in highland.
// 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