Looking to develop a method named
isEmpty:Observable<boolean>
that generates a hot Observable<boolean>
by employing a switchMap
. Here's what I have so far:
/**
* Notifies observers when the store is empty.
*/
protected notifyOnEmpty = new ReplaySubject<E[]>(1);
/**
* Check if the store is empty.
*
* @return A hot {@link Observable<boolean>} indicating the status of the store (empty or not).
*
* @example
<pre>
source.isEmpty();
</pre>
*/
isEmpty<E>():Observable<boolean> {
const isCurrentlyEmpty = values(this.entries).length == 0;
return this.notifyOnEmpty.pipe(startWith(isCurrentlyEmpty),
switchMap((entries:E[])=>entries.length == 0));
}
The idea is that the store can use
notifyOnEmpty.next(Object.values(this.entries))
to inform subscribers about whether the store is empty.
However, I encounter an error with the switchMap statement:
[ts] Argument of type '(entries: E[]) => boolean' is not assignable to parameter of type '(value: E[], index: number) => ObservableInput'. Type 'boolean' is not assignable to type 'ObservableInput'. (parameter) entries: E[]
Any suggestions?