deno.land / x / jotai@v1.8.4 / src / core / contexts.ts
1234567891011121314151617181920212223242526272829303132333435363738import { createContext } from 'react'import type { Context } from 'react'import type { Atom } from './atom'import { createStore, createStoreForExport } from './store'import type { Store } from './store'
type Scope = symbol | string | numbertype VersionedWrite = (write: (version?: object) => void) => voidtype RetryFromError = (fn: () => void) => void
export interface ScopeContainer { s: Store w?: VersionedWrite v?: object // version object r?: RetryFromError}
export const createScopeContainer = ( initialValues?: Iterable<readonly [Atom<unknown>, unknown]>, unstable_createStore?: typeof createStoreForExport): ScopeContainer => { const store = unstable_createStore ? unstable_createStore(initialValues).SECRET_INTERNAL_store : createStore(initialValues) return { s: store }}
type ScopeContext = Context<ScopeContainer>
const ScopeContextMap = new Map<Scope | undefined, ScopeContext>()
export const getScopeContext = (scope?: Scope) => { if (!ScopeContextMap.has(scope)) { ScopeContextMap.set(scope, createContext(createScopeContainer())) } return ScopeContextMap.get(scope) as ScopeContext}
Version Info