bugfix: pass along all actions to next middleware in chain #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here it is at last, the fix for #4! Thanks again for giving me the nudge @c-h-, this has been in the back of my mind to finish up for so long.
There were actually two bugs/exceptions to the general middleware pattern going on before:
next
instead of being dispatched as a new action, so it was only passing through the following links in the middleware chain rather than all of them; this had the potential to be a very large bug for anyone trying to dispatch some kind of a fetch request (or anything needing to be picked up by a middleware at the top of the chain) via the Worker's response.I had to access the
dispatch
from thestore
at the top level of the layers of function currying in order to fix the second issue, so I added some testing around that as well, naturally. This resulted in problems with thesetTimeout(fn, 0)
strategy being used in the Worker polyfill, so I've updated the polyfill strategy a bit in a way that I believe makes sense, and I had to usesetTimeout
in some of the tests. (Alternatively mock timers could be used in the tests, but I don't thinkexpect
has that functionality? I'm more accustomed to working with Chai + Sinon myself.) The tests and modifications to the polyfill are probably where I'd spend the most time reviewing, to make sure I didn't miss anything!Probably not necessary, but just to illustrate how these changes had an effect on an existing app. Here is the redux-logger operating after the worker middleware in the chain using the current version of redux-worker-middleware (without my fixes):
![screenshot 2017-02-15 16 35 41](https://cloud.githubusercontent.com/assets/1588547/23001977/09efe3fe-f39d-11e6-8096-dcae9b164463.png)
Note here that there are no
DATA_PROCESS_REQUEST
actions logged (those are the ones with the Workermeta
properties that get dropped from the chain). TheDATA_PROCESS_SUCCESS
are the actions returned by the Worker.Now here is the same fetch and data processing sequence when I locally
npm link
my clone of the redux-worker-middleware with the fixes:Observe that we have two
FETCH_DATA_SUCCESS
, which each trigger aDATA_PROCESS_REQUEST
(the action with Workermeta
properties, which now we see logged instead of dropped), and also theDATA_PROCESS_SUCCESS
are still there (though now fromdispatch
to the top of the middlewares chain rather than just going through the remainder of the chain withnext
).(Ignore all the
FETCH_DATA_SPAN
andINITIALIZE_DOMAIN
stuff intervening in there...those requests were slower in the first screenshot because the server hadn't cached them yet...😛 Also the dispatching of the Worker-generated result action to the top of the chain may be changing the sequence of things happening/getting logged. There's a lot of async data fetching and processing going on in this app.)