YahooArchive / fluxible-router

MOVED TO FLUXIBLE REPO
104 stars 26 forks source link

Resolve prior to rendering handler #24

Closed mmahalwy closed 9 years ago

mmahalwy commented 9 years ago

I was thinking about ui-router and it's powerful resolve feature. Curious if there is a good way to do it here.

index: {
        path: '/',
        method: 'get',
        page: 'index',
        title: 'Index.com',
        handler: require('../routes/Index')
    },

The only problem was that require('../routes/Index') is not the handler but something else (exports). Can handler take a function and return require('../routes/Index')?

For example, index would have statics:

statics: {
  resolve: {
    getUser() {
      return superagent.get('some_url').end().then((response) => {
        return response.user;
      })
    }
  }
}

Then in routes:

handler: () => {
  // Do something which i havent brainstormed yet but somehow injects to the handler...
    return require('../routes/Index')
}

I haven't figured out the best way yet though :(

mridgway commented 9 years ago

Right now it doesn't seem like this would be possible. I think if we added https://github.com/yahoo/fluxible/issues/15, you would be able to have a store handle NAVIGATE_START and execute currentRoute.handler().getUser(). Otherwise we would need to bake the concept of handlers in to the navigateAction in a very prescriptive way.