Keep your side-effects in the right place with redux observable
-
Upload
viliam-elischer -
Category
Engineering
-
view
93 -
download
1
Transcript of Keep your side-effects in the right place with redux observable
Because side-effects in codebase might* lead to:
development slow-downnon-determinism a.k.a. bugs hard maintenance on-boarding
1. How painful is adding new features 2. API - developer’s experience 3. Testability 4. Maintainability / Refactoring 5. Documentation
Pros / Cons
(+) Easy, simple, good for beginners
(+) Good enough for small project
(+) Documentation / part of redux
(-) Complexity grows quickly (promises, dispatches)
(-) Harder to test
(-) Business logic in action creators
(-) Custom utilities - cancelation, debounce, throttle, retry
exhaustive SO explanation on redux-thunk
#2 Effect executors
Store (state, effects) Reducers (state, action, effects)
Dispatch(action, effect) Middleware(store, executor)
Pros / Cons
(+) Easy to test*
(+) Sync action creators
(-) Hard to maintain
(-) Race conditions (setTimeout required)
(-) Action creators bloated wit SE logic
(-) Custom utilities - cancelation, debounce, throttle, retry
* based on visual opinion
#3 salsita/redux-side-effects
“What if your reducers were generators? You could yield side effects and return application state.”
Pros / Cons
(+) Declarative side effects / yield in reducer
(+) Easy to test
(+) Documentation
(-) Generators (available under flag)
(-) Custom utilities - cancelation, debounce, throttle, retry
#4 redux-saga
“The mental model is that a saga is like a separate thread in your application that's solely responsible for side effects.”
official docs
Pros / Cons
(+) Mature
(+) Easy to test
(+) Documentation
(+) Custom utilities - cancelation, debounce, throttle, retry
(o) Generators
(-) Ease of use
(-) Complexity
#4 redux-observable
“RxJS 5-based middleware for Redux. Compose and cancel async actions to create side effects and more.”
official docs
Epic
core primitive of redux-observable.
a function which takes a stream of actions and returns a stream of actions.
actions in, actions out.
Implementation
Implementation
A. Sharif
Generators and Channels in JavaScript