James Gillmore
Jul 24, 2017 · 1 min read

OK, it’s now on CodeSandBox and completely done:

I happened to have made a few other changes, such as simplifying the videosByCategory reducer by removing the nested category key and simply giving that its own reducer. So now videosByCategory is just a hash like videosHash. But of course a hash of arrays.

By all this, the race conditions completely vanished. One reason is now that the category is in its own reducer, it doesnt change categories based on VIDEOS_FETCHED. So it nows to stay stable based on route change.

And as for the isLoading selector, it’s also based on the route type, so by virtue of that, it will always indicate whether the latest thing is loading, and not the category you quickly clicked past.

What this also means is we are making the most out of Redux-First Router — i.e. by using state.location.type/payload directly in our selector. It’s a nice coming together of all the related concepts to solve the problem. And it’s not just incidental — basically maintaining router state in Redux saved the day. We needed the type and payload in both this selector and the new category reducer, which removed race conditions from videosByCategory.

In short, we have a very very idiomatic solution.

It’s the business logic distilled to its smallest form.

    James Gillmore

    Written by

    http://www.faceyspacey.com + http://twitter.com/faceyspacey