π Custom RxJS operators 4/7: "
#angular #rxjs #withLifecycle
Debugging RxJS code can be a challenge. Fortunately, the built-in tap operator provides a way to track lifecycle events for a stream.
operator
withLifecycle operator"#angular #rxjs #withLifecycle
Debugging RxJS code can be a challenge. Fortunately, the built-in tap operator provides a way to track lifecycle events for a stream.
operator
export function withLifecycle<T>(
streamId: string
): MonoTypeOperatorFunction<T> {
return tap({
subscribe: () => console.log(`[${streamId}]: subscribed`),
unsubscribe: () => console.log(`[${streamId}]: unsubscribed`),
finalize: () => console.log(`[${streamId}]: emitted final value`),
});
}
β€1