reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.73k stars 1.17k forks source link

Extend ForkedTaskApi to include API #3314

Open ericanderson opened 1 year ago

ericanderson commented 1 year ago

Having considered porting a lot of code from saga to listeners, I've noticed that I am reaching for the same pattern which is a bit verbose in order to have deeply nested forking:

Example:

function doThingEvent(action, api) {
  const forks = [];
  await api.pause(
    api.fork((forkApi) => doAnotherThing({ api, ...forkApi }))
  );
}

When in reality, the ForkedTaskApi could just include things from the parent, like getState(), dispatch(), and fork(). Not only would this make the code easier to read api.fork(doAnotherThing)), but it would also mean the type API for both the fork and the task is the same.

markerikson commented 1 year ago

I'm not sure why we only included the miniature version of the API in fork(), tbh.

Want to try making that change?

ericanderson commented 1 year ago

Yeah can look into it next week

markerikson commented 1 year ago

Still open to having this added!