Saga = Worker + Watcher
Rxjs = Epic( Type + Operators )
Saga = Worker + Watcher
Rxjs = Epic( Type + Operators )
Demo Part (1/3)
Fetch User
Fetch User (cancelable)
Do three things in sequence
Login, Logout, Cancel (with redux)
Fetch User from /api/users/1
Saga
Fetch User from /api/users/1
Rxjs
Fetch User from /api/users/1 (cancelable)
Saga
Fetch User from /api/users/1 (cancelable)
Rxjs
Do three things in sequence
Saga
Do three things in sequence
Rxjs
Login, token, Logout, Cancel
(with redux)
Login, token, Logout, Cancel
Saga
Login, token, Logout, Cancel
Rxjs
Demo Part 2/3
Logger
Take latest request
Retry with delay (1000ms)
Error Handling
Running Tasks In Parallel
Throttling, Debouncing, Retrying
Saga
Throttling, Debouncing, Retrying
Saga
Part (3/3)
Test
Saga
Rxjs
Coding Style
- Effects as data
- (Imperative style)
Tell Program HOW to do things
Take time to reason about code
- Events as data
- (Declarative Style)
Tell Program WHAT things to do
Easy to reason about code
Function Reusability
Low
High
Test
- Unit Test(easy)
- Intergration Test(easy)
- Test might fail if the order change
- Unit Test(Very easy)
- Intergration Test(Require Mocking)
- Test will not fail(same end result)
Learn Saga
- Redux (1 day)
- Generator (1 day)
- Redux-Saga (few hours)
- Skill is not transferable
Total Learning Time:
3~5 days
Learn Rxjs
- Redux (1 day)
- Rxjs (few days)
- Functional Programming (2 days)
- Redux-Observable (1 day)
- Skill is transferable
Total Learing Time:
1~2 weeks
merge()
map()
filter()
scan()
combineLatest()
concat()
do()
more …
Visual Learning http://rxmarbles.com/
Saga = Effects as data
Rxjs = Events as data
Saga doesn't actually perform the side effects itself. Instead, the helper functions will create objects that represents the intent of side effect. Then the internal library performs it for you".
This makes testing extremely easy, without the need for mocking.
React
, Redux
, Redux-Saga
, Redux-Observable