geosolutions-it / MapStore2

The solution to create and share maps, dashboards, geostories with 3D support on the web. And it is open-source too!
https://mapstore.geosolutionsgroup.com/
Other
509 stars 395 forks source link

Choose a side-effect library for MapStore #1420

Closed offtherailz closed 7 years ago

offtherailz commented 7 years ago

Motivation

We have complex async operations and side-effects, that are very difficult to be realized in thunk. In addition we want to trigger some side effects, and the way we did it (with componentReceiveProps) is hard to understand, maintain, and also an anti-pattern.

Lens

We want :

Candidates

Candidates are:

both of them have a middleware to integrate in redux, that catch actions and can produce other actions.

redux-observable

redux-observable realizes it using epics. Epics are functions that get and return observables (see rxjs ). This observable (that are streams ) receive actions and produce actions. The saga defines the stream to create composing, merging, forking and producing actions from the original events. Look like a lodash for async.

redux-sagas

Uses ES6 generator functions to represent the sequences of async calls. You may think to them like infinite loop (and without using helper they are while(true) loops) threads listening to the actions produced by redux.

Comparison

I developed the same functionality (text search with multiple services, with some hard-codings) in mapstore 2 to put them on test: redux-observable redux-saga

Usage

redux-saga is the most used (see this redux-saga is 6 months old, while saga is out born 1 year and a half ago, and side effect management was a must for not trivial projects. This explains why it is so used.

BoilerPlate Code

The boilerplate code is very similar. with the following differences:

Learning Curve

Problem Solving

(Solving common problems like throttling, de-bouncing, multiple parallel requests and cancellation)

Coding speed

Code clean

Testing

Size of the libs

Rxjs is a big sized library. We should be able to reduce it including only the needed functionalities :

redux-observable: 7.57 KB (0.0501%)
rxjs: 640.88 KB (4.24%)

while sagas is lighter:

redux-saga: 65.58 KB (0.451%)
babel-polyfill: 1001 B (0.00673%)

Performances

Rxjs 4 had good performances (with good hardware and without node at scale). Rxjs5 improved performances first with results like the following source :

redux-saga: didn't found any information about performances tests, some issues solved.

Summary

Sagas Epics Notes
Usage X x* * rxjs is used widely
Boiler Plate X X
Learning Curve X X
Problem Solving X
Coding Speed X X
Code Clean x* X * most of the problems are hidden
Testing x* X * I think is not useful testing sagas the way they test
Size of the libs X
Performances X X
MV88 commented 7 years ago

After the brain washing made by @offtherailz I would vote for Observable