Operation request which requires state information
See original GitHub issueI have run into a case quite frequently where I have an operation on a request which requires some state information before I can dispatch the request. So I run a select
-> dispatching the request. However this causes me to have to dispatch 2 different actions: first we have to dispatch the action to run the saga, then we run the saga, then we call the request action.
The downside of this with redux-act
is the user dispatches action1
but they have to watch for action2
on the store. Example:
// Call to run set feature saga
const setFeaturesAction = createAction(`set ${type}`);
const _setFeaturesAction = createAction(`set ${type} internal`, ({ map, [type]: features }) => {
return {
request: {
url: '/v2/maps/operations/',
method: 'post',
data: formatRPCCall(`set${typeCapitalized}`, {
map_id: map.id,
features,
})
},
};
}, ({ map, [type]: features }) => ({ map, features }));
// Get some stuff from state then run _setFeaturesAction.
const setFeaturesSaga = function* ({ payload }) {
const { map } = yield select(state.maps);
return yield put({ map, ...payload });
};
const reducer = requestsReducer({
actionType: getFeaturesAction,
// stuff and things...
operations: {
[_setFeaturesAction]: {},
}
}, baseReducer);
// User dispatches
function mapStateToProps(state) {
return {
data: state.data,
operation: state.operations._setFeaturesAction
};
}
function mapDispatchToProps(dispatch) {
return {
runOp: () => {
dispatch(setFeaturesAction)
}
}
}
From a user perspective its a bit awkward to know the difference between _setFeaturesAction
and setFeaturesAction
to use the store. Do you have any suggestions to improve this pattern?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
HTTP/1.1: Method Definitions
The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the ...
Read more >GOVERNMENT CODE CHAPTER 2054. INFORMATION ...
EXCEPTION: STATE LOTTERY OPERATIONS. (a) The lottery division of the Texas Lottery Commission is not subject to the planning and procurement requirements of ......
Read more >Freedom of Information Act: Learn - FOIA.gov
A request made by or on behalf of someone who seeks information for a use or purpose that furthers the commercial, trade, or...
Read more >How to Request Public Information - Texas Attorney General
Requesting public information is simple. Here's what you need to know to make a successful Public Information Act (PIA) request.
Read more >Certificate of Need State Laws
Certificate of need (CON) laws are state regulatory mechanisms for approving major capital expenditures and projects for certain health care ...
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
Closed the PR because I want to think about the problem some more. I’m going to try both your solutions this week. I’ll close this off if I like it, otherwise you can toss it in the bucket 😃
Closing, I will add some recipies before version
1
once working on docs. To sum up use eitherthunk
oronRequest
interceptor, it would be also possible to implement it on the driver level