question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Operation request which requires state information

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
megawaccommented, Jun 12, 2019

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 😃

0reactions
klis87commented, Sep 1, 2019

Closing, I will add some recipies before version 1 once working on docs. To sum up use either thunk or onRequest interceptor, it would be also possible to implement it on the driver level

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found