From a0f760d4d9abb42ef94fe5b91a8eafe8977de496 Mon Sep 17 00:00:00 2001 From: Kostya Struga Date: Tue, 12 Jul 2022 13:43:10 +0300 Subject: [PATCH] Fix prettier --- .prettierignore | 1 + .../shared/operators/boolean-debounce-time.ts | 14 ++-- src/app/shared/operators/boolean-delay.ts | 64 +++++++++-------- .../scan-continuation-search-result.ts | 70 +++++++++---------- .../operators/scan-search-result.ts | 70 +++++++++---------- 5 files changed, 112 insertions(+), 107 deletions(-) diff --git a/.prettierignore b/.prettierignore index d664f4c..f4a448f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -10,3 +10,4 @@ src/app/**/gen-model .vscode .swagger-codegen *.svg +.angular diff --git a/src/app/shared/operators/boolean-debounce-time.ts b/src/app/shared/operators/boolean-debounce-time.ts index b644c15..1c4b4fa 100644 --- a/src/app/shared/operators/boolean-debounce-time.ts +++ b/src/app/shared/operators/boolean-debounce-time.ts @@ -1,9 +1,11 @@ import { EMPTY, Observable, timer } from 'rxjs'; import { debounce, distinctUntilChanged } from 'rxjs/operators'; -export const booleanDebounceTime = (timeoutMs: number = 500) => (s: Observable): Observable => - s.pipe( - distinctUntilChanged(), - debounce((v) => (v ? timer(timeoutMs) : EMPTY)), - distinctUntilChanged() - ); +export const booleanDebounceTime = + (timeoutMs: number = 500) => + (s: Observable): Observable => + s.pipe( + distinctUntilChanged(), + debounce((v) => (v ? timer(timeoutMs) : EMPTY)), + distinctUntilChanged() + ); diff --git a/src/app/shared/operators/boolean-delay.ts b/src/app/shared/operators/boolean-delay.ts index 120ca58..cd71eb3 100644 --- a/src/app/shared/operators/boolean-delay.ts +++ b/src/app/shared/operators/boolean-delay.ts @@ -3,35 +3,37 @@ import { Observable, of, Subscriber, Subscription, timer } from 'rxjs'; const emitWithDelay = (ms: number, observer: Subscriber): Subscription => timer(ms).subscribe(() => observer.next(true)); -export const booleanDelay = (ms: number = 500, emitTrigger: Observable = of(true)) => (source: Observable) => - new Observable((observer) => { - let emitterSub = Subscription.EMPTY; - const triggerSub = emitTrigger.subscribe(() => { - emitterSub.unsubscribe(); - emitterSub = emitWithDelay(ms, observer); +export const booleanDelay = + (ms: number = 500, emitTrigger: Observable = of(true)) => + (source: Observable) => + new Observable((observer) => { + let emitterSub = Subscription.EMPTY; + 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(); - }, - }; - }); diff --git a/src/app/shared/utils/partial-fetcher/operators/scan-continuation-search-result.ts b/src/app/shared/utils/partial-fetcher/operators/scan-continuation-search-result.ts index 67cd585..6950931 100644 --- a/src/app/shared/utils/partial-fetcher/operators/scan-continuation-search-result.ts +++ b/src/app/shared/utils/partial-fetcher/operators/scan-continuation-search-result.ts @@ -5,39 +5,39 @@ import { FetchAction } from '../fetch-action'; import { FetchFnContinuation } from '../fetch-fn-continuation'; import { FetchResultContinuation } from '../fetch-result-continuation'; -export const handleFetchResultError = (result: R[] = [], continuationId?: string) => ( - s: Observable> -): Observable> => - s.pipe( - catchError(() => - of>({ - result, - continuationId, - }) - ) - ); +export const handleFetchResultError = + (result: R[] = [], continuationId?: string) => + (s: Observable>): Observable> => + s.pipe( + catchError(() => + of>({ + result, + continuationId, + }) + ) + ); -export const scanFetchResultContinuation = (fn: FetchFnContinuation) => ( - s: Observable> -): Observable> => - s.pipe( - mergeScan, FetchResultContinuation>( - ({ result, continuationId }, { type, value }) => { - switch (type) { - case 'search': - return fn(value).pipe(first(), handleFetchResultError()); - case 'fetchMore': - return fn(value, continuationId).pipe( - first(), - map((r) => ({ - result: result.concat(r.result), - continuationId: r.continuationId, - })), - handleFetchResultError(result, continuationId) - ); - } - }, - { result: [] }, - 1 - ) - ); +export const scanFetchResultContinuation = + (fn: FetchFnContinuation) => + (s: Observable>): Observable> => + s.pipe( + mergeScan, FetchResultContinuation>( + ({ result, continuationId }, { type, value }) => { + switch (type) { + case 'search': + return fn(value).pipe(first(), handleFetchResultError()); + case 'fetchMore': + return fn(value, continuationId).pipe( + first(), + map((r) => ({ + result: result.concat(r.result), + continuationId: r.continuationId, + })), + handleFetchResultError(result, continuationId) + ); + } + }, + { result: [] }, + 1 + ) + ); diff --git a/src/app/shared/utils/partial-fetcher/operators/scan-search-result.ts b/src/app/shared/utils/partial-fetcher/operators/scan-search-result.ts index 52f66ae..b2d1f41 100644 --- a/src/app/shared/utils/partial-fetcher/operators/scan-search-result.ts +++ b/src/app/shared/utils/partial-fetcher/operators/scan-search-result.ts @@ -5,39 +5,39 @@ import { FetchAction } from '../fetch-action'; import { FetchFn } from '../fetch-fn'; import { FetchResult } from '../fetch-result'; -export const handleFetchResultError = (result: R[] = [], count?: number) => ( - s: Observable> -): Observable> => - s.pipe( - catchError(() => - of>({ - result, - count, - }) - ) - ); +export const handleFetchResultError = + (result: R[] = [], count?: number) => + (s: Observable>): Observable> => + s.pipe( + catchError(() => + of>({ + result, + count, + }) + ) + ); -export const scanFetchResult = (fn: FetchFn) => ( - s: Observable> -): Observable> => - s.pipe( - mergeScan, FetchResult>( - ({ result, count }, { type, value }) => { - switch (type) { - case 'search': - return fn(value).pipe(first(), handleFetchResultError()); - case 'fetchMore': - return fn(value, (result[result.length - 1] as any).id).pipe( - first(), - map((r) => ({ - result: result.concat(r.result), - count: r.count, - })), - handleFetchResultError(result, count) - ); - } - }, - { result: [] }, - 1 - ) - ); +export const scanFetchResult = + (fn: FetchFn) => + (s: Observable>): Observable> => + s.pipe( + mergeScan, FetchResult>( + ({ result, count }, { type, value }) => { + switch (type) { + case 'search': + return fn(value).pipe(first(), handleFetchResultError()); + case 'fetchMore': + return fn(value, (result[result.length - 1] as any).id).pipe( + first(), + map((r) => ({ + result: result.concat(r.result), + count: r.count, + })), + handleFetchResultError(result, count) + ); + } + }, + { result: [] }, + 1 + ) + );