Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.48k stars 2.1k forks source link

Implement similar functionality as Knockout Computed (not combine latest) #1460

Open egucciar opened 7 years ago

egucciar commented 7 years ago

With knockout computed, I'm able to write extremely dynamic functionality where I do not know up front how many observable will be accessed and which ones they are.

How does computed work? Any observable accessed during the execution of the computed function will be automatically subscribed to, and whenever any observable accessed updates, the computed function we re-evaluate.

This means we can have recursive function calls that access several observable within a tree without knowing what those, calling "black box" type functions off of components where internally they can access many observables but the caller does not know what they are.. etc.

With CombineLatest, you must know which observable you want to combine. That means the same code that would be super-simple and easily achieved with knockout computed becomes more challenging and more explicit with RX. Now you must adhere to some sort of standards...

We have situations where, we have trees of observable arrays. Each node within those trees exposes some observables. We have a computed that react whenever the tree changes - when children added or removed - and knockout just automatically unsubscribes from removed children, subscribes to new children, and subscribes to the values exposed by the nodes for those children. With very little code, we're able to do a lot.

I find that since CombineLatest requires you to explicitly define the observables you want to combine, dynamically adding/removing subscriptions based on when others are updating might require a LOT more code, especially with recursive functions and dynamic adding/removal of entire tree branches.

Let me know if it is possible.