Skip to content

Commit 5c19880

Browse files
authored
fix: drop support for jotai store v1 (#173)
* fix: drop support for jotai store v1 * docs: update docs around prerequisites * fix: build error
1 parent 32dec78 commit 5c19880

File tree

6 files changed

+25
-117
lines changed

6 files changed

+25
-117
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88

99
- Debug 🐞 atom values with ease
1010
- ⏳ Time-travel through your atoms and find bugs faster than before
11-
(recommended jotai `>=2.2.0`)
1211
- Out-of-the-box 🔌 support for async/suspendible atoms
1312
- Built-in Dark mode 🌗
1413
- ✅ Supports custom `store`
1514
- ✅ Works with provider-less mode
1615
- ✅ Works with Next.js
1716
- ✅ Supports custom `nonce` for CSP
18-
- ✅ Hides private atoms with ability to configure (requires Jotai `>=2.0.3`)
17+
- ✅ Hides private atoms with ability to configure
1918
- ✅ Tree-shakable and built for non-production environments
2019
- ✅ Parses all the JavaScript values with JSON Tree view
2120
- ✅ Diff checking with additions and deletion highlights
@@ -30,7 +29,7 @@
3029

3130
## ☝️ Prerequisites
3231

33-
- Jotai version `>=2.1.0.`
32+
- Jotai version `>=2.9.0`
3433
- React version `>=17.0.0`
3534

3635
## 📦 Setup

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
"jest": "^29.7.0",
141141
"jest-environment-jsdom": "^29.7.0",
142142
"jest-watch-typeahead": "^2.2.2",
143-
"jotai": "^2.9.1",
143+
"jotai": "^2.11.3",
144144
"jotai-tanstack-query": "^0.7.2",
145145
"lint-staged": "^15.3.0",
146146
"postcss": "^8.4.49",

pnpm-lock.yaml

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DevTools/internal-jotai-store.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { createContext, useContext } from 'react';
2-
import { createStore } from 'jotai/vanilla';
3-
import { Store } from 'src/types';
2+
import type { Store } from 'src/types';
43

5-
// Don't use this directly in your components
6-
// use `useDevtoolsJotaiStoreOptions` instead
7-
export const internalJotaiStore = createStore();
84
export const InternalDevToolsContext = createContext<Store | undefined>(
95
undefined,
106
);

src/types.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { useStore } from 'jotai/react';
2+
import type { Atom, WritableAtom, createStore } from 'jotai/vanilla';
23
import type {
3-
Atom,
4-
WritableAtom,
5-
createStore as createStoreV1,
6-
} from 'jotai/vanilla';
7-
import { INTERNAL_DevStoreRev4, INTERNAL_PrdStore } from 'jotai/vanilla/store';
4+
INTERNAL_DevStoreRev4,
5+
INTERNAL_PrdStore,
6+
} from 'jotai/vanilla/store';
87

9-
export type StoreV1 = ReturnType<typeof createStoreV1>;
10-
export type StoreV2 = INTERNAL_DevStoreRev4 & INTERNAL_PrdStore;
8+
export type StoreWithoutDevMethods = ReturnType<typeof createStore>;
9+
export type StoreWithDevMethods = INTERNAL_DevStoreRev4 & INTERNAL_PrdStore;
1110

12-
export type Store = StoreV1 | StoreV2;
11+
export type Store = StoreWithoutDevMethods | StoreWithDevMethods;
1312

1413
export type Options = Parameters<typeof useStore>[0];
1514

src/utils/internals/compose-with-devtools.ts

+7-93
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {
44
AnyAtomError,
55
AnyAtomValue,
66
Store,
7-
StoreV1,
8-
StoreV2,
7+
StoreWithDevMethods,
98
} from '../../types';
109

1110
type DevSubscribeStoreListener = (action: {
@@ -34,23 +33,19 @@ type DevToolsStoreMethods = {
3433

3534
type WithDevToolsStore<S extends Store> = S & DevToolsStoreMethods;
3635

37-
const isStoreV2 = (store: Store | undefined): store is StoreV2 => {
36+
const isDevStore = (store: Store | undefined): store is StoreWithDevMethods => {
3837
return store ? 'dev4_get_internal_weak_map' in store : false;
3938
};
4039

41-
const isStoreV1 = (store: Store | undefined): store is StoreV1 => {
42-
return !isStoreV2(store);
43-
};
44-
4540
export const isDevToolsStore = (
4641
store: Store | WithDevToolsStore<Store>,
4742
): store is WithDevToolsStore<Store> => {
4843
return 'subscribeStore' in store;
4944
};
5045

51-
const __composeV2StoreWithDevTools = (
52-
store: StoreV2,
53-
): WithDevToolsStore<StoreV2> => {
46+
const __composeDevTools = (
47+
store: StoreWithDevMethods,
48+
): WithDevToolsStore<StoreWithDevMethods> => {
5449
const { sub, set, get } = store;
5550
const storeListeners: Set<DevSubscribeStoreListener> = new Set();
5651

@@ -159,83 +154,6 @@ const __composeV2StoreWithDevTools = (
159154
return store as typeof store & DevToolsStoreMethods;
160155
};
161156

162-
const __composeV1StoreWithDevTools = (
163-
store: StoreV1,
164-
): StoreV1 | WithDevToolsStore<StoreV1> => {
165-
if (
166-
'dev_subscribe_store' in store &&
167-
'dev_get_mounted_atoms' in store &&
168-
'dev_get_atom_state' in store &&
169-
'dev_get_mounted' in store &&
170-
'dev_restore_atoms' in store
171-
) {
172-
const {
173-
dev_subscribe_store,
174-
dev_get_mounted_atoms,
175-
dev_get_atom_state,
176-
dev_get_mounted,
177-
dev_restore_atoms,
178-
} = store;
179-
180-
(store as WithDevToolsStore<typeof store>).subscribeStore = (l) => {
181-
const cb: Parameters<typeof dev_subscribe_store>[0] = (action) => {
182-
if (action.type === 'write' || action.type === 'async-write') {
183-
l({ type: 'set' });
184-
}
185-
186-
if (action.type === 'sub') {
187-
l({ type: 'sub' });
188-
}
189-
190-
if (action.type === 'unsub') {
191-
l({ type: 'unsub' });
192-
}
193-
194-
if (action.type === 'restore') {
195-
l({ type: 'restore' });
196-
}
197-
};
198-
199-
return dev_subscribe_store(cb, 2);
200-
};
201-
202-
(store as WithDevToolsStore<typeof store>).getMountedAtoms = () => {
203-
return dev_get_mounted_atoms();
204-
};
205-
206-
(store as WithDevToolsStore<typeof store>).getAtomState = (atom) => {
207-
const aState = dev_get_atom_state(atom);
208-
209-
if (aState) {
210-
const d = new Set(aState.d.keys());
211-
d.delete(atom);
212-
213-
if ('v' in aState) {
214-
return { v: aState.v, d };
215-
}
216-
if ('e' in aState) {
217-
return { e: aState.e, d };
218-
}
219-
220-
return undefined;
221-
}
222-
};
223-
224-
(store as WithDevToolsStore<typeof store>).getMountedAtomState = (atom) => {
225-
const mounted = dev_get_mounted(atom);
226-
return mounted;
227-
};
228-
229-
(store as WithDevToolsStore<typeof store>).restoreAtoms = (values) => {
230-
dev_restore_atoms(values);
231-
};
232-
233-
return store as typeof store & DevToolsStoreMethods;
234-
}
235-
236-
return store;
237-
};
238-
239157
export const composeWithDevTools = (
240158
store: Store,
241159
): typeof store | WithDevToolsStore<typeof store> => {
@@ -244,12 +162,8 @@ export const composeWithDevTools = (
244162
return store;
245163
}
246164

247-
if (isStoreV2(store)) {
248-
return __composeV2StoreWithDevTools(store);
249-
}
250-
251-
if (isStoreV1(store)) {
252-
return __composeV1StoreWithDevTools(store);
165+
if (isDevStore(store)) {
166+
return __composeDevTools(store);
253167
}
254168

255169
return store;

0 commit comments

Comments
 (0)