add shareLast operator
This commit is contained in:
parent
1df1b1ab89
commit
e1ce89e38d
@ -1,5 +1,5 @@
|
||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||
import { OperatorFunction, pipe } from 'rxjs';
|
||||
import { distinctUntilChanged, map, shareReplay } from 'rxjs/operators';
|
||||
import { MonoTypeOperatorFunction, OperatorFunction, pipe } from 'rxjs';
|
||||
|
||||
export function get<T>(predicate: (value: T, index: number) => boolean): OperatorFunction<readonly T[], T | undefined> {
|
||||
return map(entities => entities.find(predicate));
|
||||
@ -17,5 +17,9 @@ export function filterEach<T>(predicate: (value: T, index: number) => boolean):
|
||||
return map(entities => entities.filter(predicate));
|
||||
}
|
||||
|
||||
export function shareLast<T>(values = 1): MonoTypeOperatorFunction<T> {
|
||||
return shareReplay<T>({ bufferSize: values, refCount: true });
|
||||
}
|
||||
|
||||
export const toLengthValue = (entities: unknown[]): number => entities?.length ?? 0;
|
||||
export const getLength = pipe(map(toLengthValue), distinctUntilChanged());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user