Hacker News new | ask | show | jobs
by roucoulawan 3271 days ago
Really cool summary of the power of such libs like redux-saga.

I indeed prefer using sagas than observables, maybe because of the cool 'select', 'put' and 'call' apis that helps me to do smart hook methods. With a good combination with such normalizr lib (https://github.com/paularmstrong/normalizr), you can actually fast implement a light optimist transactions system between frontend and backend.

For instance, you can define a REQUEST_PUT_ENTITIES action, and a saga watching on it. This saga will do: - a 'call' for calling the api post method for updating the backend (ie updating all the collections through your backend database apis) - get back from the api the put data, and into the saga you then 'put' a MERGE_INTO_ENTITIES action, in order to direclty update and normalize your frontend entities app state. - once your app state is synchronised, your saga can even 'select' again these put entities thanks to their ids and you can 'put' a nice REQUEST_PUT_ENTITIES_SUCCESS action from which you can hook any kind of specific-to-the-app post-synchronized methods.

So, for me redux-saga with a bit of wrapping is like a light solution for doing what we all are searching actually in such heavy libs like Relay or react-appollo (but here I am talking for a quick solution with a 'stupid-like REST approach'...so maybe not optimized for sure)

I don't know what do you think guys...