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

27 lines (21 loc) 703 B
import {useMemoObservable} from 'react-rx' import {map} from 'rxjs/operators' import {useDocumentStore} from '../store' /** @internal */ export interface SyncState { isSyncing: boolean } const SYNCING = {isSyncing: true} const NOT_SYNCING = {isSyncing: false} /** @internal */ export function useSyncState(publishedDocId: string, documentType: string): SyncState { const documentStore = useDocumentStore() return useMemoObservable<SyncState>( () => documentStore.pair .consistencyStatus(publishedDocId, documentType) .pipe(map((isConsistent) => (isConsistent ? NOT_SYNCING : SYNCING))), [documentStore.pair, documentType, publishedDocId], NOT_SYNCING, ) }