firefox-devtools / debugger

The faster and smarter Debugger for Firefox DevTools πŸ”₯πŸ¦ŠπŸ› 
https://firefox-dev.tools/
4.61k stars 758 forks source link

RFC: Introducing Sagas #3372

Closed codehag closed 7 years ago

codehag commented 7 years ago

We are going in a really excellent direction with our refactorings. One topic that came up during our work week was sagas. I did a little bit of drawing regarding how this would look from an architectural perspective:

screen shot 2017-07-19 at 1 50 24 pm

A comparison of the two approaches:

Thunks:

Thunks are a promise based way of wrapping our dispatch action to handle asynchronous data. This is well suited when we have a simple asynchronous query. Simple here being defined as one responder, and at most one data change.

Pros:

Cons:

Sagas:

Sagas rely on generators and sit between dispatched actions and the reducers they influence. They respond to actions and take care of multi-step data processing / server communicaton. This is best suited for distributed / long life transactions.

Pros:

cons:

Reading Material:

I still have a bit of thinking to do about this but am interested what others have on their minds!

kwonoj commented 7 years ago

Just throwing out question, feel freely ignore / discard πŸ™ - has epics been considered as a candidate as well? (https://github.com/redux-observable/redux-observable/blob/master/docs/basics/Epics.md#epics)

markerikson commented 7 years ago

Hey, I recognize those first two links! :) Nice diagrams too, btw.

Not sure I have specific feedback to offer, beyond agreeing that sagas (and the equivalents from redux-observable / redux-logic ) are definitely great tools for setting up complex async workflows and decoupling parts of an app architecture.

You might also want to glance through some of the articles in the "Redux Architecture" section of my list, especially the "Variations" section - there's a few articles there that discuss interesting uses of sagas.

If there's any potential questions I can help answer, please let me know!

jasonLaster commented 7 years ago

Closing this issue as we're currently working on refactoring our redux thunk actions and will continue evaluating sagas as we go.

Thanks for all the input!