jamesplease / redux-resource

3kb resource management for Redux
https://redux-resource.js.org
MIT License
237 stars 28 forks source link

Add missing requestKey in example #474

Open obedcorrales opened 3 years ago

obedcorrales commented 3 years ago

When the example for getStatus is presented, it currently lacks the requestKey needed as part of the READ_RESOURCES_SUCCEEDED action. If that key is missing, that entry in the requests section will never changed status to SUCCEEDED, instead remaining in PENDING.

jamesplease commented 3 years ago

Thanks for taking the time to open this PR, @obedcorrales ! I believe this code example works as expected, but there are a few things here that should be updated, I think. I'll list those things at the end of this issue...but let's first look at why I think this example is working:

Here's a CodeSandbox showing how it works, with some comments.

tl;dr: the request attribute sets both the key and the name of the request. So this request already has a request key: search.

The arguments to getStatus are not (state, requestKey), but it is instead (state, pathToStatus). So when we call it like this:

getStatus(state, "books.requests.search.status");

we're drilling into the state object, which looks something like:

2020_10_29_Qz76r6Cl@2x

Seeing the state object like this may make the second argument, books.requests.search.status more clear. If you've ever used _.get() from Lodash, it is very similar.

So what needs to be changed?


I can make a PR to fix these things, or if you wanted to take a stab at it that'd be cool, too. Just let me know. And thanks for opening this PR!