Skip to content

Commit

Permalink
refactor(log): Log only one subscription.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Aug 8, 2017
1 parent ec47f4c commit 38d792c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
10 changes: 6 additions & 4 deletions source/plugin/log-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class LogPlugin extends BasePlugin {
): void {

const { logger_, match_, snapshotPlugin_ } = this;
const { observable, subscriber } = ref;
const { observable, subscriber, subscription } = ref;

if (matches(observable, match_)) {
const tag = read(observable);
Expand Down Expand Up @@ -89,11 +89,13 @@ export class LogPlugin extends BasePlugin {
}

const { subscriptions } = subscriberSnapshot;
logger_.groupCollapsed(`${subscriptions.length} subscription(s)`);
logger_.groupCollapsed("Subscription");
subscriptions.forEach((subscriptionSnapshot) => {

const { finalDestination, stackTrace } = subscriptionSnapshot;
logger_.log("subscribe", finalDestination ? finalDestination.stackTrace : stackTrace);
if (subscriptionSnapshot.subscription === subscription) {
const { finalDestination, stackTrace } = subscriptionSnapshot;
logger_.log("Root subscribe", finalDestination ? finalDestination.stackTrace : stackTrace);
}
});
logger_.groupEnd();
logger_.groupEnd();
Expand Down
3 changes: 3 additions & 0 deletions source/plugin/snapshot-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { Observable } from "rxjs/Observable";
import { Subscriber } from "rxjs/Subscriber";
import { Subscription } from "rxjs/Subscription";
import { get, getSync, StackFrame } from "stacktrace-js";
import { read } from "../match";
import { BasePlugin, Notification, SubscriptionRef } from "./plugin";
Expand Down Expand Up @@ -41,6 +42,7 @@ export interface SubscriptionSnapshot {
destination: SubscriptionSnapshot | null;
finalDestination: SubscriptionSnapshot | null;
stackTrace: StackFrame[];
subscription: Subscription | null;
timestamp: number;
}

Expand Down Expand Up @@ -379,6 +381,7 @@ export class SnapshotPlugin extends BasePlugin {
destination : null,
finalDestination: null,
stackTrace,
subscription: ref.subscription,
timestamp
});
});
Expand Down
2 changes: 1 addition & 1 deletion source/spy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export function show(match: any, partialLogger: PartialLogger = defaultLogger):
subscriptions.forEach((subscriptionSnapshot) => {

const { finalDestination, stackTrace } = subscriptionSnapshot;
logger.log("subscribe", finalDestination ? finalDestination.stackTrace : stackTrace);
logger.log("Root subscribe", finalDestination ? finalDestination.stackTrace : stackTrace);
});
logger.groupEnd();
logger.groupEnd();
Expand Down

0 comments on commit 38d792c

Please sign in to comment.