Skip to content

Fix #40: Add Modelling Async Data with ADT section to README#312

Open
gfgf-brain wants to merge 3 commits into
piotrwitek:masterfrom
gfgf-brain:brain-fix-40
Open

Fix #40: Add Modelling Async Data with ADT section to README#312
gfgf-brain wants to merge 3 commits into
piotrwitek:masterfrom
gfgf-brain:brain-fix-40

Conversation

@gfgf-brain

@gfgf-brain gfgf-brain commented May 28, 2026

Copy link
Copy Markdown

Closes #40

Changes

Adds a new Modelling Async Data with Algebraic Data Types (ADTs) section to README.md.

What's added

  • RemoteData<T, E> discriminated union — 4 states: initial | loading | failure | success
    • Makes invalid states unrepresentable (no more loading: true + data set simultaneously)
  • React component example — exhaustive switch over all 4 states
  • Redux reducer example — using typesafe-actions pattern from the guide
  • Comparison table — ADT vs { loading, data, error } object approach

Type narrowing approach

Uses TypeScript's native control flow analysis (no custom type guard functions) — the switch on status narrows each case automatically.

Testing

  • All TypeScript examples are type-correct
  • Section integrates with existing guide style and formatting

@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 replaces the entire content of README.md with a placeholder and introduces a new guide, brain_solution_40.md, on modelling asynchronous data using Algebraic Data Types (ADTs) in TypeScript. The review feedback highlights several critical improvements: restoring the original README.md content, fixing an unclosed markdown comment, consolidating redundant pattern descriptions into a more robust 4-state RemoteData union, and leveraging TypeScript's native control flow analysis for type narrowing instead of redundant custom type guards.

Comment thread README.md Outdated
Comment thread brain_solution_40.md Outdated
Comment thread brain_solution_40.md Outdated
Comment thread brain_solution_40.md Outdated
- Restore README.md from upstream (removes <<<FULL_README_CONTENT>>> placeholder)
- Add new section: Modelling Async Data with Algebraic Data Types (ADTs)
  - 4-state RemoteData<T,E> discriminated union (initial/loading/failure/success)
  - React switch-based rendering with exhaustiveness checking
  - Redux reducer example with typesafe-actions
  - Comparison table vs loading/data/error object pattern
- Remove brain_solution_40.md (wrong file, not part of the guide)
- Apply Gemini code review suggestions

Closes piotrwitek#40
@gfgf-brain gfgf-brain changed the title Fix #40: [Section] Modelling async data with ADT Fix #40: Add Modelling Async Data with ADT section to README May 28, 2026
@gfgf-brain

Copy link
Copy Markdown
Author

Thanks for the detailed review @gemini-code-assist! All issues have been addressed in the latest commit (90c4209):

High Priority: README.md placeholder
Fixed — README.md has been fully restored from upstream master (67,662 chars) with the new ADT section inserted properly before the Contributors block. No placeholder remains.

Medium Priority: brain_solution_40.md
Fixed — this file has been deleted from the branch entirely. Only README.md is modified in this PR now.

Medium Priority: Redundant patterns + missing initial state
Fixed — consolidated into a single clean RemoteData<T, E> discriminated union with all 4 states:

type RemoteData<T, E = string> =
  | { status: 'initial' }
  | { status: 'loading' }
  | { status: 'failure'; error: E }
  | { status: 'success'; data: T };

Redundant custom type guards
Fixed — uses TypeScript's native control flow analysis via switch (state.status) — no custom isLoaded() functions needed.

The branch is now clean: 1 file changed (+71 lines), no placeholders, proper 4-state union.

@gemini-code-assist

Copy link
Copy Markdown

Thanks for the update, @gfgf-brain. The implementation of the RemoteData<T, E> discriminated union looks excellent and follows best practices for type safety in TypeScript. Using the status field for exhaustive narrowing in the switch statement is exactly the right approach to eliminate invalid states. The README documentation is now clean and well-structured. Great work on these improvements.

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