import * as React from 'react' ; import { createObservableStore , SetStore } from "../../../../web/js/react/store/ObservableStore" ; import { Provider } from "polar-shared/src/util/Providers" ; interface ISnapshot { readonly value : any ; readonly exists : boolean ; } interface ICachedSnapshotStore { readonly snapshot : ISnapshot | undefined ; } interface ICachedSnapshotCallbacks { readonly set : ( snapshot : ISnapshot ) => void ; } const initialStore = { snapshot : undefined } ; interface Mutator { } function mutatorFactory < A > ( storeProvider , setStore ) { return { } ; } function useCallbacksFactory ( storeProvider , setStore , mutator ) { return React . useMemo ( ( ) => { function set ( snapshot ) { setStore ( { snapshot } ) ; } return { set } ; } , [ setStore ] ) ; } export function createCacheSnapshotStore ( ) { return createObservableStore < ICachedSnapshotStore , Mutator , ICachedSnapshotCallbacks > ( { initialValue : initialStore , mutatorFactory , callbacksFactory : useCallbacksFactory } ) ; } interface IPropsWithChildren { readonly children : JSX . Element ; } export function createCachedSnapshotProvider ( ) { const [ CachedSnapshotStoreProvider , useCachedSnapshotStore , useCachedSnapshotCallbacks ] = createCacheSnapshotStore ( ) ; return ( props ) => { return ( < CachedSnapshotStoreProvider > { props . children } < /CachedSnapshotStoreProvider>); } ; }