pathvars and body in store + multiple actions => weird behaviour
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- api
Research direction
Start by tracing the reducer handling multiple actions with the same reducerName, including the request-error path described in the examples. Compare how pathvars, body, and existing content are updated for successful and failed requests. Done means the intended state behavior is defined and consistently covered for actions with and without path variables.
Written by the indexing model from the issue text.
Description
This issue is related to #152, that have been merged in version 0.10.7
If several actions are bound to the same reducer (with the reducerName option), the pathvars and body will contain the latest action done on it. That might not be the expected behaviour.
Example :
const rest = reduxApi({
getUser: {
reducerName: "user"
url: "/user/:id", // return a user object
},
updateUser: {
reducerName: "user"
url: "/user/:id/update",
options: {
method: "post"
},
transformer: function(data, prevData, action) {
/* update the store content based on the data received */
}
}
});
/* ... */
dispatch(rest.actions.getUser({id:1}));
// store will contain { pathvars: {id:1}, body: {} }
dispatch(rest.actions.updateUser({ id:1 }, {
body: {message: 'hello world'}
}));
// store will contain { pathvars: {id:1}, body: {message: 'hello world'} }
The content of body is kinda weird : the store still contains the results of the first call, with the update.
It would make sense that the body stays empty.
This gets even worse with a poorly coded API, where updateUser does not contain any pathvar :
const rest = reduxApi({
getUser: {
reducerName: "user"
url: "/user/:id", // return a user object
},
updateUser: {
reducerName: "user"
url: "/user/update",
options: {
method: "post"
},
transformer: function(data, prevData, action) {
/* update the store content based on the data received */
}
}
});
/* ... */
dispatch(rest.actions.getUser({id:1}));
// store will contain { pathvars: {id:1}, body: {} }
dispatch(rest.actions.updateUser({ id:1 }, {
body: {user_id:1, message: 'hello world'}
}));
// store will contain { pathvars: {}, body: {user_id:1, message: 'hello world'} }
This can also be a problem when the request gives an error : pathvars and body will change, but not the content.
How should we handle such cases ?
- Dominant language
- JavaScript
- Stars
- 493
- Forks
- 86
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lexich/redux-api
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 15/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
All issues in lexich/redux-api
Similar issues
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100