I'm currently trying to create a small project to demonstrate reactive programming using RxJS. The goal is to show my colleagues that this thing is, and it's worth exploring. I do not have a framework, so this complicates the situation.
I am going to deploy another demo of mine to use RxJS. This is not a very difficult demonstration, basically I can add any number of small forms that lead to a number calculated by a small formula, and there is a button that sums up the values of all forms.
Getting a formula that calculates inside forms is easy, but I decided that I could go further.
I want the summation operation to be performed automatically through the combined observable. The only solution I understood was something like that:
//dummy observables var s1 = Rx.Observable.Interval(100); var s2 = Rx.Observable.Interval(200); //Combine the observables var m = s1.combineLatest(s2, function(x,y){return x+y}); //Subscribe to the combined observable var sub = m.subscribe(function(x){console.log(x)}); //A new observable is created var s3 = Rx.Observable.Interval(300); //Now I need to update all my subscriptions, wich is a pain. m = m.combine(s3, function(x,y){return x+y}); sub.dispose(); sub=m.subscribe(function(x){console.log(x)});
I thought I could get another observable to notify my subscriptions, to renew myself - since knowing how all my subscribers work, the whole architecture will be useless, but it sounds like overkill for such a task, and I don't just mean a demo, I I can’t imagine that in the real world there would be “every day”, where such an architecture would do things cleaner than just observe any changes and get the calculated values “actively” from my forms. I would probably do the active retrieval and summation of values inside the module processing the forms, and the "m" observed for the outside world to subscribe to it by clicking my values into it from inside the module.
Will this be the right approach? I think yes, because they belong to my module, I should have full control over what happens to them, but I really wonder what more experienced people think about it.