Skip to content

Commit

Permalink
enhance: Move state.endpoints above state.indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jul 22, 2024
1 parent 6fccfbc commit 09ad848
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
10 changes: 10 additions & 0 deletions .changeset/rude-wolves-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@data-client/core': patch
'@data-client/react': patch
---

state.endpoints moved above indexes

`entites` and `endpoints` are the most commonly inspected
parts of state when debugging, so it is better to have endpoints
above indexes.
2 changes: 1 addition & 1 deletion packages/core/src/state/reducer/createReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export default function createReducer(controller: Controller): ReducerType {

export const initialState: State<unknown> = {
entities: {},
indexes: {},
endpoints: {},
indexes: {},
meta: {},
entityMeta: {},
optimistic: [],
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/state/reducer/setReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export function setReducer(
);
return {
entities,
indexes,
endpoints: state.endpoints,
entityMeta,
indexes,
meta: state.meta,
entityMeta,
optimistic: state.optimistic,
lastReset: state.lastReset,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/state/reducer/setResponseReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ export function setResponseReducer(
}
return {
entities,
indexes,
endpoints,
entityMeta,
indexes,
meta: {
...state.meta,
[action.key]: {
Expand All @@ -80,6 +79,7 @@ export function setResponseReducer(
prevExpiresAt: state.meta[action.key]?.expiresAt,
},
},
entityMeta,
optimistic: filterOptimistic(state, action),
lastReset: state.lastReset,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export interface State<T> {
readonly entities: {
readonly [entityKey: string]: { readonly [pk: string]: T } | undefined;
};
readonly indexes: NormalizedIndex;
readonly endpoints: {
readonly [key: string]: unknown | PK[] | PK | undefined;
};
readonly indexes: NormalizedIndex;
readonly meta: {
readonly [key: string]: {
readonly date: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,10 @@ interface State<T> {
readonly [pk: string]: T;
} | undefined;
};
readonly indexes: NormalizedIndex;
readonly endpoints: {
readonly [key: string]: unknown | PK[] | PK | undefined;
};
readonly indexes: NormalizedIndex;
readonly meta: {
readonly [key: string]: {
readonly date: number;
Expand Down

0 comments on commit 09ad848

Please sign in to comment.