mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-10-24 04:25:05 +00:00
- @pezkuwi/dev, dev-test, dev-ts ^0.86.3; disable directives renamed for the new rule names, or removed where the rule no longer reports - rethrown errors carry the original as `cause` (13 sites) - optional chains where a guard expression tested the same value - Init: the registry cache settles with the creator's own promise, dropping the entry in finally(), instead of re-wrapping it - Combinator: a typed call instead of `Function` - checkTypes.manual: synchronous checks run outside Promise.all - sortValues, createTypeUnsafe: initial values that were never read - typegen util: load docs.js for its side effect (it registers the `docs` Handlebars partial) now that its types are re-exported type-only - MockProvider keeps its Header assertion: the package's own build does not load api-augment, so createType returns a plain Codec there - Decorate keeps `delete queue[i]`: the hole marks a fired queue and later indexes must not shift
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/rpc-core authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Observable } from 'rxjs';
|
|
|
|
import { catchError, distinctUntilChanged, publishReplay, refCount, tap } from 'rxjs';
|
|
|
|
import { stringify } from '@pezkuwi/util';
|
|
|
|
import { refCountDelay } from './refCountDelay.js';
|
|
|
|
export type DrrResult = <T> (source$: Observable<T>) => Observable<T>;
|
|
|
|
interface Options {
|
|
delay?: number;
|
|
skipChange?: boolean;
|
|
skipTimeout?: boolean;
|
|
}
|
|
|
|
function CMP (a: unknown, b: unknown): boolean {
|
|
return stringify({ t: a }) === stringify({ t: b });
|
|
}
|
|
|
|
function ERR (error: Error): Observable<never> {
|
|
throw error;
|
|
}
|
|
|
|
function NOOP (): void {
|
|
// empty
|
|
}
|
|
|
|
/**
|
|
* Shorthand for distinctUntilChanged(), publishReplay(1) and refCount().
|
|
*
|
|
* @ignore
|
|
* @internal
|
|
*/
|
|
export function drr ({ delay, skipChange = false, skipTimeout = false }: Options = {}): DrrResult {
|
|
return <T> (source$: Observable<T>): Observable<T> =>
|
|
source$.pipe(
|
|
catchError(ERR),
|
|
skipChange
|
|
? tap(NOOP)
|
|
: distinctUntilChanged<T>(CMP),
|
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
publishReplay(1),
|
|
skipTimeout
|
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
? refCount()
|
|
: refCountDelay(delay)
|
|
);
|
|
}
|