cerebral-legacy / cerebral-module-router

An opinionated URL change handler for Cerebral
http://cerebral-website.herokuapp.com/documentation/cerebral-module-router
19 stars 4 forks source link

Export redirect action factory with Router #47

Closed bfitch closed 9 years ago

bfitch commented 9 years ago

I brought this up in Gitter, but thought I'd capture it here too.

With the latest release 0.6.0 removing Router.redirect, could we export a redirect action factory along with the main Router export, so users will be spared rewriting it for each application? It's my opinion that redirect is something that should be handled once in the router lib and not left up to users to reimplement. :smile:

Something like:

import {Router, redirect} from 'cerebral-router';

Implementation could be simple:

function redirect(url) {
  function action(input, state, output, services) {
    return services.router.redirect(url, {
      replace: false
    });
  }
  action.displayName = `redirect(${url})`;
  return action;
}
Guria commented 9 years ago

Did you have noticed that redirect still available as method of router exposed as a service? but it can't be imported as befote.

So redirect available as services.router.redirect() inside any action.

Still think that we need redirect action factory?

bfitch commented 9 years ago

I liked the "higher level" API of Router.redirect and the factory gets us that. Otherwise, I'd have to wrap services.router.redirect (as shown above) for each project. Won't most cererbral-router users be doing the same?