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.

Composing actions

See original GitHub issue

With redux-thunk I can dispatch(actionA).then(() => dispatch(actionB)). For example, I have a form that I want to populate with initial values. Dispatching actionA allows me to get these initial values (by sending an async fetch). Dispatching actionB initializes the form with these values.

With sagas I can’t do the above, because dispatches don’t return promises. I have to create a new action - actionAandB - along with a new saga that combines the logic of actionA and actionB. Is there a more idiomatic way to do this instead of creating a new action, and a new saga for that action?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
slorbercommented, Jul 5, 2016

So, you are dispatching promises, because fetchNote(id) is likely to return a promise. Thus please try what I have written above and if this does not work open a feature request

1reaction
slorbercommented, Jul 5, 2016

If your dispatch function returns promise, it’s probably because you use some promise middleware.

It is possible to wait for promises in redux-saga, have you tried the following?

const actionAPromise = yield put(actionA);
const actionAResult = yield actionAPromise;
const actionBPromise = yield put(actionB);
const actionBResult = yield actionBPromise;

I’m not sure if currently the put effect does return the result of the dispatch method however but you can try that.

Also, why do you want to mix redux-saga code with promise middleware? If you start to use sagas you would tend to dispatch only synchronous actions and manage effects inside sagas directly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Actions | Vuex
Actions are often asynchronous, so how do we know when an action is done? And more importantly, how can we compose multiple actions...
Read more >
Scala Actions Composition - 2.8.x - Play Framework
While action composition allows you to perform additional processing at the HTTP request and response level, often you want to build pipelines of...
Read more >
Creating a composite action - GitHub Docs
In this guide, you'll learn how to build a composite action. Introduction. In this guide, you'll learn about the basic components needed to...
Read more >
Composing Actions - NgRx Auto-Entity - GitBook
When developing complex applications, sometimes it may help to "bundle" multiple actions together or compose many individual actions into sort of a higher ......
Read more >
Composing actions with Vuex - codeburst
Composing actions with Vuex. Introduction to implementing complex actions using Vuex, the Vue.js state management library.
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