Skip to content

Commit e580d5c

Browse files
committed
refactor: rename api
1 parent 4bd5caf commit e580d5c

3 files changed

Lines changed: 22 additions & 40 deletions

File tree

‎packages/jotai-x/src/createAtomStore.spec.tsx‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { splitAtom } from 'jotai/utils';
88

99
import {
1010
createAtomStore,
11-
useAtomValueOfJotaiXStore,
12-
useSetOfJotaiXStore,
13-
useStateOfJotaiXStore,
14-
useValueOfJotaiXStore,
11+
useStoreAtomValue,
12+
useStoreSet,
13+
useStoreState,
14+
useStoreValue,
1515
} from './createAtomStore';
1616

1717
describe('createAtomStore', () => {
@@ -414,8 +414,8 @@ describe('createAtomStore', () => {
414414
// Just guarantee that the react compiler doesn't complain
415415
/* eslint-enable react-compiler/react-compiler */
416416
const store = useMyTestStoreStore();
417-
const becomeFriends1 = useValueOfJotaiXStore(store, 'becomeFriends');
418-
const becomeFriends2 = useAtomValueOfJotaiXStore(
417+
const becomeFriends1 = useStoreValue(store, 'becomeFriends');
418+
const becomeFriends2 = useStoreAtomValue(
419419
store,
420420
myTestStoreStore.atom.becomeFriends
421421
);
@@ -507,7 +507,7 @@ describe('createAtomStore', () => {
507507
// Just guarantee that the react compiler doesn't complain
508508
/* eslint-enable react-compiler/react-compiler */
509509
const store = useMyTestStoreStore();
510-
const setBecomeFriends = useSetOfJotaiXStore(store, 'becomeFriends');
510+
const setBecomeFriends = useStoreSet(store, 'becomeFriends');
511511
const [becameFriends, setBecameFriends] = React.useState(false);
512512

513513
return (
@@ -603,10 +603,7 @@ describe('createAtomStore', () => {
603603
// Just guarantee that the react compiler doesn't complain
604604
/* eslint-enable react-compiler/react-compiler */
605605
const store = useMyTestStoreStore();
606-
const [, setBecomeFriends] = useStateOfJotaiXStore(
607-
store,
608-
'becomeFriends'
609-
);
606+
const [, setBecomeFriends] = useStoreState(store, 'becomeFriends');
610607
const [becameFriends, setBecameFriends] = React.useState(false);
611608

612609
return (

‎packages/jotai-x/src/createAtomStore.ts‎

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -832,29 +832,19 @@ Please wrap them with useCallback or configure the deps array correctly.`
832832
} as any;
833833
};
834834

835-
export function useValueOfJotaiXStore<T, E, K extends keyof StoreAtoms<T, E>>(
835+
export function useStoreValue<T, E, K extends keyof StoreAtoms<T, E>>(
836836
store: ReturnOfUseStoreApi<T, E>,
837837
key: K
838838
): StoreAtoms<T, E>[K] extends Atom<infer V> ? V : never;
839-
export function useValueOfJotaiXStore<
840-
T,
841-
E,
842-
K extends keyof StoreAtoms<T, E>,
843-
S,
844-
>(
839+
export function useStoreValue<T, E, K extends keyof StoreAtoms<T, E>, S>(
845840
store: ReturnOfUseStoreApi<T, E>,
846841
key: K,
847842
selector: StoreAtoms<T, E>[K] extends Atom<infer V>
848843
? (v: V, prevSelectorOutput?: S) => S
849844
: never,
850845
deps?: unknown[]
851846
): S;
852-
export function useValueOfJotaiXStore<
853-
T,
854-
E,
855-
K extends keyof StoreAtoms<T, E>,
856-
S,
857-
>(
847+
export function useStoreValue<T, E, K extends keyof StoreAtoms<T, E>, S>(
858848
store: ReturnOfUseStoreApi<T, E>,
859849
key: K,
860850
selector: StoreAtoms<T, E>[K] extends Atom<infer V>
@@ -863,12 +853,7 @@ export function useValueOfJotaiXStore<
863853
equalityFn: (prevSelectorOutput: S, selectorOutput: S) => boolean,
864854
deps?: unknown[]
865855
): S;
866-
export function useValueOfJotaiXStore<
867-
T,
868-
E,
869-
K extends keyof StoreAtoms<T, E>,
870-
S,
871-
>(
856+
export function useStoreValue<T, E, K extends keyof StoreAtoms<T, E>, S>(
872857
store: ReturnOfUseStoreApi<T, E>,
873858
key: K,
874859
selector?: StoreAtoms<T, E>[K] extends Atom<infer V>
@@ -880,38 +865,38 @@ export function useValueOfJotaiXStore<
880865
return store.useValue(key, selector, equalityFnOrDeps, deps);
881866
}
882867

883-
export function useSetOfJotaiXStore<T, E, K extends keyof StoreAtoms<T, E>>(
868+
export function useStoreSet<T, E, K extends keyof StoreAtoms<T, E>>(
884869
store: ReturnOfUseStoreApi<T, E>,
885870
key: K
886871
) {
887872
return store.useSet(key);
888873
}
889874

890-
export function useStateOfJotaiXStore<T, E, K extends keyof StoreAtoms<T, E>>(
875+
export function useStoreState<T, E, K extends keyof StoreAtoms<T, E>>(
891876
store: ReturnOfUseStoreApi<T, E>,
892877
key: K
893878
) {
894879
return store.useState(key);
895880
}
896881

897-
export function useAtomValueOfJotaiXStore<T, E, V>(
882+
export function useStoreAtomValue<T, E, V>(
898883
store: ReturnOfUseStoreApi<T, E>,
899884
atom: Atom<V>
900885
): V;
901-
export function useAtomValueOfJotaiXStore<T, E, V, S>(
886+
export function useStoreAtomValue<T, E, V, S>(
902887
store: ReturnOfUseStoreApi<T, E>,
903888
atom: Atom<V>,
904889
selector: (v: V, prevSelectorOutput?: S) => S,
905890
deps?: unknown[]
906891
): S;
907-
export function useAtomValueOfJotaiXStore<T, E, V, S>(
892+
export function useStoreAtomValue<T, E, V, S>(
908893
store: ReturnOfUseStoreApi<T, E>,
909894
atom: Atom<V>,
910895
selector: ((v: V, prevSelectorOutput?: S) => S) | undefined,
911896
equalityFn: (prevSelectorOutput: S, selectorOutput: S) => boolean,
912897
deps?: unknown[]
913898
): S;
914-
export function useAtomValueOfJotaiXStore<T, E, V, S>(
899+
export function useStoreAtomValue<T, E, V, S>(
915900
store: ReturnOfUseStoreApi<T, E>,
916901
atom: Atom<V>,
917902
selector?: (v: V, prevSelectorOutput?: S) => S,
@@ -921,14 +906,14 @@ export function useAtomValueOfJotaiXStore<T, E, V, S>(
921906
return store.useAtomValue(atom, selector, equalityFnOrDeps, deps);
922907
}
923908

924-
export function useSetAtomOfJotaiXStore<T, E, V, A extends unknown[], R>(
909+
export function useStoreSetAtom<T, E, V, A extends unknown[], R>(
925910
store: ReturnOfUseStoreApi<T, E>,
926911
atom: WritableAtom<V, A, R>
927912
) {
928913
return store.useSetAtom(atom);
929914
}
930915

931-
export function useAtomStateOfJotaiXStore<T, E, V, A extends unknown[], R>(
916+
export function useStoreAtomState<T, E, V, A extends unknown[], R>(
932917
store: ReturnOfUseStoreApi<T, E>,
933918
atom: WritableAtom<V, A, R>
934919
) {

‎packages/jotai-x/src/elementAtom.spec.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import '@testing-library/jest-dom';
33
import React from 'react';
44
import { act, render } from '@testing-library/react';
55

6-
import { createAtomStore, useValueOfJotaiXStore } from './createAtomStore';
6+
import { createAtomStore, useStoreValue } from './createAtomStore';
77

88
type TElement = any;
99

@@ -24,7 +24,7 @@ export const useElement = <T extends TElement = TElement>(
2424
pluginKey = SCOPE_ELEMENT
2525
): T => {
2626
const store = useElementStore(pluginKey);
27-
const value = useValueOfJotaiXStore(store, 'element');
27+
const value = useStoreValue(store, 'element');
2828

2929
if (!value) {
3030
console.warn(

0 commit comments

Comments
 (0)