Is not sent (pristine) indicator/flag/state
See original GitHub issueHello. Thank you for your library, it’s great!
In some cases, we need to know that the request hasn’t been sent yet at all. But getQuery
always returns the default structure:
const defaultQuery = {
data: null,
loading: false,
error: null,
};
Just checking over data
is null
won’t work as the backend may return, for example, either null
or a model (yes, that happens ¯_(ツ)_/¯).
Is there a way to extend defaultQuery
(not default data) or to understand, that the query is “pristine”?
It looks like, just adding pristine
flag to defaultQuery
should solve the issue as the default query is returned any time when there is no data for the query (it’s not initialized/sent/etc.) in requests` state.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
ROADMAP · Issue #306 · klis87/redux-requests
getRequestKey renamed to requestKey , u just pass value not callback anymore, ... Is not sent (pristine) indicator/flag/state #329.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@cluk3 In reducers there is even no
loading
prop, there is justpending
counter, which is just integer, number of current pending requests of a given type. Boolean would be indeed buggy, as for instance sequence 1stREQUEST > 2ndREQUEST > 1stRESPONSE > 2ndRESPONSE would cause 1stRESPONSE to setloading
tofalse
despite the fact there is still 2ndREQUEST pending.getQuery
transformspending
integer asloading: pending > 0
This task is to give 1 extra information, to distinguish between:
null
and I really want to know that I tried, but data was emptyThis flag wont be necessary for response.data like
empty
, or[]
, but fornull
it is as by defaultdata
isnull
if nothing was fetched or a query was reset.Regarding the attached article, I agree that booleans can be abused if you have many states, and state machines are better then, but in our case 90% people will need only
loading
flag,pristine
will be just extra flag for 10% cases. I dont want all people to doif(query.loading === 'loading'
, justif(query.loading)
Hello! Thank you for your reply.
For now, it’s resolved at the request level. An Axios interceptor runs a casting function if it’s passed in the config. It just throws a simulated not found error.
The issue is not for a particular problem. It’s very handy in many cases to have an ability to understand that the request is “pristine”. I’m glad to know there is the roadmap with the feature coming!
Looking forward to new versions. This issue can be closed. 😃