javascript - how do i define operators on an RX subject? -


how define operators on rx subject? want able throttle/take/debounce data stream without changing original source stream. ive tried following (broken) implementation. appreciated.

var source = rx.observable.interval(1000).take(10);  var subject = new rx.subject(); source.subscribe(subject);  var subscriber1 = subject.subscribe(     function (x) { $("#result1").append('next: ' + x + '<br>'); },     function (e) { $("#result1").append('onerror: ' + e.message); },     function () { $("#result1").append('oncompleted'); });  var modified = new rx.subject().take(2); // ... or throttle, or debounce etc  source.subscribe(modified);  var subscriber2 = modified.subscribe(     function (x) { $("#result2").append('next: ' + x + '<br>'); },     function (e) { $("#result2").append('onerror: ' + e.message); },     function () { $("#result2").append('oncompleted'); }); 

you can review what semantics of different rxjs subjects? info on subjects.

subjects observables, can use same operators act on observables. subjects observers can subscribe them sources.

what wrong in code following var modified = new rx.subject().take(2); source.subscribe(modified);

modified not subject anymore, regular observable, cannot subscribe source, can subscribe observer source.

so :

var news = new rx.subject(); source.subscribe(news);  var subscriber2 = news.take(2).subscribe(     function (x) { $("#result2").append('next: ' + x + '<br>'); },     function (e) { $("#result2").append('onerror: ' + e.message); },     function () { $("#result2").append('oncompleted'); }); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -