This kind of flies in the face of the trend to separate stores/state from the components in favor of simpler components... Also, there's no cleanup of the event registrations which will lead to memory leaks.
Perhaps you're right - but the trend doesn't necessarily account for all use cases.
Assuming the OP is only modifying the components internal state (which has no bearing on the application state), I'd be all for it.
Hey, thanks for the share. Where I haven't used Rx per se, I used Bacon extensively at my last gig.
Rx is a module, and you're merging `plus$` and `minus$` to 'Rx.Observable' - is there an issue of having these bindings persist when the React component unmounts? What would be the best practice for tidying up in `componentWillUnmount`?
Calling `subscribe` on an observable returns a subscription that can be disposed at a later time. The approach that I use is something like this: http://jsbin.com/seyetudasu/edit?js
If you are subscribing to multiple observables in a single component, you could also consider using `CompositeDisposable`, which allows you to merge multiple subscriptions into a single disposable.
Cool, thanks for the clarification.
I guess I should read a bit of the Rx API docs, but doesn't seem far off Bacon with `combineTemplate`; which from memory returns a curried function to end any streams. Someone correct me if I'm wrong.
There very much is - without having dug deeper, this doesn't look like a complete answer, but merely serves as an introduction on how to begin using it.
You should definately unregister your event listeners in componentWillUnmount. If you wanted to pursue this approach I would probably make a higher level component (or mixin) to declaretively and automatically handle the binding and unbinding of events, plus the glue to rxObservables.
RxJS provides this consideration with dispose() for many ephemeral Observables. Keep track of your subscriptions and dispose in `componentWillUnmount`.
e: better data above.
Interesting as a comparison. A couple days ago I whipped up this functional-reactive example on top of Preact (lightweight React replacement), might be of interest to people looking at this:
http://esnextb.in/?gist=ba28702c94e22d26e3bc