Skip to content

Possible to use transitionTo() outside of the mixin in 0.8.0? #346

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

Closed
scottwoodall opened this issue Oct 4, 2014 · 3 comments
Closed

Possible to use transitionTo() outside of the mixin in 0.8.0? #346

scottwoodall opened this issue Oct 4, 2014 · 3 comments

Comments

@scottwoodall
Copy link

For starters amazing library and my thanks goes out to you and all the other contributors. My application uses Fluxxor and there are actions that get dispatched which make async calls see here for details to the server.

Depending on the http status code returned I may need to transition to an error page:

var errorCallback = function (payload, response) {
    this.dispatch(constants.AJAX_WAITING, false);

    switch(response.status) {
        case 400:
            var errors = response.responseJSON;
            this.dispatch(constants.COLLECTION_ERROR, errors);
            break;
        case 403:
            Router.transitionTo(constants.FORBIDDEN);
        case 500:
            Router.transitionTo(constants.SERVER_ERROR);
            break;
    }
};

After reading the 0.8.0 docs I'm not seeing how I can initiate transitions like in 0.7.0 because I have to use the Transitions mixin. Am I missing something in the docs, should I re-structure my application, or perhaps this is a valid use case that needs to be re-evaluated?

@scottwoodall scottwoodall changed the title Possible to use transitionTo outside of the mixin? Possible to use transitionTo outside of the mixin in 0.8.0? Oct 4, 2014
@scottwoodall scottwoodall changed the title Possible to use transitionTo outside of the mixin in 0.8.0? Possible to use transitionTo() outside of the mixin in 0.8.0? Oct 4, 2014
@scottwoodall scottwoodall reopened this Oct 4, 2014
@ryanflorence
Copy link
Member

Weird, I replied to this an hour ago but its gone ... well, here goes again :)

We can't have singletons anywhere anymore for server-side rendering. All of these transitions and links and such need to be tied to a context. You have three options:

  1. Pass your component into the action payload, call transitionTo on that.

  2. Fire a server action with an error payload in errorCallback, have the component subscribe to that store, and then call transitionTo in the component.

  3. Export your rendered routes component instance for other modules to require, and then they can call transitionTo on it.

    var appRouter = Router.renderComponent(<Routes>...</Routes>, el);
    module.exports = appRouter;
    // in another module
    var appRouter = require('../appRouter');
    appRouter.transitionTo()

@scottwoodall
Copy link
Author

I'll implement one of your solutions. Thank you for the quick response!

@ryanflorence
Copy link
Member

I like #2 in a flux environment

@lock lock bot locked as resolved and limited conversation to collaborators Jan 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants