I'm trying to extend a service function which returns an Observable<T>. The idea is to extend the function so I can add logging functionality whenever the observable emits a new value.
fromEvent<T>(eventName: string): Observable<T> {
super.fromEvent(eventName).subscribe(
function next(data) {
console.group();
console.log('----- SOCKET INBOUND -----');
console.log('Action: ', eventName);
console.log('Payload: ', data);
console.groupEnd();
}
);
return super.fromEvent(eventName);
How can I make my function more effective? Because whenever fromEvent() is invoked a subscription is created and an observable is returned from the base class. As I understand, all subscriptions should at some point be unsubscribed.
Or are there any other way you could implement a logging functionality on an observable that listens to a specific event?