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

Idea: use sagas #1

Open
slorber opened this issue Mar 2, 2016 · 3 comments
Open

Idea: use sagas #1

slorber opened this issue Mar 2, 2016 · 3 comments

Comments

@slorber
Copy link
Owner

slorber commented Mar 2, 2016

Use Sagas

I think a saga can be useful to solve this part:

Business rule: if the current counter value is > 10 AND the button is active, then the counter value is incremented by 2 instead of 1.

The saga can listen for events from the counter (increments), and from the button, and from the gif component, hold some state, and then dispatch increment(1) or increment(2) based on the state hold by the saga.


In the backend world, the saga is a piece of software that permits to coordinate long running transactions (eventual consistency), and transactions across different bounded contexts (domain driven design jargon).

It is gaining popularity in frontend world by with redux-sagas from @yelouafi (even if most people only use it now only as a replacement for redux-thunks). See also

To simplify this for frontend world, imagine there is widget1 and widget2. When some button on widget1 is clicked, then it should have an effect on widget2. Instead of coupling the 2 widgets together (ie widget1 dispatch an action that targets widget2), widget1 only dispatch that its button was clicked. Then the saga listen for this button click and then update widget2 by dispaching a new event that widget2 is aware of.

The 2 widgets are now bounded contexts that can live separately. They do not need each others to be consistent and can be reused in other apps as well. The saga is the coupling point between the two widgets that coordinate them in a meaningful way for your business.

@tomkis
Copy link
Contributor

tomkis commented Mar 3, 2016

👍

@sibelius
Copy link

how do u handle if widget1 and widget2 uses the same action name ( reduxjs/redux#897) ?

@slorber
Copy link
Owner Author

slorber commented Jun 20, 2016

@sibelius yes this is a problem and Elm solves it properly. This is why initially I suggested to use 2 Elm mailboxes, one for nested actions to manage local component state, and one for flat business/unique/app-coupled actions

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

No branches or pull requests

3 participants