reduxjs / redux

A JS library for predictable global state management
https://redux.js.org
MIT License
60.87k stars 15.27k forks source link

[Docs Rewrite] Rewrite the existing "Basics/Advanced" tutorial sequence #3855

Closed markerikson closed 3 years ago

markerikson commented 4 years ago

Overview

The existing Redux "Basics/Advanced" tutorial sequence desperately needs to be rewritten. While it's been useful for many people, the target audience of the Redux docs has changed considerably since Dan first put it together. At the time, Dan said:

So hard to write the new docs. Many different audiences to cater to.
Should make sense to: Flux beginners, FP people, FP people who don't get Flux, Flux people who don't get FP, normal JS people too
Flux people: "is this proper Flux?" FP people: "is this that weird thing called Flux?" Normal people: "why not Backbone"

Clearly, the audience today is very different.

The existing tutorial teaches Redux using a "bottom-up" approach, explaining how each piece works individually, and building up towards putting them together into something useful. The new "Redux Essentials" tutorial that I just wrote teaches Redux "top-down", explaining "how to use it the right way", but not covering how it works. Both approaches are needed.

Flaws with the Tutorial

Goals

My main goals here are:

I'll need to figure out how to balance teaching the individual concepts, with having a coherent set of examples and explanations.

Existing Redux Tutorial Sequence Notes

Previous Personal Notes

Feedback

Introduction

Basics

Actions

Reducers

Store

Data Flow

Usage with React

Advanced

This section should not at all be called "advanced". This is pretty key info, and the only real distinction here is that it's stuff that goes beyond using Redux synchronously by itself. Consider renaming it to something else.

Async Actions

Async Flow

Middleware

Usage with React Router

Example: Reddit API

Next Steps

MilosRasic commented 4 years ago

Everything looks awesome, just have some feedback on the action naming part.

{ type: 'FETCH_POSTS_REQUEST' }
{ type: 'FETCH_POSTS_FAILURE', error: 'Oops' }
{ type: 'FETCH_POSTS_SUCCESS', response: { ... } }

could have an example of a simple thunk creator function that's passed FETCH_POSTS and implicitly generates the above three action types.

markerikson commented 4 years ago

@MilosRasic yeah, I'm inclined to go with 'todos/todoAdded' as well.

The point of the inline action names is to remove the extra line of code needed for the old classic const ADD_TODO = "ADD_TODO" pattern. I'm going to have to find a way to emphasize in these docs that "this is how it works underneath, but this isn't how we recommend using it - use RTK instead".

Similarly, the purpose of this tutorial is to show the mechanics and how you would write this code "by hand", so that you later understand what RTK's abstractions do for you. In fact, I think the best way to finish this tutorial would be to migrate all the code we write over to RTK to show how much nicer it is.

markerikson commented 4 years ago

Basics Tutorial Rewrite Plans

Initial Thoughts

Here's my initial thoughts on how to tackle this:

Outline

Part 1: Redux Overview

Part 2: Redux Terms and Data Flow

Part 3: Actions and Reducers

Part 4: Store

Part 5: UI

Part 6: Async Logic and Data Flow

Part 7: Standard Redux Patterns

Part 8: Modern Redux

Part 9: Next Steps

markerikson commented 3 years ago

And this is now LIVE!

https://redux.js.org/tutorials/fundamentals/part-1-overview