redux-resource icon indicating copy to clipboard operation
redux-resource copied to clipboard

Add missing requestKey in example

Open obedcorrales opened this issue 5 years ago • 1 comments

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.

obedcorrales avatar Oct 29 '20 00:10 obedcorrales

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?

  • The typo you noticed with from being typed as fom (good eye!)
  • The request shorthand to set both the key and name is deprecated, so it shouldn't appear in any of the examples.
  • A second typo..."deprecated" being spelled as "dreprecated" in the above link 🙈

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!

jamesplease avatar Oct 29 '20 16:10 jamesplease