nope/lib/helpers/getSubject.ts
Martin Karkowski fa234b9a9b # 1.4.1
- Fixes:
    - Fixing time based issue in `ConnectivityManager` (using the now synced time for checkups)
      - `dispatchers.ConnectivityManager.ConnectivityManager`: fixing `_checkDispatcherHealth`
    - Fixing `extractUniqueValues` now it is possible to use different pathes for the `key` and `value`
      - `lib\helpers\mapMethods.ts` has been adapted
2022-10-04 08:06:03 +02:00

52 lines
1.0 KiB
TypeScript

/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
*/
import { BehaviorSubject, ReplaySubject, Subject } from "rxjs";
export interface TSubjectOptions {
/**
* Definition whether to show the current value on subscription.
*
* @author M.Karkowski
* @type {boolean}
* @memberof TSubjectOptions
*/
showCurrent?: boolean;
/**
* Definition, whether to playback the history every
* time or not.
*
* @author M.Karkowski
* @type {boolean}
* @memberof TSubjectOptions
*/
playHistory?: boolean;
}
/**
* Helper to define the correct RXJS Subject.
*
* @author M.Karkowski
* @export
* @template T
* @param {{
* useHistory?: boolean,
* playBackhistoryEveryTime?: boolean;
* }} [options={}]
* @return {*}
*/
export function getSubject<T>(
options: TSubjectOptions = {}
): Subject<T> | ReplaySubject<T> | BehaviorSubject<T> {
if (options.showCurrent) {
if (options.playHistory) {
return new ReplaySubject<T>();
}
return new BehaviorSubject<T>(undefined);
}
return new Subject<T>();
}