Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routes as middleware: fall-through logic #4

Open
timoxley opened this issue Nov 23, 2016 · 2 comments
Open

Routes as middleware: fall-through logic #4

timoxley opened this issue Nov 23, 2016 · 2 comments

Comments

@timoxley
Copy link

timoxley commented Nov 23, 2016

It'd be neat to be able to trigger fall-through logic, middleware style.

e.g. attach a handler for /users/:userID that will validate :userID and or hydrate the user info which could be consumed in nested /users/:userID/* routes.

Express's params handler stuff is also kinda neat for centralising this kind of logic: http://expressjs.com/en/4x/api.html#app.param

Basically afaict just some way to toggle whether this is a return or a continue:

enroute/index.js

Lines 32 to 33 in 36300b8

if (typeof fn !== 'function') return fn
else return fn(params, props)

Just a thought.

@timoxley timoxley changed the title Fall-through logic Routes as middleware: fall-through logic Nov 23, 2016
@matthewmueller
Copy link
Member

matthewmueller commented Nov 23, 2016

Hey @timoxley, thanks for stopping by :-)

Would the hydration step be async or sync? I think the way that I normally approach this with the sync version is with nested routers.

Something like this:

function App (props) {
  return Route({
    '/users/:userID': (params) => UserView(Object.assign(params, props))
  }, props.url)
}

function UserView (props) {
  var url = userRoutingCondition(props)
  return Route({
    '/users/:userID/settings': () => Settings(props),
    '/users/:userID/profile': () => Profile(props)
  }, url)
}

Does that solve your use case?

@timoxley
Copy link
Author

Would the hydration step be async or sync?

Sync does makes things easier but it's not always possible.

I don't mind that nested router pattern, nice, it's similar to express's ability to mount sub Router objects. How do you think that could that work for async?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants