mirror of
https://github.com/valitydev/fraudbusters-ui.git
synced 2024-11-06 08:35:18 +00:00
Fix prettier
This commit is contained in:
parent
7fe1537e1f
commit
a0f760d4d9
@ -10,3 +10,4 @@ src/app/**/gen-model
|
||||
.vscode
|
||||
.swagger-codegen
|
||||
*.svg
|
||||
.angular
|
||||
|
@ -1,9 +1,11 @@
|
||||
import { EMPTY, Observable, timer } from 'rxjs';
|
||||
import { debounce, distinctUntilChanged } from 'rxjs/operators';
|
||||
|
||||
export const booleanDebounceTime = (timeoutMs: number = 500) => (s: Observable<boolean>): Observable<boolean> =>
|
||||
s.pipe(
|
||||
distinctUntilChanged(),
|
||||
debounce((v) => (v ? timer(timeoutMs) : EMPTY)),
|
||||
distinctUntilChanged()
|
||||
);
|
||||
export const booleanDebounceTime =
|
||||
(timeoutMs: number = 500) =>
|
||||
(s: Observable<boolean>): Observable<boolean> =>
|
||||
s.pipe(
|
||||
distinctUntilChanged(),
|
||||
debounce((v) => (v ? timer(timeoutMs) : EMPTY)),
|
||||
distinctUntilChanged()
|
||||
);
|
||||
|
@ -3,35 +3,37 @@ import { Observable, of, Subscriber, Subscription, timer } from 'rxjs';
|
||||
const emitWithDelay = (ms: number, observer: Subscriber<boolean>): Subscription =>
|
||||
timer(ms).subscribe(() => observer.next(true));
|
||||
|
||||
export const booleanDelay = (ms: number = 500, emitTrigger: Observable<any> = of(true)) => <T>(source: Observable<T>) =>
|
||||
new Observable<boolean>((observer) => {
|
||||
let emitterSub = Subscription.EMPTY;
|
||||
const triggerSub = emitTrigger.subscribe(() => {
|
||||
emitterSub.unsubscribe();
|
||||
emitterSub = emitWithDelay(ms, observer);
|
||||
export const booleanDelay =
|
||||
(ms: number = 500, emitTrigger: Observable<any> = of(true)) =>
|
||||
<T>(source: Observable<T>) =>
|
||||
new Observable<boolean>((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();
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@ -5,39 +5,39 @@ import { FetchAction } from '../fetch-action';
|
||||
import { FetchFnContinuation } from '../fetch-fn-continuation';
|
||||
import { FetchResultContinuation } from '../fetch-result-continuation';
|
||||
|
||||
export const handleFetchResultError = <R>(result: R[] = [], continuationId?: string) => (
|
||||
s: Observable<FetchResultContinuation<R>>
|
||||
): Observable<FetchResultContinuation<R>> =>
|
||||
s.pipe(
|
||||
catchError(() =>
|
||||
of<FetchResultContinuation<R>>({
|
||||
result,
|
||||
continuationId,
|
||||
})
|
||||
)
|
||||
);
|
||||
export const handleFetchResultError =
|
||||
<R>(result: R[] = [], continuationId?: string) =>
|
||||
(s: Observable<FetchResultContinuation<R>>): Observable<FetchResultContinuation<R>> =>
|
||||
s.pipe(
|
||||
catchError(() =>
|
||||
of<FetchResultContinuation<R>>({
|
||||
result,
|
||||
continuationId,
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
export const scanFetchResultContinuation = <P, R>(fn: FetchFnContinuation<P, R>) => (
|
||||
s: Observable<FetchAction<P>>
|
||||
): Observable<FetchResultContinuation<R>> =>
|
||||
s.pipe(
|
||||
mergeScan<FetchAction<P>, FetchResultContinuation<R>>(
|
||||
({ 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 =
|
||||
<P, R>(fn: FetchFnContinuation<P, R>) =>
|
||||
(s: Observable<FetchAction<P>>): Observable<FetchResultContinuation<R>> =>
|
||||
s.pipe(
|
||||
mergeScan<FetchAction<P>, FetchResultContinuation<R>>(
|
||||
({ 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
|
||||
)
|
||||
);
|
||||
|
@ -5,39 +5,39 @@ import { FetchAction } from '../fetch-action';
|
||||
import { FetchFn } from '../fetch-fn';
|
||||
import { FetchResult } from '../fetch-result';
|
||||
|
||||
export const handleFetchResultError = <R>(result: R[] = [], count?: number) => (
|
||||
s: Observable<FetchResult<R>>
|
||||
): Observable<FetchResult<R>> =>
|
||||
s.pipe(
|
||||
catchError(() =>
|
||||
of<FetchResult<R>>({
|
||||
result,
|
||||
count,
|
||||
})
|
||||
)
|
||||
);
|
||||
export const handleFetchResultError =
|
||||
<R>(result: R[] = [], count?: number) =>
|
||||
(s: Observable<FetchResult<R>>): Observable<FetchResult<R>> =>
|
||||
s.pipe(
|
||||
catchError(() =>
|
||||
of<FetchResult<R>>({
|
||||
result,
|
||||
count,
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
export const scanFetchResult = <P, R>(fn: FetchFn<P, R>) => (
|
||||
s: Observable<FetchAction<P>>
|
||||
): Observable<FetchResult<R>> =>
|
||||
s.pipe(
|
||||
mergeScan<FetchAction<P>, FetchResult<R>>(
|
||||
({ 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 =
|
||||
<P, R>(fn: FetchFn<P, R>) =>
|
||||
(s: Observable<FetchAction<P>>): Observable<FetchResult<R>> =>
|
||||
s.pipe(
|
||||
mergeScan<FetchAction<P>, FetchResult<R>>(
|
||||
({ 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
|
||||
)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user