import { IObservableCache, isObservableCache } from '../IObservableCache'; import { map } from 'rxjs/operators'; import { Observable, OperatorFunction } from 'rxjs'; import { IChangeSet } from '../IChangeSet'; import { watch } from './watch'; /** * Watches updates for a single value matching the specified key * @typeparam TObject The type of the object. * @typeparam TKey The type of the key. * @param cache The cache. * @param key The key. */ export function watchValue(cache: IObservableCache, key: TKey): Observable; /** * Watches updates for a single value matching the specified key * @typeparam TObject The type of the object. * @typeparam TKey The type of the key. * @param key The key. */ export function watchValue(key: TKey): OperatorFunction, TObject>; export function watchValue(cache: IObservableCache | TKey, key?: TKey) { if (isObservableCache(cache)) { return cache.watch(key!).pipe(map(z => z.current)); } else { key = cache; return function watchValueOperator(source: Observable>) { return source.pipe( watch(key), map(z => z.current), ); }; } }