File tree 6 files changed +31
-26
lines changed
6 files changed +31
-26
lines changed Original file line number Diff line number Diff line change 6
6
import { useSyncExternalStore } from 'use-sync-external-store/shim'
7
7
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'
8
8
9
- import { setSyncFunctions } from './utils/useSyncExternalStore'
9
+ import { initializeUseSelector } from './hooks/useSelector'
10
+ import { initializeConnect } from './components/connect'
10
11
11
- setSyncFunctions ( useSyncExternalStore , useSyncExternalStoreWithSelector )
12
+ initializeUseSelector ( useSyncExternalStoreWithSelector )
13
+ initializeConnect ( useSyncExternalStore )
12
14
13
15
import { getBatch } from './utils/batch'
14
16
Original file line number Diff line number Diff line change 5
5
import { useSyncExternalStore } from 'use-sync-external-store/shim'
6
6
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'
7
7
8
- import { setSyncFunctions } from './utils/useSyncExternalStore'
9
8
import { unstable_batchedUpdates as batch } from './utils/reactBatchedUpdates'
10
9
import { setBatch } from './utils/batch'
11
10
12
- setSyncFunctions ( useSyncExternalStore , useSyncExternalStoreWithSelector )
11
+ import { initializeUseSelector } from './hooks/useSelector'
12
+ import { initializeConnect } from './components/connect'
13
+
14
+ initializeUseSelector ( useSyncExternalStoreWithSelector )
15
+ initializeConnect ( useSyncExternalStore )
13
16
14
17
// Enable batched updates in our subscriptions for use
15
18
// 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'
28
28
29
29
import { createSubscription , Subscription } from '../utils/Subscription'
30
30
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
31
- import { getSyncFunctions } from '../utils/useSyncExternalStore'
32
31
import shallowEqual from '../utils/shallowEqual'
33
32
34
33
import {
@@ -37,7 +36,13 @@ import {
37
36
ReactReduxContextInstance ,
38
37
} from './Context'
39
38
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
+ }
41
46
42
47
// Define some constant arrays just to avoid re-creating these
43
48
const 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'
2
2
3
3
import { useReduxContext as useDefaultReduxContext } from './useReduxContext'
4
4
import { ReactReduxContext } from '../components/Context'
5
- import { getSyncFunctions } from '../utils/useSyncExternalStore'
6
5
import type { DefaultRootState , EqualityFn } from '../types'
6
+ import type { uSESWS } from '../utils/useSyncExternalStore'
7
+ import { notInitialized } from '../utils/useSyncExternalStore'
7
8
8
- const [ , useSyncExternalStoreWithSelector ] = getSyncFunctions ( )
9
+ let useSyncExternalStoreWithSelector = notInitialized as uSESWS
10
+ export const initializeUseSelector = ( fn : uSESWS ) => {
11
+ useSyncExternalStoreWithSelector = fn
12
+ }
9
13
10
14
const refEquality : EqualityFn < any > = ( a , b ) => a === b
11
15
Original file line number Diff line number Diff line change 7
7
import { useSyncExternalStore } from 'react'
8
8
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector'
9
9
10
- import { setSyncFunctions } from './utils/useSyncExternalStore'
11
10
import { unstable_batchedUpdates as batch } from './utils/reactBatchedUpdates'
12
11
import { setBatch } from './utils/batch'
13
12
14
- setSyncFunctions ( useSyncExternalStore , useSyncExternalStoreWithSelector )
13
+ import { initializeUseSelector } from './hooks/useSelector'
14
+ import { initializeConnect } from './components/connect'
15
+
16
+ initializeUseSelector ( useSyncExternalStoreWithSelector )
17
+ initializeConnect ( useSyncExternalStore )
15
18
16
19
// Enable batched updates in our subscriptions for use
17
20
// with standard React renderers (ReactDOM, React Native)
Original file line number Diff line number Diff line change 1
1
import type { useSyncExternalStore } from 'use-sync-external-store'
2
2
import type { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector'
3
3
4
- const notInitialized = ( ) => {
5
- throw new Error ( 'Not initialize !' )
4
+ export const notInitialized = ( ) => {
5
+ throw new Error ( 'uSES not initialized !' )
6
6
}
7
7
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