3 ms·
Observables are a powerful abstraction, but with great power comes great complexity (so use them only when you expect/require updates) An observable can be cre
by gitgud 7y ago
Observables are a powerful abstraction, but with great power comes great complexity (so use them only when you expect/require updates)
An observable can be created from an event and have several transformations applied to that event (see https://www.learnrxjs.io/ https://www.learnrxjs.io/). These transformations functions are powerful because they can be composed to create the observable and can also be shared and reused.
They are not "just superior in every way", they are just suited to listening and emitting events to/from various components in your system. A simple object is perfect if no events are needed.
- pezo1919 7y ago"A simple object is perfect if no events are needed." To my understanding calling an objects <any_method> can be interpreted as the object receives the message named <any_method> (with additional args). From that point of view there is nothing but messages: method calls are also messages, so that part "no events are needed" does not hold, because if methods are needed then virtually events are needed. "so use them only when you expect/require updates": To me, it turned out I always expect/require update. The only question is in what form of. Via method calls consecutive or via "explicit" events. My intuition says that using Observables won't change the problems inherent complexity in any direction. << That's the real, deep question I think. So if there are useful transformation functions to use with observables I don't know why not to use them in every case.
- gitgud 7y ago> From that point of view there is nothing but messages. Yes this is true. The observable's implemented by Rx is an interesting abstraction that can act as an emitter OR a listener of messages (events). The events emitted from an Observable can be an object with methods. However, you need to subscribe to the observable to get the object and call those methods. > To me, it turned out I always expect/require update. Yes, most systems will need to send updates around to various components in the system. Rx is a great option for these use cases. > So if there are useful transformation functions to use with Observables I don't know why not to use them in every case. The complexity of an event-driven system is why you generally shouldn't use them every where. Events inherently make things more complex and harder to debug as dependencies between components become implicit rather than an explicit function call. My advice is to use Rx to decouple parts of your system. But try to stick with the KISS principle and keep things simple to understand. [1] https://en.wikipedia.org/wiki/KISS_principle https://en.wikipedia.org/wiki/KISS_principle