-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework uSES init to not rely on module initialization order
The previous attempt worked fine in local dev + tests, but failed when built and run in a real app.
- Loading branch information
1 parent
268e3d1
commit e0c5c3d
Showing
6 changed files
with
31 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,9 @@ | ||
import type { useSyncExternalStore } from 'use-sync-external-store' | ||
import type { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector' | ||
|
||
const notInitialized = () => { | ||
throw new Error('Not initialize!') | ||
export const notInitialized = () => { | ||
throw new Error('uSES not initialized!') | ||
} | ||
|
||
let uSES: typeof useSyncExternalStore = notInitialized | ||
let uSESWS: typeof useSyncExternalStoreWithSelector = notInitialized | ||
|
||
// Allow injecting the actual functions from the entry points | ||
export const setSyncFunctions = ( | ||
sync: typeof useSyncExternalStore, | ||
withSelector: typeof useSyncExternalStoreWithSelector | ||
) => { | ||
uSES = sync | ||
uSESWS = withSelector | ||
} | ||
|
||
// Supply a getter just to skip dealing with ESM bindings | ||
export const getSyncFunctions = () => [uSES, uSESWS] as const | ||
export type uSES = typeof useSyncExternalStore | ||
export type uSESWS = typeof useSyncExternalStoreWithSelector |