Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for complex sagas asynchronously initializing the store state at server-side #438

Open
wants to merge 6 commits into
base: 7.x
Choose a base branch
from

Conversation

jurca
Copy link

@jurca jurca commented Dec 7, 2021

The current usage example does not correctly handle some cases of sagas initializing the store. If saga A is waiting for the result of an asynchronous operation done by saga B, with the result dispatched as a redux action, saga A would never receive the result-carrying action because the END action is dispatched too soon in such a case. (This pattern enables multiple sagas to receive the result of A while having to execute A only once).

This PR handles such use cases by introducing a saga monitor that observes saga activity and reports once every saga has either terminated or is waiting for a redux action (this is an assumption that the saga at hand awaits a user action that would dispatch the expected action, and can be terminated using the END action).

This saga monitor factory can be used to use complex redux sagas
dependant on redux actions dispatched by each other for redux store
state initialization at the server.

The initialization is deemed completed once every saga is either
terminated or waiting on a redux action.
This fixes compatibility with init saga that wait for another init
saga's outcome being provided through a redux action - this is useful if
there are multiple consumers of the outcome of a single saga.
@jurca
Copy link
Author

jurca commented May 6, 2022

@kirill-konshin Would you mind taking a look at this pull request, please?

@tannguyenthanhreiq
Copy link

This solution may resolve this bug #515
I'd be glad if I could dispatch End in getStaticProps, and Saga A still receives results from Saga B, Saga C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants