Derive drr doesn't have delay (#1548)

This commit is contained in:
Jaco Greeff
2019-11-06 17:19:12 +01:00
committed by GitHub
parent b6b2f2beec
commit 8cc256fdcf
10 changed files with 49 additions and 35 deletions
+11 -4
View File
@@ -3,12 +3,17 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { Observable } from 'rxjs';
import { catchError, distinctUntilChanged, publishReplay, tap } from 'rxjs/operators';
import { catchError, distinctUntilChanged, publishReplay, tap, refCount } from 'rxjs/operators';
import { logger } from '@polkadot/util';
import { refCountDelay } from './refCountDelay';
type DrrResult = <T> (source$: Observable<T>) => Observable<T>;
export type DrrResult = <T> (source$: Observable<T>) => Observable<T>;
interface Options {
skipChange?: boolean;
skipTimeout?: boolean;
}
const l = logger('drr');
@@ -28,12 +33,14 @@ const NOOP = (): void => {};
*
* @ignore
*/
export const drr = (skipChange?: boolean): DrrResult => <T> (source$: Observable<T>): Observable<T> =>
export const drr = ({ skipChange, skipTimeout }: Options = {}): DrrResult => <T> (source$: Observable<T>): Observable<T> =>
source$.pipe(
catchError(ERR),
skipChange
? tap(NOOP)
: distinctUntilChanged(CMP),
publishReplay(1),
refCountDelay()
skipTimeout
? refCount()
: refCountDelay()
);