Skip to content

Add section: Modelling async data with ADT - #360

Open
libracapitalinvestments-rgb wants to merge 1 commit into
piotrwitek:masterfrom
libracapitalinvestments-rgb:casharmy/fix-issue-40
Open

Add section: Modelling async data with ADT#360
libracapitalinvestments-rgb wants to merge 1 commit into
piotrwitek:masterfrom
libracapitalinvestments-rgb:casharmy/fix-issue-40

Conversation

@libracapitalinvestments-rgb

Copy link
Copy Markdown

Adds a new section covering the RemoteData ADT pattern for modelling async data in reducers and React components. This pattern makes incorrect states unrepresentable using discriminated union types. Closes #40

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new markdown guide and a corresponding TypeScript file demonstrating how to model asynchronous data in Redux using Algebraic Data Types (ADTs) / discriminated unions instead of boolean flags. The feedback points out a critical issue in both files where mapStateToProps incorrectly types the incoming state as the slice state (RemoteData or State) instead of the global RootState, which would lead to runtime errors when accessing properties. Suggestions are provided to define a proper RootState type and map the slice state correctly.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +135 to +137
const mapStateToProps = (state: RemoteData<Error, Array<User>>) => ({
usersData: state,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In a standard Redux application, the state passed to mapStateToProps represents the global root state (usually combined via combineReducers), not the individual slice state. Typing state as RemoteData directly will cause runtime errors (e.g., usersData will be assigned the root state object, and usersData.status will be undefined, leading to a crash when trying to render). We should define a RootState type to represent the global state structure.

Suggested change
const mapStateToProps = (state: RemoteData<Error, Array<User>>) => ({
usersData: state,
});
type RootState = {
users: RemoteData<Error, Array<User>>;
};
const mapStateToProps = (state: RootState) => ({
usersData: state.users,
});

Comment on lines +80 to +82
const mapStateToProps = (state: State) => ({
usersData: state,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In a standard Redux application, the state passed to mapStateToProps represents the global root state (usually combined via combineReducers), not the individual slice state. Typing state as State directly will cause runtime errors (e.g., usersData will be assigned the root state object, and usersData.status will be undefined, leading to a crash when trying to render). We should define a RootState type to represent the global state structure.

Suggested change
const mapStateToProps = (state: State) => ({
usersData: state,
});
type RootState = {
users: State;
};
const mapStateToProps = (state: RootState) => ({
usersData: state.users,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Section] Modelling async data with ADT

1 participant