artalar / reatom

Reatom - the ultimate state manager
https://reatom.dev
MIT License
989 stars 104 forks source link

What is difference between reatom and other libs? #201

Closed xgrommx closed 1 year ago

xgrommx commented 4 years ago

I have some experience with reactive programming (Rx, Bacon, Flyd, etc) What is difference between join patterns with subjects from Rx? What is difference between focal? (https://github.com/grammarly/focal)

As for me better solution is reactive join patterns (I hate redux with imperative constructions)

artalar commented 4 years ago

Thanks for your question!

All reactive libraries that you describe have two few problems: 1) Stateful approach that forces you to think more about memory leaks. Reatom's atoms are stateless, just like features (example). It much more reusable: defining it once and reusing it in different contexts - stores (SSR is the main example). 2) Observables notify it children (subscribers) by a depth, that can generate glitches - it wastes performance and may spawn inconsistency... In Reatom atoms updates always by right order and has no glitches. 3) Observables do not follow ACID principles and encouraging inconsistency data when an error occurs. 4) Observables definitions are more flexible and imperative than atoms declarations. It possible to create cyclic dependencies and encouraging you to separate model (of an application or domains) definitions to different parts of code, that not much predictable. This is a controversial argument, but I have to voice it.

focal

Totaly different library about friendly reactive bindings to view (JSX-specific). Reatom is a framework-agnostic / any subscriber-agnostic state manager for efficiently calculate derived state and to give it away reactively.

artalar commented 4 years ago

@xgrommx I add the third problem after some thought

xgrommx commented 4 years ago

@artalar can u solve Dining philosophers problem in reatom via join patterns approach?

xgrommx commented 4 years ago

For example in Bacon.js exists update method. This is really correct version of join patterns in js libs about reactive programming In Rx we can emulate it https://github.com/xgrommx/react-rx-flux/blob/master/src/rx-extensions.js In most.js also we can do almost the same

artalar commented 4 years ago

@artalar can u solve Dining philosophers problem in reatom via join patterns approach?

@xgrommx do you have some implementation by Rx or whatever, that I can try rewrite to Reatom?

xgrommx commented 4 years ago

@artalar Sure, https://baconjs.github.io/api.html#join-patterns-and-baconbus

artalar commented 4 years ago

@xgrommx sorry, maybe I don't understand the task completed, but it is resolution? https://codesandbox.io/s/reatom-diningphilosophersproblem-vdvv2

I'm not familiar with Bacon API, so maybe my implementation is not fully mirroring Bacon's logic...

xgrommx commented 4 years ago

@artalar

Bacon variant

// philosopher 0 eating
// philosopher 0 thinking
// philosopher 2 eating
// philosopher 2 thinking
// philosopher 1 eating
// philosopher 1 thinking
// philosopher 0 eating
// philosopher 0 thinking
// philosopher 2 eating
// philosopher 2 thinking
// philosopher 1 eating
// philosopher 1 thinking
// philosopher 0 eating
// philosopher 0 thinking
// philosopher 2 eating
// philosopher 2 thinking
// philosopher 1 eating
// philosopher 1 thinking

Your variant

// philosopher 0 eating 
// philosopher 1 eating 
// philosopher 2 eating 
// philosopher 0 thinking 
// philosopher 0 eating 
// philosopher 1 thinking 
// philosopher 1 eating 
// philosopher 2 eating 
// philosopher 2 thinking 
// philosopher 0 thinking 
// philosopher 1 thinking 
// philosopher 2 thinking
xgrommx commented 4 years ago

@artalar this is simple example for join patterns (via when) https://codepen.io/xgrommx/pen/qdyErQ

BANOnotIT commented 1 year ago

@xgrommx are you still interested? If so please create a topic in Discussions.