File tree Expand file tree Collapse file tree 6 files changed +31
-26
lines changed Expand file tree Collapse file tree 6 files changed +31
-26
lines changed Original file line number Diff line number Diff line change 66import { useSyncExternalStore } from 'use-sync-external-store/shim'
77import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'
88
9- import { setSyncFunctions } from './utils/useSyncExternalStore'
9+ import { initializeUseSelector } from './hooks/useSelector'
10+ import { initializeConnect } from './components/connect'
1011
11- setSyncFunctions ( useSyncExternalStore , useSyncExternalStoreWithSelector )
12+ initializeUseSelector ( useSyncExternalStoreWithSelector )
13+ initializeConnect ( useSyncExternalStore )
1214
1315import { getBatch } from './utils/batch'
1416
Original file line number Diff line number Diff line change 55import { useSyncExternalStore } from 'use-sync-external-store/shim'
66import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'
77
8- import { setSyncFunctions } from './utils/useSyncExternalStore'
98import { unstable_batchedUpdates as batch } from './utils/reactBatchedUpdates'
109import { setBatch } from './utils/batch'
1110
12- setSyncFunctions ( useSyncExternalStore , useSyncExternalStoreWithSelector )
11+ import { initializeUseSelector } from './hooks/useSelector'
12+ import { initializeConnect } from './components/connect'
13+
14+ initializeUseSelector ( useSyncExternalStoreWithSelector )
15+ initializeConnect ( useSyncExternalStore )
1316
1417// Enable batched updates in our subscriptions for use
1518// with standard React renderers (ReactDOM, React Native)
Original file line number Diff line number Diff line change @@ -28,7 +28,6 @@ import defaultMergePropsFactories from '../connect/mergeProps'
2828
2929import { createSubscription , Subscription } from '../utils/Subscription'
3030import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
31- import { getSyncFunctions } from '../utils/useSyncExternalStore'
3231import shallowEqual from '../utils/shallowEqual'
3332
3433import {
@@ -37,7 +36,13 @@ import {
3736 ReactReduxContextInstance ,
3837} from './Context'
3938
40- const [ useSyncExternalStore ] = getSyncFunctions ( )
39+ import type { uSES } from '../utils/useSyncExternalStore'
40+ import { notInitialized } from '../utils/useSyncExternalStore'
41+
42+ let useSyncExternalStore = notInitialized as uSES
43+ export const initializeConnect = ( fn : uSES ) => {
44+ useSyncExternalStore = fn
45+ }
4146
4247// Define some constant arrays just to avoid re-creating these
4348const EMPTY_ARRAY : [ unknown , number ] = [ null , 0 ]
Original file line number Diff line number Diff line change @@ -2,10 +2,14 @@ import { useContext, useDebugValue } from 'react'
22
33import { useReduxContext as useDefaultReduxContext } from './useReduxContext'
44import { ReactReduxContext } from '../components/Context'
5- import { getSyncFunctions } from '../utils/useSyncExternalStore'
65import type { DefaultRootState , EqualityFn } from '../types'
6+ import type { uSESWS } from '../utils/useSyncExternalStore'
7+ import { notInitialized } from '../utils/useSyncExternalStore'
78
8- const [ , useSyncExternalStoreWithSelector ] = getSyncFunctions ( )
9+ let useSyncExternalStoreWithSelector = notInitialized as uSESWS
10+ export const initializeUseSelector = ( fn : uSESWS ) => {
11+ useSyncExternalStoreWithSelector = fn
12+ }
913
1014const refEquality : EqualityFn < any > = ( a , b ) => a === b
1115
Original file line number Diff line number Diff line change 77import { useSyncExternalStore } from 'react'
88import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector'
99
10- import { setSyncFunctions } from './utils/useSyncExternalStore'
1110import { unstable_batchedUpdates as batch } from './utils/reactBatchedUpdates'
1211import { setBatch } from './utils/batch'
1312
14- setSyncFunctions ( useSyncExternalStore , useSyncExternalStoreWithSelector )
13+ import { initializeUseSelector } from './hooks/useSelector'
14+ import { initializeConnect } from './components/connect'
15+
16+ initializeUseSelector ( useSyncExternalStoreWithSelector )
17+ initializeConnect ( useSyncExternalStore )
1518
1619// Enable batched updates in our subscriptions for use
1720// with standard React renderers (ReactDOM, React Native)
Original file line number Diff line number Diff line change 11import type { useSyncExternalStore } from 'use-sync-external-store'
22import type { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector'
33
4- const notInitialized = ( ) => {
5- throw new Error ( 'Not initialize !' )
4+ export const notInitialized = ( ) => {
5+ throw new Error ( 'uSES not initialized !' )
66}
77
8- let uSES : typeof useSyncExternalStore = notInitialized
9- let uSESWS : typeof useSyncExternalStoreWithSelector = notInitialized
10-
11- // Allow injecting the actual functions from the entry points
12- export const setSyncFunctions = (
13- sync : typeof useSyncExternalStore ,
14- withSelector : typeof useSyncExternalStoreWithSelector
15- ) => {
16- uSES = sync
17- uSESWS = withSelector
18- }
19-
20- // Supply a getter just to skip dealing with ESM bindings
21- export const getSyncFunctions = ( ) => [ uSES , uSESWS ] as const
8+ export type uSES = typeof useSyncExternalStore
9+ export type uSESWS = typeof useSyncExternalStoreWithSelector
You can’t perform that action at this time.
0 commit comments