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.

[Question] How to organize complex scenarios

See original GitHub issue

How would you organize complex scenarios involving multiple async stuff and multiple action types?

With redux-saga its superb easy once one gets comfortable with generators and with redux-observable for a skillful observable user it should be quite easy too (although didnt use the latter personally).

Wondering how to orchestrating smth more complex would look like with the proposed approach of those self-contained descriptive actions in redux-pack.

Would be cool if such example be in the docs.

Nice lib nonetheless!

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sorodrigocommented, Jan 14, 2019

@divyanshutomar

Thanks for the wonderful library.It really helps in writing more maintainable code. So I am stuck in a situation where I need to dispatch two actions one after another wherein a part (id of the newly created entity) of the response from first API call (POST request) is used as request data for the second API call (Another POST request that uses the retrieved id ). How do you deal with such scenarios?

I think maybe a good solution is to chain the promises given that this is a transaction one thing shouldn’t update the state without the other. So this could be done in the following way:

const getFooAndThenGetBar = async () => {
  const foo = await API.getFoo();
  const bar = await API.getBar();
  return { foo, bar };
}

export const doSomething = () => ({
  type: FOO_AND_BAR,
  promise: getFooAndThenGetBar(),
})

Then you can actually listen for FOO_AND_BAR in the 2 reducers that interest you.

0reactions
morgs32commented, Sep 10, 2018

@lelandrichardson it would seem to me that your comment is more than an escape hatch. It makes the onSuccess and onFailure callbacks redundant. More importantly it is easier to test than those callbacks. Do you agree? Is there anything else to consider before I implement the “escape hatch” everywhere in my app?

Thanks for this library by the way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Answers to “How Do You Stay Organized?” (4 Examples)
Answer structure: Start with the “how” and then share an example if possible ... I recommend you begin your answer by describing the...
Read more >
Interview Question: "How Do You Stay Organized?" - Indeed
1. Describe what works for you · 2. Explain your time management strategies · 3. Demonstrate your level of organization · 4. Give...
Read more >
Interview Question: “How Do You Organize a Complex ...
Break the job into chunks. The most complex tasks can be readily handled if you break them up into logical steps and attack...
Read more >
8 Tips to Answer “How Do You Stay Organized?” - The Muse
8 Tips to Answer “How Do You Stay Organized?” · 1. Reassure Your Interviewer · 2. Describe Your System—and Be Specific · 3....
Read more >
Give an Example of How You Explained a Complex Situation
How to answer “Tell me about a time you created a goal and achieved it” (with examples). Star Method. Organizing your answer is...
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