UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

25 lines (21 loc) 751 B
import {type SanityClient} from '@sanity/client' import {Observable} from 'rxjs' import {publishReplay, refCount} from 'rxjs/operators' import {type IdPair} from '../types' import {memoize} from '../utils/createMemoizer' import {checkoutPair, type Pair} from './checkoutPair' import {memoizeKeyGen} from './memoizeKeyGen' export const memoizedPair: ( client: SanityClient, idPair: IdPair, typeName: string, ) => Observable<Pair> = memoize( (client: SanityClient, idPair: IdPair, _typeName: string): Observable<Pair> => { return new Observable<Pair>((subscriber) => { const pair = checkoutPair(client, idPair) subscriber.next(pair) return pair.complete }).pipe(publishReplay(1), refCount()) }, memoizeKeyGen, )