ReactiveX / rxjs

A reactive programming library for JavaScript
https://rxjs.dev
Apache License 2.0
30.7k stars 3k forks source link

RX-JS - do we have in RX-JS method like .spy in bacon #2142

Closed waqas7803 closed 7 years ago

waqas7803 commented 7 years ago

Is there any function in RX-JS that serve same as we have .spy in Bacon.js. https://github.com/baconjs/bacon.js/#bacon-spy

Or any other way to achieve same functionality ?

I need that to create Debugging tool for RX-JS.

Best Regards

jayphelps commented 7 years ago

Those linked docs don't fully explain what it provides, can you describe further?

We do provide a semi-private API called lift(). Every prototype-based operator uses it, which could be used as a one piece to create debugging tools (in addition to stubbing other things, if you want a fuller picture).

A demo of using lift to add operator logging can be found here in the tests.

waqas7803 commented 7 years ago

@jayphelps : Problem with overriding lift is that it only allows to log observables that is applied to some operator. Please have a look here for me detail http://stackoverflow.com/questions/40675631/rx-js-5-using-lift-to-log-observable-data-for-debugging

Thanks

waqas7803 commented 7 years ago

For RX-JS If i override lift , it becomes possible to inject behaviors into all observers in an operator chain , But how can i log RX-Observables those are not applied to any operator yet ?.

And is it proper way to log all observables to override lift and subscribe to each observables for logging data , Because do operator did not work.

This is how i am trying

const _lift = Rx.Observable.prototype.lift; var idCounter = 0; Rx.Observable.prototype.lift = function (operator) { var sourceObs = this ; sourceObs.id = ++idCounter; var resultantObservable = _lift.call(sourceObs, operator); resultantObservable.id = ++idCounter; // In this Method i log data LogObserver(operator , sourceObs , resultantObservable); return resultantObservable; }; Above code works for

var timer = Rx.Observable.interval(1000).take(4); But does not work for

var sequence = Rx.Observable.range(1, 10); Thanks in advance.

Best Regards

kwonoj commented 7 years ago

Closing as inactive. while it is interesting idea, I don't think core 5 will going to have this. Probably best way for userlevel approach is hook lift as suggested as well as hook static creations methods.

lock[bot] commented 6 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.