source: node_modules/react-redux/src/components/Context.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.5 KB
Line 
1import type { Context } from 'react'
2import { React } from '../utils/react'
3import type { Action, Store, UnknownAction } from 'redux'
4import type { Subscription } from '../utils/Subscription'
5import type { ProviderProps } from './Provider'
6
7export interface ReactReduxContextValue<
8 SS = any,
9 A extends Action<string> = UnknownAction,
10> extends Pick<ProviderProps, 'stabilityCheck' | 'identityFunctionCheck'> {
11 store: Store<SS, A>
12 subscription: Subscription
13 getServerState?: () => SS
14}
15
16const ContextKey = /* @__PURE__ */ Symbol.for(`react-redux-context`)
17const gT: {
18 [ContextKey]?: Map<
19 typeof React.createContext,
20 Context<ReactReduxContextValue | null>
21 >
22} = (
23 typeof globalThis !== 'undefined'
24 ? globalThis
25 : /* fall back to a per-module scope (pre-8.1 behaviour) if `globalThis` is not available */ {}
26) as any
27
28function getContext(): Context<ReactReduxContextValue | null> {
29 if (!React.createContext) return {} as any
30
31 const contextMap = (gT[ContextKey] ??= new Map<
32 typeof React.createContext,
33 Context<ReactReduxContextValue | null>
34 >())
35 let realContext = contextMap.get(React.createContext)
36 if (!realContext) {
37 realContext = React.createContext<ReactReduxContextValue | null>(
38 null as any,
39 )
40 if (process.env.NODE_ENV !== 'production') {
41 realContext.displayName = 'ReactRedux'
42 }
43 contextMap.set(React.createContext, realContext)
44 }
45 return realContext
46}
47
48export const ReactReduxContext = /*#__PURE__*/ getContext()
49
50export type ReactReduxContextInstance = typeof ReactReduxContext
Note: See TracBrowser for help on using the repository browser.