Fix for concurrent action calls
If multiple actions are called to the same endpoint in rapid succession, all the callbacks are pushed onto the same pubsub object. When the first fetch returns, all of the callbacks are called with that data, and subsequent fetch returns call no callbacks. Moving the pubsub instantiation into the individual calls to the api solves this issue.
Concurrent calls for endpoint isn't permitted by design, because you can't update you store concurrent without race condition. And failing test shows it.
I see how that is supposed to stop multiple calls, but it doesn't. I have a lookahead search that passes along the string in the url to the api call. When typing fast enough, the api endpoint is called for each letter typed, and the same response is fed to all the callbacks. This causes the values to be incorrect, however the redux store ends up with the correct values. Correction, the redux store ends up with the values for whatever call returns last.
This is using react-select, with the async options callback.
In this "spam case" you should abort previous request. Now you have 2 variants. Use request method and update store. Or use reset method - but this set initialState to store. But it's point to new feature to abort previous request.
@Paxmagister I made PR. I add support abortable requests. https://github.com/lexich/redux-api/pull/143/files#diff-5a4fb2f7a580b6a02bf1dead9d25e66fR614 Might is be useful for your case. What do you think about API?
That would work for the base functionality I'm going for, thanks. But I would like to cache the results that are returned from the previous api calls, so it would actually be nice if they called the callbacks passed to them. I was thinking something like, only call dispatch to update redux if it was the last call made, but everything else still gets run, and the callbacks are registered per request.
@Paxmagister I have seen your progress and I'm not sure that you on the right way, unfortunately.
@lexich I seem to be having an issue that is related to this. so is it not possible to make multiple action calls with different parameters before the first one comes back? I need to make many calls in a row to the same endpoint but with different ids. is this not possible??
you can use pure requests request and after that aggregate this
thanks @lexich. so how can we use reducers with request? or is there a way to get concurrent gets to work as expected? I guess I don't understand the issue with updating store with concurrent calls... can we not merge prevState in with the response with something like Immutable?