Skip to content

Commit

Permalink
refactor: remove deprecated dev methods
Browse files Browse the repository at this point in the history
BREAKING CHANGE: stop using  as fallback and throw error if dev_subscribe_store v2 is missing
  • Loading branch information
arjunvegda committed Aug 7, 2023
1 parent 03a97fd commit b390ad9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 32 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"jest-watch-typeahead": "^2.2.2",
"jotai": "^2.2.3",
"jotai": "^2.3.0",
"jotai-tanstack-query": "^0.7.1",
"lint-staged": "^13.2.3",
"prettier": "^3.0.0",
Expand All @@ -157,6 +157,7 @@
},
"peerDependencies": {
"@emotion/react": ">=11.0.0",
"jotai": ">=2.3.0",
"react": ">=17.0.0"
},
"dependencies": {
Expand Down
15 changes: 8 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ export function useInternalAtomValue<Value>(atom: Atom<Value>) {
atomSubCb.isJotaiDevTools = true;

const devSubCb = (
type?: Parameters<Parameters<typeof devSubscribeStore>[0]>[0],
type: Parameters<Parameters<typeof devSubscribeStore>[0]>[0],
) => {
const normalizedType = typeof type === 'string' ? type : type?.type;
if (typeof type !== 'object') {
throw Error(
'[DEPRECATION-ERROR]: `dev_subscribe_store` v1 is deprecated. Please update to the latest version of Jotai to automatically switch to v2.',
);
}

if (normalizedType !== 'unsub') {
if (type.type !== 'unsub') {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/stories/Default/Playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
atomWithObservable,
loadable,
splitAtom,
unstable_unwrap as unwrap,
unwrap,
} from 'jotai/vanilla/utils';
import { atomsWithQuery } from 'jotai-tanstack-query';
import { interval } from 'rxjs';
Expand Down
11 changes: 2 additions & 9 deletions src/utils/useAtomsDebugValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,16 @@ export const useAtomsDebugValue = (options?: Options) => {
const [atoms, setAtoms] = useState<Atom<unknown>[]>([]);
useEffect(() => {
const devSubscribeStore: Store['dev_subscribe_store'] =
// @ts-expect-error dev_subscribe_state is deprecated in <= 2.0.3
store?.dev_subscribe_store || store?.dev_subscribe_state;
store?.dev_subscribe_store;

if (!enabled || !devSubscribeStore) {
return;
}
const callback = () => {
setAtoms(Array.from(store.dev_get_mounted_atoms?.() || []));
};
// FIXME replace this with `store.dev_subscribe_store` check after next minor Jotai 2.1.0?
if (!('dev_subscribe_store' in store)) {
console.warn(
"[DEPRECATION-WARNING] Jotai version you're using contains deprecated dev-only properties that will be removed soon. Please update to the latest version of Jotai.",
);
}

const unsubscribe = devSubscribeStore?.(callback, 2);
const unsubscribe = devSubscribeStore(callback, 2);
callback();
return unsubscribe;
}, [enabled, store]);
Expand Down
15 changes: 4 additions & 11 deletions src/utils/useAtomsSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,20 @@ export function useAtomsSnapshot(options?: Options): AtomsSnapshot {

useEffect(() => {
const devSubscribeStore: Store['dev_subscribe_store'] =
// @ts-expect-error dev_subscribe_state is deprecated in <= 2.0.3
store?.dev_subscribe_store || store?.dev_subscribe_state;
store?.dev_subscribe_store;

if (!devSubscribeStore) return;

let prevValues: AtomsValues = new Map();
let prevDependents: AtomsDependents = new Map();

if (!('dev_subscribe_store' in store)) {
console.warn(
'[DEPRECATION-WARNING]: Your Jotai version is out-of-date and contains deprecated properties that will be removed soon. Please update to the latest version of Jotai.',
);
}

// TODO remove this `t: any` and deprecation warnings in next breaking change release
const callback = (
type?: Parameters<Parameters<typeof devSubscribeStore>[0]>[0],
type: Parameters<Parameters<typeof devSubscribeStore>[0]>[0],
) => {
if (typeof type !== 'object') {
console.warn(
'[DEPRECATION-WARNING]: Your Jotai version is out-of-date and contains deprecated properties that will be removed soon. Please update to the latest version of Jotai.',
throw Error(
'[DEPRECATION-ERROR]: `dev_subscribe_store` v1 is deprecated. Please update to the latest version of Jotai to automatically switch to v2.',
);
}

Expand Down

0 comments on commit b390ad9

Please sign in to comment.