Skip to content

Conversation

edsioufi
Copy link

It is a common pattern that after dispatching a request, we set an isFetching flag in the reducer. This flag is used in the bailout function to prevent sending the same request before receiving a reply from the server.

With the current implementation, payload and meta attributes can be promises / async functions that construct the attributes. This means that the REQUEST action has to wait for these to return before dispatching. During this time, other API call actions might be dispatched, and these would check for the bailout flag before anyREQUEST is fired and before the bailout flag is set in the state. This results in multiple calls at the same time and make the bailout function not very useful.

This fix dispatches REQUEST actions with non-async payload and meta attributes synchronously, guaranteeing that the flag is set in the reducer before any other action is dispatched.

@edsioufi
Copy link
Author

This addresses #94

@coveralls
Copy link

coveralls commented Jul 27, 2016

Coverage Status

Coverage decreased (-0.6%) to 99.387% when pulling 8ad0314 on siouf:handle_sync_requests into e72ac27 on agraboso:master.

@nason
Copy link
Collaborator

nason commented Sep 21, 2017

Hi @SIOUF, thanks for this and sorry its taken so long to get to 😿

Cool solution! master is currently the 1.0 branch, and we're working on 2.0 in next.

To get this in, we'd need to target this change to the next branch and add some tests around this behavior. Do you still want to help? I might be able to work on this in a couple days otherwise.

@artemtsushko
Copy link

Hi @nason! I've migrated @SIOUF 's fix to version 2.0 and added some tests around this behavior. Could you please have a look at #165?

@nason
Copy link
Collaborator

nason commented Jan 24, 2018

This change was merged in #165 👏

@nason nason closed this Jan 24, 2018
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

Successfully merging this pull request may close these issues.

4 participants