@nozbe/watermelondb
Version:
Build powerful React Native and React web apps that scale from hundreds to tens of thousands of records and remain fast
14 lines (10 loc) • 634 B
JavaScript
// @flow
import { type Observable, distinctUntilChanged } from '../__wmelonRxShim'
import publishReplayLatestWhileConnected from '../publishReplayLatestWhileConnected'
// Equivalent to observable |> distinctUntilChanged |> publishReplayLatestWhileConnected |> refCount
//
// Creates an observable that shares the connection with and replays the latest value from the underlying
// observable, and skips emissions that are the same as the previous one
export default function cacheWhileConnected<T>(source: Observable<T>): Observable<T> {
return source.pipe(distinctUntilChanged(), publishReplayLatestWhileConnected).refCount()
}