Skip to content

Trigger this.emit( 'change' ); after dispatch ends #92

@mjangda

Description

@mjangda

I'm using Fluxxor + rackt/react-router and running into the "Cannot dispatch an action (...) while another action (...) is being dispatched" error.

Here's what I'm doing:

  • A Login route/component displays a login form
  • onSubmit triggers the "login" action creator.
  • The "login" action creator interacts (async) with our API to validate the submission. When the call completes, dispatch the "LOGIN_SUCCESS" action (assume no failures for simplicity)
  • AuthStore is listening for this action and updates its data and triggers an this.emit( 'change' );
  • The Login route/component is using StoreWatchMixin( 'AuthStore' ) to listen for updates and uses react-router to transitionTo( 'dashboard' )
  • During its setup, the "dashboard" route/component triggers an action.
  • The "Cannot dispatch an action..." error is thrown.

The problem is that the emit call triggers the transition and results in the "dashboard" component set up while the dispatcher thinks that the "LOGIN_SUCCESS" action is still being fired.

Is there a way to defer the emit call to after the action dispatch is complete? Or should I be thinking of another approach to this? (I could do a setTimeout but that feels fragile.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions