Skip to content

Instantly share code, notes, and snippets.

@bgotink
Last active November 27, 2018 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgotink/dfb9736f2ca1c7cfb7bac98e6506dfb0 to your computer and use it in GitHub Desktop.
Save bgotink/dfb9736f2ca1c7cfb7bac98e6506dfb0 to your computer and use it in GitHub Desktop.
Track all observable subscriptions

Exmaple usage:

  • Add this piece of code in your angular application's main.ts, above the bootstrap call
  • Execute subscriptions.clear() in the console, because a lot of subscriptions are created at bootstrap time
  • Trigger the actions you want to investigate
  • Copy the subscriptions map to prevent changes while you're investigating
  • Investigate
import {Observable, Subscription} from 'rxjs';
declare const subscriptions: Map<Observable<any>, Subscription[]>;
(window as any).subscriptions = new Map<Observable<any>, Subscription[]>();
Observable.prototype.subscribe = (function (_super) {
return function(this: Observable<any>, ...args: any[]) {
const subscription = _super.apply(this, args)
const list = subscriptions.get(this);
if (list != null) {
list.push(subscription);
} else {
subscriptions.set(this, [subscription]);
}
return subscription;
};
})(Observable.prototype.subscribe);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment