Fix prettier

This commit is contained in:
Kostya Struga 2022-07-12 13:43:10 +03:00
parent 7fe1537e1f
commit a0f760d4d9
5 changed files with 112 additions and 107 deletions

View File

@ -10,3 +10,4 @@ src/app/**/gen-model
.vscode .vscode
.swagger-codegen .swagger-codegen
*.svg *.svg
.angular

View File

@ -1,9 +1,11 @@
import { EMPTY, Observable, timer } from 'rxjs'; import { EMPTY, Observable, timer } from 'rxjs';
import { debounce, distinctUntilChanged } from 'rxjs/operators'; import { debounce, distinctUntilChanged } from 'rxjs/operators';
export const booleanDebounceTime = (timeoutMs: number = 500) => (s: Observable<boolean>): Observable<boolean> => export const booleanDebounceTime =
s.pipe( (timeoutMs: number = 500) =>
distinctUntilChanged(), (s: Observable<boolean>): Observable<boolean> =>
debounce((v) => (v ? timer(timeoutMs) : EMPTY)), s.pipe(
distinctUntilChanged() distinctUntilChanged(),
); debounce((v) => (v ? timer(timeoutMs) : EMPTY)),
distinctUntilChanged()
);

View File

@ -3,35 +3,37 @@ import { Observable, of, Subscriber, Subscription, timer } from 'rxjs';
const emitWithDelay = (ms: number, observer: Subscriber<boolean>): Subscription => const emitWithDelay = (ms: number, observer: Subscriber<boolean>): Subscription =>
timer(ms).subscribe(() => observer.next(true)); timer(ms).subscribe(() => observer.next(true));
export const booleanDelay = (ms: number = 500, emitTrigger: Observable<any> = of(true)) => <T>(source: Observable<T>) => export const booleanDelay =
new Observable<boolean>((observer) => { (ms: number = 500, emitTrigger: Observable<any> = of(true)) =>
let emitterSub = Subscription.EMPTY; <T>(source: Observable<T>) =>
const triggerSub = emitTrigger.subscribe(() => { new Observable<boolean>((observer) => {
emitterSub.unsubscribe(); let emitterSub = Subscription.EMPTY;
emitterSub = emitWithDelay(ms, observer); const triggerSub = emitTrigger.subscribe(() => {
emitterSub.unsubscribe();
emitterSub = emitWithDelay(ms, observer);
});
const sourceSub = source.subscribe({
next() {
emitterSub.unsubscribe();
observer.next(false);
},
error(err) {
triggerSub.unsubscribe();
emitterSub.unsubscribe();
observer.next(false);
observer.error(err);
},
complete() {
triggerSub.unsubscribe();
emitterSub.unsubscribe();
observer.complete();
},
});
return {
unsubscribe() {
triggerSub.unsubscribe();
emitterSub.unsubscribe();
sourceSub.unsubscribe();
},
};
}); });
const sourceSub = source.subscribe({
next() {
emitterSub.unsubscribe();
observer.next(false);
},
error(err) {
triggerSub.unsubscribe();
emitterSub.unsubscribe();
observer.next(false);
observer.error(err);
},
complete() {
triggerSub.unsubscribe();
emitterSub.unsubscribe();
observer.complete();
},
});
return {
unsubscribe() {
triggerSub.unsubscribe();
emitterSub.unsubscribe();
sourceSub.unsubscribe();
},
};
});

View File

@ -5,39 +5,39 @@ import { FetchAction } from '../fetch-action';
import { FetchFnContinuation } from '../fetch-fn-continuation'; import { FetchFnContinuation } from '../fetch-fn-continuation';
import { FetchResultContinuation } from '../fetch-result-continuation'; import { FetchResultContinuation } from '../fetch-result-continuation';
export const handleFetchResultError = <R>(result: R[] = [], continuationId?: string) => ( export const handleFetchResultError =
s: Observable<FetchResultContinuation<R>> <R>(result: R[] = [], continuationId?: string) =>
): Observable<FetchResultContinuation<R>> => (s: Observable<FetchResultContinuation<R>>): Observable<FetchResultContinuation<R>> =>
s.pipe( s.pipe(
catchError(() => catchError(() =>
of<FetchResultContinuation<R>>({ of<FetchResultContinuation<R>>({
result, result,
continuationId, continuationId,
}) })
) )
); );
export const scanFetchResultContinuation = <P, R>(fn: FetchFnContinuation<P, R>) => ( export const scanFetchResultContinuation =
s: Observable<FetchAction<P>> <P, R>(fn: FetchFnContinuation<P, R>) =>
): Observable<FetchResultContinuation<R>> => (s: Observable<FetchAction<P>>): Observable<FetchResultContinuation<R>> =>
s.pipe( s.pipe(
mergeScan<FetchAction<P>, FetchResultContinuation<R>>( mergeScan<FetchAction<P>, FetchResultContinuation<R>>(
({ result, continuationId }, { type, value }) => { ({ result, continuationId }, { type, value }) => {
switch (type) { switch (type) {
case 'search': case 'search':
return fn(value).pipe(first(), handleFetchResultError()); return fn(value).pipe(first(), handleFetchResultError());
case 'fetchMore': case 'fetchMore':
return fn(value, continuationId).pipe( return fn(value, continuationId).pipe(
first(), first(),
map((r) => ({ map((r) => ({
result: result.concat(r.result), result: result.concat(r.result),
continuationId: r.continuationId, continuationId: r.continuationId,
})), })),
handleFetchResultError(result, continuationId) handleFetchResultError(result, continuationId)
); );
} }
}, },
{ result: [] }, { result: [] },
1 1
) )
); );

View File

@ -5,39 +5,39 @@ import { FetchAction } from '../fetch-action';
import { FetchFn } from '../fetch-fn'; import { FetchFn } from '../fetch-fn';
import { FetchResult } from '../fetch-result'; import { FetchResult } from '../fetch-result';
export const handleFetchResultError = <R>(result: R[] = [], count?: number) => ( export const handleFetchResultError =
s: Observable<FetchResult<R>> <R>(result: R[] = [], count?: number) =>
): Observable<FetchResult<R>> => (s: Observable<FetchResult<R>>): Observable<FetchResult<R>> =>
s.pipe( s.pipe(
catchError(() => catchError(() =>
of<FetchResult<R>>({ of<FetchResult<R>>({
result, result,
count, count,
}) })
) )
); );
export const scanFetchResult = <P, R>(fn: FetchFn<P, R>) => ( export const scanFetchResult =
s: Observable<FetchAction<P>> <P, R>(fn: FetchFn<P, R>) =>
): Observable<FetchResult<R>> => (s: Observable<FetchAction<P>>): Observable<FetchResult<R>> =>
s.pipe( s.pipe(
mergeScan<FetchAction<P>, FetchResult<R>>( mergeScan<FetchAction<P>, FetchResult<R>>(
({ result, count }, { type, value }) => { ({ result, count }, { type, value }) => {
switch (type) { switch (type) {
case 'search': case 'search':
return fn(value).pipe(first(), handleFetchResultError()); return fn(value).pipe(first(), handleFetchResultError());
case 'fetchMore': case 'fetchMore':
return fn(value, (result[result.length - 1] as any).id).pipe( return fn(value, (result[result.length - 1] as any).id).pipe(
first(), first(),
map((r) => ({ map((r) => ({
result: result.concat(r.result), result: result.concat(r.result),
count: r.count, count: r.count,
})), })),
handleFetchResultError(result, count) handleFetchResultError(result, count)
); );
} }
}, },
{ result: [] }, { result: [] },
1 1
) )
); );