Skip to content

Commit

Permalink
enhance: Remove dispatch from StoreContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jun 19, 2024
1 parent afe0640 commit 96b683b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .changeset/funny-socks-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@data-client/react': patch
---

Remove need for dispatch in StoreContext as it is never used

This should have no affect unless you're working with internals of Data Client
2 changes: 0 additions & 2 deletions packages/react/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ export const ControllerContext = createContext<Controller>(

export interface Store<S> {
subscribe(listener: () => void): () => void;
dispatch: React.Dispatch<ActionTypes>;
getState(): S;
uninitialized?: boolean;
}
/* istanbul ignore next */
export const StoreContext = createContext<Store<State<unknown>>>({
subscribe: listener => () => {},
dispatch: () => {},
getState: () => initialState,
uninitialized: true,
});
7 changes: 2 additions & 5 deletions packages/react/src/server/SSRDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ export default function SSRDataProvider({
devButton,
hasDevManager = true,
}: Props<State<any>>) {
const controller = useMemo(() => new Controller({ dispatch }), []);
const store = useMemo(
() => ({ subscribe, dispatch, getState }),
[subscribe, dispatch, getState],
);
const controller = useMemo(() => new Controller({ dispatch }), [dispatch]);
const store = useMemo(() => ({ subscribe, getState }), [subscribe, getState]);

return (
<StoreContext.Provider value={store}>
Expand Down
4 changes: 0 additions & 4 deletions packages/react/src/server/redux/ExternalDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import {
StoreContext,
BackupLoading,
UniversalSuspense,
usePromisifiedDispatch,
StateContext,
} from '../../index.js';

interface Store<S> {
subscribe(listener: () => void): () => void;
dispatch: React.Dispatch<ActionTypes>;
getState(): S;
}
interface Props<S> {
Expand Down Expand Up @@ -73,8 +71,6 @@ export default function ExternalDataProvider<S>({
return unsubscribe;
}, [selectState, store]);

const dispatch = usePromisifiedDispatch(store.dispatch, state);

const adaptedStore = useMemo(() => {
return { ...store, getState: () => selector(store.getState()) };
}, [selector, store]);
Expand Down

0 comments on commit 96b683b

Please sign in to comment.