Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
feat: numbered "next" badges
Browse files Browse the repository at this point in the history
BREAKING CHANGE: now that "next" badges are numbered, you may need to update Jest snapshots
  • Loading branch information
ivan7237d committed Mar 6, 2021
1 parent abbdee7 commit e508b92
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"node": ">=14"
},
"dependencies": {
"antiutils": "^3.0.5"
"antiutils": "^3.1.0"
},
"devDependencies": {
"1log": "2.1.4",
Expand Down
20 changes: 11 additions & 9 deletions src/internal/observablePlugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { badgePlugin, getMessages, log } from '1log';
import { applyPipe } from 'antiutils';
import { pipe } from 'antiutils';
import { EMPTY, from, throwError, timer } from 'rxjs';
import { catchError, concatAll } from 'rxjs/operators';

Expand All @@ -15,7 +15,7 @@ test('basic usage', () => {
expect(getMessages()).toMatchInlineSnapshot(`
[create 1] +0ms [Observable]
[create 1] [subscribe 1] +0ms [Subscriber]
[create 1] [subscribe 1] [next] +500ms 0
[create 1] [subscribe 1] [next 1] +500ms 0
· [next] +0ms 0
[create 1] [subscribe 1] [complete] +0ms
· [complete] +0ms
Expand All @@ -38,25 +38,27 @@ test('basic usage', () => {
`);
});

test('multiple subscriptions', () => {
const observable = applyPipe(from([1]), log);
test('multiple subscriptions and nexts', () => {
const observable = pipe(from([1, 2]), log);
observable.subscribe();
observable.subscribe();
expect(getMessages()).toMatchInlineSnapshot(`
[create 1] +0ms [Observable]
[create 1] [subscribe 1] +0ms [Subscriber]
· [create 1] [subscribe 1] [next] +0ms 1
· [create 1] [subscribe 1] [next 1] +0ms 1
· [create 1] [subscribe 1] [next 2] +0ms 2
· [create 1] [subscribe 1] [complete] +0ms
· · [create 1] [subscribe 1] [unsubscribe] +0ms
[create 1] [subscribe 2] +0ms [Subscriber]
· [create 1] [subscribe 2] [next] +0ms 1
· [create 1] [subscribe 2] [next 1] +0ms 1
· [create 1] [subscribe 2] [next 2] +0ms 2
· [create 1] [subscribe 2] [complete] +0ms
· · [create 1] [subscribe 2] [unsubscribe] +0ms
`);
});

test('stack level', () => {
const observable = applyPipe(
const observable = pipe(
from([[1], throwError(2)]),
concatAll(),
log,
Expand All @@ -69,8 +71,8 @@ test('stack level', () => {
[create 2] +0ms [Observable]
[create 2] [subscribe 1] +0ms [Subscriber]
· [create 1] [subscribe 1] +0ms [Subscriber]
· · [create 1] [subscribe 1] [next] +0ms 1
· · · [create 2] [subscribe 1] [next] +0ms 1
· · [create 1] [subscribe 1] [next 1] +0ms 1
· · · [create 2] [subscribe 1] [next 1] +0ms 1
· · [create 1] [subscribe 1] [error] +0ms 2
· · · [create 1] [subscribe 1] [unsubscribe] +0ms
· · · [create 2] [subscribe 1] [complete] +0ms
Expand Down
24 changes: 10 additions & 14 deletions src/internal/observablePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
PluginType,
ProxyPlugin,
} from '1log';
import { applyPipe } from 'antiutils';
import { pipe } from 'antiutils';
import { Observable, Operator, Subscriber, TeardownLogic } from 'rxjs';

/**
Expand Down Expand Up @@ -45,7 +45,7 @@ class LogObservableOperator<T> implements Operator<T, T> {
subscriber,
logWithSubscribe,
);
return applyPipe(
return pipe(
() => source.subscribe(logObservableSubscriber),
includeInTimeDelta,
increaseStackLevel,
Expand All @@ -55,19 +55,19 @@ class LogObservableOperator<T> implements Operator<T, T> {
}

class LogObservableSubscriber<T> extends Subscriber<T> {
addNextBadge: (log: PluginLogger) => PluginLogger;

constructor(
destination: Subscriber<T>,
private logWithSubscribe: PluginLogger,
) {
super(destination);
this.addNextBadge = addNumberedBadge('next', logPalette.yellow);
}

protected _next = excludeFromTimeDelta((value: T) => {
this.logWithSubscribe(
[{ caption: `next`, color: logPalette.yellow }],
value,
);
applyPipe(
this.addNextBadge(this.logWithSubscribe)([], value);
pipe(
() => this.destination.next?.(value),
includeInTimeDelta,
increaseStackLevel,
Expand All @@ -77,7 +77,7 @@ class LogObservableSubscriber<T> extends Subscriber<T> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected _error = excludeFromTimeDelta((error: any) => {
this.logWithSubscribe([{ caption: `error`, color: logPalette.red }], error);
applyPipe(
pipe(
() => this.destination.error?.(error),
includeInTimeDelta,
increaseStackLevel,
Expand All @@ -86,7 +86,7 @@ class LogObservableSubscriber<T> extends Subscriber<T> {

protected _complete = excludeFromTimeDelta(() => {
this.logWithSubscribe([{ caption: `complete`, color: logPalette.orange }]);
applyPipe(
pipe(
() => this.destination.complete?.(),
includeInTimeDelta,
increaseStackLevel,
Expand All @@ -98,11 +98,7 @@ class LogObservableSubscriber<T> extends Subscriber<T> {
this.logWithSubscribe([
{ caption: `unsubscribe`, color: logPalette.purple },
]);
applyPipe(
() => super.unsubscribe(),
includeInTimeDelta,
increaseStackLevel,
)();
pipe(() => super.unsubscribe(), includeInTimeDelta, increaseStackLevel)();
}
});
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,11 @@ antiutils@^3.0.5:
resolved "https://registry.yarnpkg.com/antiutils/-/antiutils-3.0.5.tgz#6a3039fe60dd3b86f91105b4a6a651268deacd3d"
integrity sha512-axGBBdxGk1FM2UztW/81HsuWzkljUHvBmFXvG5eJlhP8vFL4j9s9Drex1xNl8Kq0JeBCIHxYziPeWlOWCaRUOA==

antiutils@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/antiutils/-/antiutils-3.1.0.tgz#2bc31913722ca9ffe22d006b1a5395294ea5013c"
integrity sha512-B0Le14U9Ho4uGVZ+hqYI/wOkdig7ee2e7A/0XK3EgikMDcb2kHiYdwBxKhp95gQftfwfJhCYVCoQjKYqXFL8og==

anymatch@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-2.0.0.tgz#bcb24b4f37934d9aa7ac17b4adaf89e7c76ef2eb"
Expand Down

0 comments on commit e508b92

Please sign in to comment.