cartant / rxjs-spy

A debugging library for RxJS
https://cartant.github.io/rxjs-spy/
MIT License
702 stars 22 forks source link

Share operator does not reconnect to source observable when rxjs spy is running #37

Closed jpmitche11 closed 6 years ago

jpmitche11 commented 6 years ago

Rxjs-spy is not handling connectable observables correctly. This will impact the multicast family of operators, including share.

When a shared observable is completely unsubscribed, then resubscribed later, normally the source observable is resubscribed. When there is a spy object created, this is not working. The share operator creates an internal subject, I see that is not being unsubscribed as well.

Here is some code that demonstrates the issue. The issue is present if a spy object has been created.

const shared$ = interval(100).pipe(
  share()
);

const a = shared.subscribe(() => log('a'))
setTimeout(() => a.unsubscribe(), 200);  // a logged twice, then the interval() observable is unsubscribed

setTimeout(() => shared.subscribe(() => log('b')),  1000);    //Nothing logged. This should log b repeatedly

Here is a runnable version https://stackblitz.com/edit/rxjs-spy-share?file=index.ts

cartant commented 6 years ago

Thanks. I really appreciate the StackBlitz reproduction.

cartant commented 6 years ago

Until I find and fix the problem, there is an alternate workaround. You can hide the shared observable from the spy, like this:

import { hide } from "rxjs-spy/operators";
const shared$ = interval(100).pipe(
  share(),
  hide()
);
jpmitche11 commented 6 years ago

Confirmed hide operator works around the issue. Thanks.

cartant commented 6 years ago

This should be fixed in 7.0.3.