Skip to content

fix: expose an internal function for devtools #3045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/vanilla.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export { atom } from './vanilla/atom.ts'
export type { Atom, WritableAtom, PrimitiveAtom } from './vanilla/atom.ts'

export { createStore, getDefaultStore } from './vanilla/store.ts'
export {
createStore,
getDefaultStore,
INTERNAL_overrideCreateStore,
} from './vanilla/store.ts'

export type {
Getter,
Expand Down
14 changes: 12 additions & 2 deletions src/vanilla/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,22 @@ type PrdOrDevStore =
| INTERNAL_PrdStore
| (INTERNAL_PrdStore & INTERNAL_DevStoreRev4)

let overiddenCreateStore: typeof createStore | undefined

export function INTERNAL_overrideCreateStore(
fn: (prev: typeof createStore | undefined) => typeof createStore,
): void {
overiddenCreateStore = fn(overiddenCreateStore)
}

Comment on lines +89 to +94
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we export it out of jotai/vanilla too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I forgot there was a follow-up commit. Thanks.

export function createStore(): PrdOrDevStore {
if (overiddenCreateStore) {
return overiddenCreateStore()
}
if (import.meta.env?.MODE !== 'production') {
return createDevStoreRev4()
}
const store = INTERNAL_buildStore()
return store
return INTERNAL_buildStore()
}

let defaultStore: PrdOrDevStore | undefined
Expand Down