From a96cfa09ac3df76f57b3ba732927d551c29c3471 Mon Sep 17 00:00:00 2001 From: Matthew Gerstman Date: Sat, 18 Aug 2018 08:49:54 -0600 Subject: [PATCH 1/6] Begin refactoring redux docs --- README.md | 53 ++++----- docs/introduction/Tutorial.md | 217 ++++++++++++++++++++++++++++++++++ 2 files changed, 243 insertions(+), 27 deletions(-) create mode 100644 docs/introduction/Tutorial.md diff --git a/README.md b/README.md index e07a9ae1fd..35bd66f4d0 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Redux Logo -Redux is a predictable state container for JavaScript apps. -(Not to be confused with a WordPress framework – [Redux Framework](https://reduxframework.com/).) +Redux is a predictable state container for JavaScript apps. In essence Redux stores your state as an object tree, +and provides tooling for updating that object and ensuring that all consumers are informed of updates. It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. On top of that, it provides a great developer experience, such as [live code editing combined with a time traveling debugger](https://github.com/reduxjs/redux-devtools). -You can use Redux together with [React](https://reactjs.org), or with any other view library. +Redux is often used with [React](https://reactjs.org), however it can be used with any view library. It is tiny (2kB, including dependencies). [![build status](https://img.shields.io/travis/reduxjs/redux/master.svg?style=flat-square)](https://travis-ci.org/reduxjs/redux) @@ -14,10 +14,9 @@ It is tiny (2kB, including dependencies). [![redux channel on discord](https://img.shields.io/badge/discord-%23redux%20%40%20reactiflux-61dafb.svg?style=flat-square)](https://discord.gg/0ZcbPKXt5bZ6au5t) [![Changelog #187](https://img.shields.io/badge/changelog-%23187-lightgrey.svg?style=flat-square)](https://changelog.com/187) - ## Learn Redux -We have a variety of resources available to help you learn Redux, no matter what your background or learning style is. +We have a variety of resources available to help you learn Redux, no matter what your background or learning style is. If you're looking to dive right in check out our [tutorial](introduction/Tutorial.md) ### Just the Basics @@ -49,7 +48,7 @@ Going from a TodoMVC app to a real production application can be a big jump, but - Redux creator Dan Abramov's **[free "Building React Applications with Idiomatic Redux" video series](https://egghead.io/courses/building-react-applications-with-idiomatic-redux)** builds on his first video series and covers topics like middleware, routing, and persistence. - The **[Redux FAQ](https://redux.js.org/faq)** answers many common questions about how to use Redux, and the **["Recipes" docs section](https://redux.js.org/recipes)** has information on handling derived data, testing, structuring reducer logic, and reducing boilerplate. -- Redux co-maintainer Mark Erikson's **["Practical Redux" tutorial series](http://blog.isquaredsoftware.com/series/practical-redux/)** demonstrates real-world intermediate and advanced techniques for working with React and Redux (also available as **[an interactive course on Educative.io](https://www.educative.io/collection/5687753853370368/5707702298738688)**). +- Redux co-maintainer Mark Erikson's **["Practical Redux" tutorial series](http://blog.isquaredsoftware.com/series/practical-redux/)** demonstrates real-world intermediate and advanced techniques for working with React and Redux (also available as **[an interactive course on Educative.io](https://www.educative.io/collection/5687753853370368/5707702298738688)**). - The **[React/Redux links list](https://github.com/markerikson/react-redux-links)** has categorized articles on working with [reducers and selectors](https://github.com/markerikson/react-redux-links/blob/master/redux-reducers-selectors.md), [managing side effects](https://github.com/markerikson/react-redux-links/blob/master/redux-side-effects.md), [Redux architecture and best practices](https://github.com/markerikson/react-redux-links/blob/master/redux-architecture.md), and more. - Our community has created thousands of Redux-related libraries, addons, and tools. The **["Ecosystem" docs page](https://redux.js.org/introduction/ecosystem)** lists our recommendations, and there's a complete listing available in the **[Redux addons catalog](https://github.com/markerikson/redux-ecosystem-links)**. - If you're looking to learn from actual application codebases, the addons catalog also has a list of **[purpose-built examples and real-world applications](https://github.com/markerikson/redux-ecosystem-links/blob/master/apps-and-examples.md)**. @@ -87,7 +86,7 @@ Dan Abramov (author of Redux) wrote Redux while working on his React Europe talk ## Influences -Redux evolves the ideas of [Flux](http://facebook.github.io/flux/), but avoids its complexity by taking cues from [Elm](https://github.com/evancz/elm-architecture-tutorial/). +Redux evolves the ideas of [Flux](http://facebook.github.io/flux/), but avoids its complexity by taking cues from [Elm](https://github.com/evancz/elm-architecture-tutorial/). Even if you haven't used Flux or Elm, Redux only takes a few minutes to get started with. ## Installation @@ -98,7 +97,7 @@ To install the stable version: npm install --save redux ``` -This assumes you are using [npm](https://www.npmjs.com/) as your package manager. +This assumes you are using [npm](https://www.npmjs.com/) as your package manager. If you're not, you can [access these files on unpkg](https://unpkg.com/redux/), download them, or point your package manager to them. @@ -121,8 +120,8 @@ Note that unlike Redux itself, many packages in the Redux ecosystem don't provid ## The Gist -The whole state of your app is stored in an object tree inside a single *store*. -The only way to change the state tree is to emit an *action*, an object describing what happened. +The whole state of your app is stored in an object tree inside a single *store*. +The only way to change the state tree is to emit an *action*, an object describing what happened. To specify how the actions transform the state tree, you write pure *reducers*. That's it! @@ -188,19 +187,19 @@ This architecture might seem like an overkill for a counter app, but the beauty #### Getting Started with Redux **[Getting Started with Redux](https://egghead.io/series/getting-started-with-redux)** is a video course consisting of 30 videos narrated by [Dan Abramov](https://twitter.com/dan_abramov), author of Redux. It is designed to complement the “Basics” part of the docs while bringing additional insights about immutability, testing, Redux best practices, and using Redux with React. **This course is free and will always be.** ->[“Great course on egghead.io by @dan_abramov - instead of just showing you how to use #redux, it also shows how and why redux was built!”](https://twitter.com/sandrinodm/status/670548531422326785) +>[“Great course on egghead.io by @dan_abramov - instead of just showing you how to use #redux, it also shows how and why redux was built!”](https://twitter.com/sandrinodm/status/670548531422326785) >Sandrino Di Mattia ->[“Plowing through @dan_abramov 'Getting Started with Redux' - its amazing how much simpler concepts get with video.”](https://twitter.com/chrisdhanaraj/status/670328025553219584) +>[“Plowing through @dan_abramov 'Getting Started with Redux' - its amazing how much simpler concepts get with video.”](https://twitter.com/chrisdhanaraj/status/670328025553219584) >Chris Dhanaraj ->[“This video series on Redux by @dan_abramov on @eggheadio is spectacular!”](https://twitter.com/eddiezane/status/670333133242408960) +>[“This video series on Redux by @dan_abramov on @eggheadio is spectacular!”](https://twitter.com/eddiezane/status/670333133242408960) >Eddie Zaneski ->[“Come for the name hype. Stay for the rock solid fundamentals. (Thanks, and great job @dan_abramov and @eggheadio!)”](https://twitter.com/danott/status/669909126554607617) +>[“Come for the name hype. Stay for the rock solid fundamentals. (Thanks, and great job @dan_abramov and @eggheadio!)”](https://twitter.com/danott/status/669909126554607617) >Dan ->[“This series of videos on Redux by @dan_abramov is repeatedly blowing my mind - gunna do some serious refactoring”](https://twitter.com/gelatindesign/status/669658358643892224) +>[“This series of videos on Redux by @dan_abramov is repeatedly blowing my mind - gunna do some serious refactoring”](https://twitter.com/gelatindesign/status/669658358643892224) >Laurence Roberts So, what are you waiting for? @@ -224,14 +223,14 @@ The **[Building React Applications with Idiomatic Redux](https://egghead.io/cour **[Practical Redux](https://www.educative.io/collection/5687753853370368/5707702298738688/)** is a paid interactive course by Redux co-maintainer [Mark Erikson](https://twitter.com/acemarke). The course is designed to show how to apply the basic concepts of Redux to building something larger than a TodoMVC application. It includes real-world topics like: -- Adding Redux to a new Create-React-App project and configuring Hot Module Replacement for faster development -- Controling your UI behavior with Redux -- Using the Redux-ORM library to manage relational data in your Redux store -- Building a master/detail view to display and edit data -- Writing custom advanced Redux reducer logic to solve specific problems -- Optimizing performance of Redux-connected form inputs +- Adding Redux to a new Create-React-App project and configuring Hot Module Replacement for faster development +- Controling your UI behavior with Redux +- Using the Redux-ORM library to manage relational data in your Redux store +- Building a master/detail view to display and edit data +- Writing custom advanced Redux reducer logic to solve specific problems +- Optimizing performance of Redux-connected form inputs -And much more! +And much more! The course is based on Mark's original free **["Practical Redux" blog tutorial series](http://blog.isquaredsoftware.com/series/practical-redux/)**, but with updated and improved content. @@ -287,13 +286,13 @@ If you're new to the NPM ecosystem and have troubles getting a project up and ru ## Testimonials ->[“Love what you're doing with Redux”](https://twitter.com/jingc/status/616608251463909376) +>[“Love what you're doing with Redux”](https://twitter.com/jingc/status/616608251463909376) >Jing Chen, creator of Flux ->[“I asked for comments on Redux in FB's internal JS discussion group, and it was universally praised. Really awesome work.”](https://twitter.com/fisherwebdev/status/616286955693682688) +>[“I asked for comments on Redux in FB's internal JS discussion group, and it was universally praised. Really awesome work.”](https://twitter.com/fisherwebdev/status/616286955693682688) >Bill Fisher, author of Flux documentation ->[“It's cool that you are inventing a better Flux by not doing Flux at all.”](https://twitter.com/andrestaltz/status/616271392930201604) +>[“It's cool that you are inventing a better Flux by not doing Flux at all.”](https://twitter.com/andrestaltz/status/616271392930201604) >André Staltz, creator of Cycle ## Thanks @@ -317,12 +316,12 @@ You can find the official logo [on GitHub](https://github.com/reduxjs/redux/tree ## Change Log -This project adheres to [Semantic Versioning](http://semver.org/). +This project adheres to [Semantic Versioning](http://semver.org/). Every release, along with the migration instructions, is documented on the GitHub [Releases](https://github.com/reduxjs/redux/releases) page. ## Patrons -The work on Redux was [funded by the community](https://www.patreon.com/reactdx). +The work on Redux was [funded by the community](https://www.patreon.com/reactdx). Meet some of the outstanding companies that made it possible: * [Webflow](https://github.com/webflow) diff --git a/docs/introduction/Tutorial.md b/docs/introduction/Tutorial.md new file mode 100644 index 0000000000..df7acd0238 --- /dev/null +++ b/docs/introduction/Tutorial.md @@ -0,0 +1,217 @@ +# Tutorial + +This article serves to teach you the basics of Redux and get up and running in a React/Redux application. While Redux can be used with any view layer, it is most commonly used with React, so we’ll explore that here. + +## The TLDR + +Redux is a predictable state container for JavaScript apps. In essence Redux stores your state as an object tree, +and provides tooling for updating that object and ensuring that all consumers are informed of updates. + +## A Friendly Warning + +This page is *opinionated* more-so than most of the other documentation. This is to make your life +easier when getting started with Redux for the first time. + +## Nitpicking about Names + +There are a couple of terms that will be thrown around a lot that we should make sure we have a clear understanding of. These may not make sense right away, but should be at the top of this document for +quick reference. +- The **store** is the the entire Redux Store that encompasses **state, middleware, dispatch,** and **reducers**. +- A **namespace** is a top level key on both the state object and the list of reducers. A namespace maps a reducer to a slice of the Redux state. +- The state object is a plain JSON object that is separated into namespaces. When an action is fired every reducer is called with the action and it’s slice of the store. The reducers then return a new state at that namespace which is combined into the overall state object. + + +## Store: One Store to Rule Them All + +Towards the top of your application you should have a file called `store.js`. This file is going +to be where we **create the react store.** + +Most likely, you want to inforce the invariant of one store per page for multi-page app and one store total for single page apps. This is usually important when integrating with React because it allows us to use a single `` per React tree that can use any selector from any library. Don't worry about all these other terms just yet. We'll get there. +Inside this file you'll have the following code: + + + import { createStore } from 'redux' + import rootReducer from './reducer' + const store = createStore(rootReducer) + export default store + +That's it. There's a bunch of other stuff you might want to do: inject middleware, initial state, etc. But let's consider all that out of scope for the moment. + +## Reducer: What does my Reducer Look Like? + +Your reducer should be a pure function that takes an `action` and a `state` and returns a brand new state object. +What’s a pure function? +A pure function is a function that takes inputs, does not mutate them, and returns a new reference as output. They are purely synchronous. Here are a few don’ts for a reducer: + +- Do Not: Dispatch a new action +- Do Not: Hit an API +- Do Not: Block or sleep +- Do Not: setTimeout +- Do Not: Mutate an object. For example: `state.foo =` `'``bar``'` + +Under the hood, Redux works by checking whether or not references have changed. You should never mutate any part of the state object, always return a brand new one with properties copied over. + +The average reducer file will look something like this: + + export WIZARD_REDUCER_KEY = 'WIZARD'; + + const defaultState = { + name: "Harry Potter", + scar: true, + parents: 'dead', + learnedSpells: [], + } + export default function potterReducer(state = defaultState, action) { + switch (action.type) { + case "LEARN_SPELL": { + ...state, + learnedSpells: [...state.learnedSpells, action.payload.spell] + } + default: { + return state + } + } + } + +You'll notice that we have a defaultState default parameter. This is because when the store is instantiated it calls potterReducer with `null` and an `INIT` action. + +Your reducer should not handle this `INIT` action directly but rather return the previous state. We actually make this very difficult to do but that’s another topic. + + +## **Namespaces** + +We know about our store and the reducer, but what if we want more than one reducer? We actually do that quite a bit. To do this you’ll use `combineReducers`. Here’s what that code usually looks like + + + import muggleReducer, {MUGGLE_NAMESPACE_KEY} from './muggle-reducer'; + import wizardReducer, {WIZARD_NAMESPACE_KEY} from './wizard-reducer'; + + export default rootReducer = combineReducers({ + [MUGGLE_NAMESPACE_KEY]: muggleReducer, + [WIZARD_NAMESPACE_KEY]: wizardReducer, + }); + +When using `combineReducers` every dispatched action on the store will cause the reducer to be called with it’s slice (namespace) of the state and the action. + + +## **Selectors:** Getting Your Data Out Of the Store + +Your selectors should also be pure functions that take state and an (optional) object of options as parameters and return data form the store. + +Selectors will often be small and each drill down throughout the store. The average `selectors.js` file will look like this: + + + import {WIZARD_NAMESPACE_KEY} from './wizard-reducer'; + + /* + state = { + name: "Harry Potter", + scar: true, + parents: 'dead', + learnedSpells: [], + } + * / + + const getWizardState = (state) => state[WIZARD_NAMESPACE_KEY]; + + export const getName = (state) => getWizardState(state).name; + export const getSpells = (state) => getWizardState(state).learnedSpells; + + +## **Actions:** Changing State + +Actions are payloads of information that send data from your application to your store. They are **the only source of new information** for the store. Actions should always be encapsulated by a function or **action creator**. + +Here’s what an `actions.js` file might look like. + + + export function learnSpell(spell) { + return { + type: "LEARN_SPELL", + payload: { spell }, + } + } + +The only invariant on actions inside of redux is that their exists a key called `type`. However `type` is most commonly a string and `payload` is often an object that is present as well. Many people follow the [FluxStandardAction](https://github.com/redux-utilities/flux-standard-action) paradigm. + + +## **Action Creators** + +Action creators can also be used to dispatch multiple actions. They are also commonly used for To do this we use a [**thunk**](https://github.com/gaearon/redux-thunk)**.** In the context of Redux, a ****thunk is an action creator that returns a function. We’re going to skip these for now but for more information check out THE SECTION ON THUNKS. + + +## **Integrating with React:** Tying it all together with `connect` + +We just covered a lot. Stores, reducers, actions, selectors, but how do we get these things into our application? Enter `connect`, a function exported by the library `react-redux`. Connect is a Higher Order Component (LINK) that ensures your component receives **always up to date** selected data from redux. It also calls `[bindActionCreators](https://redux.js.org/docs/api/bindActionCreators.html)` on all of your action creators so they can be called without passing them to `dispatch`. + +Let’s look at some sample code then discuss it. + + + import {getName, getSpells} 'data/selectors'; + + function Wizard({name, spells, learnSpell}) { + return ( +
+

{name}

+

Learned Spells

+
    + {spells.map((spell) => ( +
  • {spell}
  • +
+ + +
+ ); + } + + const mapStateToProps = (state) => { + return { + name: getName(state), + spells: getSpells(state), + }; + }; + + const mapDispatchToProps = { + learnSpell, + }; + + export default connect(mapStateToProps, mapDispatchToProps)(Wizard); + +**Whats going on here?** +There’s a few parts happening here + +First, we have a functional stateless component that takes some props. These props are a name (string), spells (array), and learnSpell (function). The internal component should have no idea it’s connected to Redux. It simply takes data and functions that can change that data. + +Second, we have `connect`. This is a higher order component that abstracts away the internal publish/subscribe pattern with Redux. It takes two parameters `mapStateToProps` and `mapDispatchToProps`. + +`mapStateToProps` is a function that get’s passed the redux state and returns an object that will have it’s keys passed as props to the internal component. Connect guarantees that the component is always rendered with the newest state whenever state changes. + +`mapDispatchToProps` can be either a function or an object. In this tutorial we will only discuss the object syntax. `mapDispatchToProps` takes a list of action creators and calls `bindActionCreators` before passing them to the component. This is the magic that allows you to call the prop internally and have it dispatch an object to Redux. + + +## **Provider:** Connect isn’t magic. + +Connect gets access to the redux store over [context](https://reactjs.org/docs/context.html). This is an advanced React API that allows you to pass through data without props. The `` component takes a store and ensures that components wrapped in a `connect` function get access. + +Somewhere towards the top of your application you’ll have some code that looks like this: + + + import store from 'store'; + import MyApp from 'MyApp'; + export default function() { + return ( + + + + ); + } + + +## You should never access the redux store directly in a component. Always use `` and `connect`. + +Your components should ideally have no idea that they’re connected to Redux. This provides a clear separation of concerns between view logic and business logic. By using `connect` we abstract Redux away from the component. The only things the component needs to know is “What data do I need to receive” and “What functions should I call to change something.” + +This abstraction layer protects you both from changes in our Redux layer code and changes in the Redux API itself. + From 92209c124db6109206932e37ff40bd67afd78786 Mon Sep 17 00:00:00 2001 From: Matthew Gerstman Date: Sat, 18 Aug 2018 17:46:37 -0600 Subject: [PATCH 2/6] Move courses to LearnRedux.md --- README.md | 185 +------------------------------- docs/introduction/LearnRedux.md | 89 +++++++++++++++ 2 files changed, 93 insertions(+), 181 deletions(-) create mode 100644 docs/introduction/LearnRedux.md diff --git a/README.md b/README.md index 35bd66f4d0..10cb8da414 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ It helps you write applications that behave consistently, run in different envir Redux is often used with [React](https://reactjs.org), however it can be used with any view library. It is tiny (2kB, including dependencies). +Not to be confused with a WordPress framework – [Redux Framework](https://reduxframework.com/). + [![build status](https://img.shields.io/travis/reduxjs/redux/master.svg?style=flat-square)](https://travis-ci.org/reduxjs/redux) [![npm version](https://img.shields.io/npm/v/redux.svg?style=flat-square)](https://www.npmjs.com/package/redux) [![npm downloads](https://img.shields.io/npm/dm/redux.svg?style=flat-square)](https://www.npmjs.com/package/redux) @@ -16,53 +18,13 @@ It is tiny (2kB, including dependencies). ## Learn Redux -We have a variety of resources available to help you learn Redux, no matter what your background or learning style is. If you're looking to dive right in check out our [tutorial](introduction/Tutorial.md) - -### Just the Basics - -If you're brand new to Redux and want to understand the basic concepts, see: - -- The **[basic tutorial in the Redux docs](https://redux.js.org/basics)** -- Redux creator Dan Abramov's **free ["Getting Started with Redux" video series](https://egghead.io/series/getting-started-with-redux)** on Egghead.io -- Redux co-maintainer Mark Erikson's **["Redux Fundamentals" slideshow](http://blog.isquaredsoftware.com/2018/03/presentation-reactathon-redux-fundamentals/)** and **[list of suggested resources for learning Redux](http://blog.isquaredsoftware.com/2017/12/blogged-answers-learn-redux/)** -- If you learn best by looking at code and playing with it, check out our list of **[Redux example applications](https://redux.js.org/introduction/examples)**, available as separate projects in the Redux repo, and also as interactive online examples on CodeSandbox. -- The **[Redux Tutorials](https://github.com/markerikson/react-redux-links/blob/master/redux-tutorials.md)** section of the **[React/Redux links list](https://github.com/markerikson/react-redux-links)**. Here's a top list of our recommended tutorials: - - Dave Ceddia's posts [What Does Redux Do? (and when should you use it?)](https://daveceddia.com/what-does-redux-do/) and [How Redux Works: A Counter-Example](https://daveceddia.com/how-does-redux-work/) are a great intro to the basics of Redux and how to use it with React, as is this post on [React and Redux: An Introduction](http://jakesidsmith.com/blog/post/2017-11-18-redux-and-react-an-introduction/). - - Valentino Gagliardi's post [React Redux Tutorial for Beginners: Learning Redux in 2018](https://www.valentinog.com/blog/react-redux-tutorial-beginners/) is an excellent extended introduction to many aspects of using Redux. - - The CSS Tricks article [Leveling Up with React: Redux](https://css-tricks.com/learning-react-redux/) covers the Redux basics well. - - This [DevGuides: Introduction to Redux](http://devguides.io/redux/) tutorial covers several aspects of Redux, including actions, reducers, usage with React, and middleware. - - -### Intermediate Concepts - -Once you've picked up the basics of working with actions, reducers, and the store, you may have questions about topics like working with asynchronous logic and AJAX requests, connecting a UI framework like React to your Redux store, and setting up an application to use Redux: - -- The **["Advanced" docs section](https://redux.js.org/advanced)** covers working with async logic, middleware, routing. -- The Redux docs **["Learning Resources"](https://redux.js.org/introduction/learning-resources)** page points to recommended articles on a variety of Redux-related topics. -- Sophie DeBenedetto's 8-part **[Building a Simple CRUD App with React + Redux](http://www.thegreatcodeadventure.com/building-a-simple-crud-app-with-react-redux-part-1/)** series shows how to put together a basic CRUD app from scratch. - - -### Real-World Usage - -Going from a TodoMVC app to a real production application can be a big jump, but we've got plenty of resources to help: - -- Redux creator Dan Abramov's **[free "Building React Applications with Idiomatic Redux" video series](https://egghead.io/courses/building-react-applications-with-idiomatic-redux)** builds on his first video series and covers topics like middleware, routing, and persistence. -- The **[Redux FAQ](https://redux.js.org/faq)** answers many common questions about how to use Redux, and the **["Recipes" docs section](https://redux.js.org/recipes)** has information on handling derived data, testing, structuring reducer logic, and reducing boilerplate. -- Redux co-maintainer Mark Erikson's **["Practical Redux" tutorial series](http://blog.isquaredsoftware.com/series/practical-redux/)** demonstrates real-world intermediate and advanced techniques for working with React and Redux (also available as **[an interactive course on Educative.io](https://www.educative.io/collection/5687753853370368/5707702298738688)**). -- The **[React/Redux links list](https://github.com/markerikson/react-redux-links)** has categorized articles on working with [reducers and selectors](https://github.com/markerikson/react-redux-links/blob/master/redux-reducers-selectors.md), [managing side effects](https://github.com/markerikson/react-redux-links/blob/master/redux-side-effects.md), [Redux architecture and best practices](https://github.com/markerikson/react-redux-links/blob/master/redux-architecture.md), and more. -- Our community has created thousands of Redux-related libraries, addons, and tools. The **["Ecosystem" docs page](https://redux.js.org/introduction/ecosystem)** lists our recommendations, and there's a complete listing available in the **[Redux addons catalog](https://github.com/markerikson/redux-ecosystem-links)**. -- If you're looking to learn from actual application codebases, the addons catalog also has a list of **[purpose-built examples and real-world applications](https://github.com/markerikson/redux-ecosystem-links/blob/master/apps-and-examples.md)**. - -Finally, Mark Erikson is teaching a series of **[Redux workshops through Workshop.me](#redux-workshops)**. Check the [workshop schedule](https://workshop.me/?a=mark) for upcoming dates and locations. - +We have a variety of resources available to help you learn Redux, no matter what your background or learning style is. If you're looking to dive right in check out our [tutorial](introduction/Tutorial.md). We also have quite a few [references available](introduction/LearnRedux.md). -### Help and Discussion +## Help and Discussion The **[#redux channel](https://discord.gg/0ZcbPKXt5bZ6au5t)** of the **[Reactiflux Discord community](http://www.reactiflux.com)** is our official resource for all questions related to learning and using Redux. Reactiflux is a great place to hang out, ask questions, and learn - come join us! - - ## Before Proceeding Further Redux is a valuable tool for organizing your state, but you should also consider whether it's appropriate for your situation. Don't use Redux just because someone said you should - take some time to understand the potential benefits and tradeoffs of using it. @@ -84,11 +46,6 @@ Yes, these guidelines are subjective and vague, but this is for good reason. The Dan Abramov (author of Redux) wrote Redux while working on his React Europe talk called [“Hot Reloading with Time Travel”](https://www.youtube.com/watch?v=xsSnOQynTHs). His goal was to create a state management library with a minimal API but completely predictable behavior. Redux makes it possible to implement logging, hot reloading, time travel, universal apps, record and replay, without any buy-in from the developer. -## Influences - -Redux evolves the ideas of [Flux](http://facebook.github.io/flux/), but avoids its complexity by taking cues from [Elm](https://github.com/evancz/elm-architecture-tutorial/). -Even if you haven't used Flux or Elm, Redux only takes a few minutes to get started with. - ## Installation To install the stable version: @@ -118,140 +75,6 @@ npm install --save-dev redux-devtools Note that unlike Redux itself, many packages in the Redux ecosystem don't provide UMD builds, so we recommend using CommonJS module bundlers like [Webpack](https://webpack.js.org/) and [Browserify](http://browserify.org/) for the most comfortable development experience. -## The Gist - -The whole state of your app is stored in an object tree inside a single *store*. -The only way to change the state tree is to emit an *action*, an object describing what happened. -To specify how the actions transform the state tree, you write pure *reducers*. - -That's it! - -```js -import { createStore } from 'redux' - -/** - * This is a reducer, a pure function with (state, action) => state signature. - * It describes how an action transforms the state into the next state. - * - * The shape of the state is up to you: it can be a primitive, an array, an object, - * or even an Immutable.js data structure. The only important part is that you should - * not mutate the state object, but return a new object if the state changes. - * - * In this example, we use a `switch` statement and strings, but you can use a helper that - * follows a different convention (such as function maps) if it makes sense for your - * project. - */ -function counter(state = 0, action) { - switch (action.type) { - case 'INCREMENT': - return state + 1 - case 'DECREMENT': - return state - 1 - default: - return state - } -} - -// Create a Redux store holding the state of your app. -// Its API is { subscribe, dispatch, getState }. -let store = createStore(counter) - -// You can use subscribe() to update the UI in response to state changes. -// Normally you'd use a view binding library (e.g. React Redux) rather than subscribe() directly. -// However it can also be handy to persist the current state in the localStorage. - -store.subscribe(() => - console.log(store.getState()) -) - -// The only way to mutate the internal state is to dispatch an action. -// The actions can be serialized, logged or stored and later replayed. -store.dispatch({ type: 'INCREMENT' }) -// 1 -store.dispatch({ type: 'INCREMENT' }) -// 2 -store.dispatch({ type: 'DECREMENT' }) -// 1 -``` - -Instead of mutating the state directly, you specify the mutations you want to happen with plain objects called *actions*. Then you write a special function called a *reducer* to decide how every action transforms the entire application's state. - -If you're coming from Flux, there is a single important difference you need to understand. Redux doesn't have a Dispatcher or support many stores. Instead, there is just a single store with a single root reducing function. As your app grows, instead of adding stores, you split the root reducer into smaller reducers independently operating on the different parts of the state tree. This is exactly like how there is just one root component in a React app, but it is composed out of many small components. - -This architecture might seem like an overkill for a counter app, but the beauty of this pattern is how well it scales to large and complex apps. It also enables very powerful developer tools, because it is possible to trace every mutation to the action that caused it. You can record user sessions and reproduce them just by replaying every action. - -## Learn Redux from Its Authors - -### Redux Video Tutorials by Dan Abramov - -#### Getting Started with Redux -**[Getting Started with Redux](https://egghead.io/series/getting-started-with-redux)** is a video course consisting of 30 videos narrated by [Dan Abramov](https://twitter.com/dan_abramov), author of Redux. It is designed to complement the “Basics” part of the docs while bringing additional insights about immutability, testing, Redux best practices, and using Redux with React. **This course is free and will always be.** - ->[“Great course on egghead.io by @dan_abramov - instead of just showing you how to use #redux, it also shows how and why redux was built!”](https://twitter.com/sandrinodm/status/670548531422326785) ->Sandrino Di Mattia - ->[“Plowing through @dan_abramov 'Getting Started with Redux' - its amazing how much simpler concepts get with video.”](https://twitter.com/chrisdhanaraj/status/670328025553219584) ->Chris Dhanaraj - ->[“This video series on Redux by @dan_abramov on @eggheadio is spectacular!”](https://twitter.com/eddiezane/status/670333133242408960) ->Eddie Zaneski - ->[“Come for the name hype. Stay for the rock solid fundamentals. (Thanks, and great job @dan_abramov and @eggheadio!)”](https://twitter.com/danott/status/669909126554607617) ->Dan - ->[“This series of videos on Redux by @dan_abramov is repeatedly blowing my mind - gunna do some serious refactoring”](https://twitter.com/gelatindesign/status/669658358643892224) ->Laurence Roberts - -So, what are you waiting for? - -#### [Watch the free "Getting Started with Redux" video series](https://egghead.io/series/getting-started-with-redux) - -> Note: If you enjoyed Dan's course, consider supporting Egghead by [buying a subscription](https://egghead.io/pricing). Subscribers have access to the source code of every example in my videos and tons of advanced lessons on other topics, including JavaScript in depth, React, Angular, and more. Many [Egghead instructors](https://egghead.io/instructors) are also open source library authors, so buying a subscription is a nice way to thank them for the work that they've done. - - -#### Building React Applications with Idiomatic Redux - -The **[Building React Applications with Idiomatic Redux](https://egghead.io/courses/building-react-applications-with-idiomatic-redux)** course is a second free video series by Dan Abramov. It picks up where the first series left off, and covers practical production ready techniques for building your React and Redux applications: advanced state management, middleware, React Router integration, and other common problems you are likely to encounter while building applications for your clients and customers. As with the first series, **this course will always be free**. - - -#### [Watch the free "Idiomatic Redux" video series](https://egghead.io/courses/building-react-applications-with-idiomatic-redux) - - - -### Practical Redux course - -**[Practical Redux](https://www.educative.io/collection/5687753853370368/5707702298738688/)** is a paid interactive course by Redux co-maintainer [Mark Erikson](https://twitter.com/acemarke). The course is designed to show how to apply the basic concepts of Redux to building something larger than a TodoMVC application. It includes real-world topics like: - - -- Adding Redux to a new Create-React-App project and configuring Hot Module Replacement for faster development -- Controling your UI behavior with Redux -- Using the Redux-ORM library to manage relational data in your Redux store -- Building a master/detail view to display and edit data -- Writing custom advanced Redux reducer logic to solve specific problems -- Optimizing performance of Redux-connected form inputs - -And much more! - -The course is based on Mark's original free **["Practical Redux" blog tutorial series](http://blog.isquaredsoftware.com/series/practical-redux/)**, but with updated and improved content. - - -### Redux Workshops - -Redux co-maintainer [Mark Erikson](https://twitter.com/acemarke) has partnered with [Workshop.me](https://workshop.me/) to teach a series of Redux workshops. - -The first [**Redux Fundamentals** workshop will be held in New York City, April 19-20](https://workshop.me/2018-04-react-redux?a=mark), and will cover: - -- The history and purpose of Redux -- Reducers, actions, and working with a Redux store -- Using Redux with React -- Using and writing Redux middleware -- Working with AJAX calls and other side effects -- Unit testing Redux apps -- Real-world Redux app structure and development - -Tickets are still available, and [can be purchased through Workshop.me](https://workshop.me/2018-04-react-redux?a=mark). - - ## Documentation * [Introduction](http://redux.js.org/introduction/index.html) diff --git a/docs/introduction/LearnRedux.md b/docs/introduction/LearnRedux.md new file mode 100644 index 0000000000..b6d2b947de --- /dev/null +++ b/docs/introduction/LearnRedux.md @@ -0,0 +1,89 @@ +# Learn Redux + +## Just the Basics + +If you're brand new to Redux and want to understand the basic concepts, see: + +- The **[basic tutorial in the Redux docs](https://redux.js.org/basics)** +- Redux creator Dan Abramov's **free ["Getting Started with Redux" video series](https://egghead.io/series/getting-started-with-redux)** on Egghead.io +- Redux co-maintainer Mark Erikson's **["Redux Fundamentals" slideshow](http://blog.isquaredsoftware.com/2018/03/presentation-reactathon-redux-fundamentals/)** and **[list of suggested resources for learning Redux](http://blog.isquaredsoftware.com/2017/12/blogged-answers-learn-redux/)** +- If you learn best by looking at code and playing with it, check out our list of **[Redux example applications](https://redux.js.org/introduction/examples)**, available as separate projects in the Redux repo, and also as interactive online examples on CodeSandbox. +- The **[Redux Tutorials](https://github.com/markerikson/react-redux-links/blob/master/redux-tutorials.md)** section of the **[React/Redux links list](https://github.com/markerikson/react-redux-links)**. Here's a top list of our recommended tutorials: + - Dave Ceddia's posts [What Does Redux Do? (and when should you use it?)](https://daveceddia.com/what-does-redux-do/) and [How Redux Works: A Counter-Example](https://daveceddia.com/how-does-redux-work/) are a great intro to the basics of Redux and how to use it with React, as is this post on [React and Redux: An Introduction](http://jakesidsmith.com/blog/post/2017-11-18-redux-and-react-an-introduction/). + - Valentino Gagliardi's post [React Redux Tutorial for Beginners: Learning Redux in 2018](https://www.valentinog.com/blog/react-redux-tutorial-beginners/) is an excellent extended introduction to many aspects of using Redux. + - The CSS Tricks article [Leveling Up with React: Redux](https://css-tricks.com/learning-react-redux/) covers the Redux basics well. + - This [DevGuides: Introduction to Redux](http://devguides.io/redux/) tutorial covers several aspects of Redux, including actions, reducers, usage with React, and middleware. + + +## Intermediate Concepts + +Once you've picked up the basics of working with actions, reducers, and the store, you may have questions about topics like working with asynchronous logic and AJAX requests, connecting a UI framework like React to your Redux store, and setting up an application to use Redux: + +- The **["Advanced" docs section](https://redux.js.org/advanced)** covers working with async logic, middleware, routing. +- The Redux docs **["Learning Resources"](https://redux.js.org/introduction/learning-resources)** page points to recommended articles on a variety of Redux-related topics. +- Sophie DeBenedetto's 8-part **[Building a Simple CRUD App with React + Redux](http://www.thegreatcodeadventure.com/building-a-simple-crud-app-with-react-redux-part-1/)** series shows how to put together a basic CRUD app from scratch. + + +## Real-World Usage + +Going from a TodoMVC app to a real production application can be a big jump, but we've got plenty of resources to help: + +- Redux creator Dan Abramov's **[free "Building React Applications with Idiomatic Redux" video series](https://egghead.io/courses/building-react-applications-with-idiomatic-redux)** builds on his first video series and covers topics like middleware, routing, and persistence. +- The **[Redux FAQ](https://redux.js.org/faq)** answers many common questions about how to use Redux, and the **["Recipes" docs section](https://redux.js.org/recipes)** has information on handling derived data, testing, structuring reducer logic, and reducing boilerplate. +- Redux co-maintainer Mark Erikson's **["Practical Redux" tutorial series](http://blog.isquaredsoftware.com/series/practical-redux/)** demonstrates real-world intermediate and advanced techniques for working with React and Redux (also available as **[an interactive course on Educative.io](https://www.educative.io/collection/5687753853370368/5707702298738688)**). +- The **[React/Redux links list](https://github.com/markerikson/react-redux-links)** has categorized articles on working with [reducers and selectors](https://github.com/markerikson/react-redux-links/blob/master/redux-reducers-selectors.md), [managing side effects](https://github.com/markerikson/react-redux-links/blob/master/redux-side-effects.md), [Redux architecture and best practices](https://github.com/markerikson/react-redux-links/blob/master/redux-architecture.md), and more. +- Our community has created thousands of Redux-related libraries, addons, and tools. The **["Ecosystem" docs page](https://redux.js.org/introduction/ecosystem)** lists our recommendations, and there's a complete listing available in the **[Redux addons catalog](https://github.com/markerikson/redux-ecosystem-links)**. +- If you're looking to learn from actual application codebases, the addons catalog also has a list of **[purpose-built examples and real-world applications](https://github.com/markerikson/redux-ecosystem-links/blob/master/apps-and-examples.md)**. + +Finally, Mark Erikson is teaching a series of **[Redux workshops through Workshop.me](#redux-workshops)**. Check the [workshop schedule](https://workshop.me/?a=mark) for upcoming dates and locations. + +## Courses + +There are many courses available both on and offline, free or paid. Take a look at some of the courses below if that's your learning style. + +### [Watch the free "Getting Started with Redux" video series](https://egghead.io/series/getting-started-with-redux) + +> Note: If you enjoyed Dan's course, consider supporting Egghead by [buying a subscription](https://egghead.io/pricing). Subscribers have access to the source code of every example in my videos and tons of advanced lessons on other topics, including JavaScript in depth, React, Angular, and more. Many [Egghead instructors](https://egghead.io/instructors) are also open source library authors, so buying a subscription is a nice way to thank them for the work that they've done. + + +### Building React Applications with Idiomatic Redux + +The **[Building React Applications with Idiomatic Redux](https://egghead.io/courses/building-react-applications-with-idiomatic-redux)** course is a second free video series by Dan Abramov. It picks up where the first series left off, and covers practical production ready techniques for building your React and Redux applications: advanced state management, middleware, React Router integration, and other common problems you are likely to encounter while building applications for your clients and customers. As with the first series, **this course will always be free**. + + +### [Watch the free "Idiomatic Redux" video series](https://egghead.io/courses/building-react-applications-with-idiomatic-redux) + + + +### Practical Redux course + +**[Practical Redux](https://www.educative.io/collection/5687753853370368/5707702298738688/)** is a paid interactive course by Redux co-maintainer [Mark Erikson](https://twitter.com/acemarke). The course is designed to show how to apply the basic concepts of Redux to building something larger than a TodoMVC application. It includes real-world topics like: + + +- Adding Redux to a new Create-React-App project and configuring Hot Module Replacement for faster development +- Controling your UI behavior with Redux +- Using the Redux-ORM library to manage relational data in your Redux store +- Building a master/detail view to display and edit data +- Writing custom advanced Redux reducer logic to solve specific problems +- Optimizing performance of Redux-connected form inputs + +And much more! + +The course is based on Mark's original free **["Practical Redux" blog tutorial series](http://blog.isquaredsoftware.com/series/practical-redux/)**, but with updated and improved content. + + +### Redux Workshops + +Redux co-maintainer [Mark Erikson](https://twitter.com/acemarke) has partnered with [Workshop.me](https://workshop.me/) to teach a series of Redux workshops. + +The first [**Redux Fundamentals** workshop will be held in New York City, April 19-20](https://workshop.me/2018-04-react-redux?a=mark), and will cover: + +- The history and purpose of Redux +- Reducers, actions, and working with a Redux store +- Using Redux with React +- Using and writing Redux middleware +- Working with AJAX calls and other side effects +- Unit testing Redux apps +- Real-world Redux app structure and development + +Tickets are still available, and [can be purchased through Workshop.me](https://workshop.me/2018-04-react-redux?a=mark). From 68f247410db9ce8250b82216fb717ff70ae8fc08 Mon Sep 17 00:00:00 2001 From: Matthew Gerstman Date: Sat, 18 Aug 2018 18:10:50 -0600 Subject: [PATCH 3/6] Continue moving sections out of the landing page and into separate pages --- README.md | 43 +------------------ docs/InstallationContinued.md | 6 +++ .../{LearnRedux.md => ExternalTutorials.md} | 17 ++++++++ 3 files changed, 25 insertions(+), 41 deletions(-) create mode 100644 docs/InstallationContinued.md rename docs/introduction/{LearnRedux.md => ExternalTutorials.md} (87%) diff --git a/README.md b/README.md index 10cb8da414..9ef5cf02dc 100644 --- a/README.md +++ b/README.md @@ -24,24 +24,6 @@ We have a variety of resources available to help you learn Redux, no matter what The **[#redux channel](https://discord.gg/0ZcbPKXt5bZ6au5t)** of the **[Reactiflux Discord community](http://www.reactiflux.com)** is our official resource for all questions related to learning and using Redux. Reactiflux is a great place to hang out, ask questions, and learn - come join us! - -## Before Proceeding Further - -Redux is a valuable tool for organizing your state, but you should also consider whether it's appropriate for your situation. Don't use Redux just because someone said you should - take some time to understand the potential benefits and tradeoffs of using it. - -Here are some suggestions on when it makes sense to use Redux: -* You have reasonable amounts of data changing over time -* You need a single source of truth for your state -* You find that keeping all your state in a top-level component is no longer sufficient - -Yes, these guidelines are subjective and vague, but this is for good reason. The point at which you should integrate Redux into your application is different for every user and different for every application. - ->**For more thoughts on how Redux is meant to be used, see:**
->- **[You Might Not Need Redux](https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367)**
->- **[The Tao of Redux, Part 1 - Implementation and Intent](http://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-1/)**
->- **[The Tao of Redux, Part 2 - Practice and Philosophy](http://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-2/)** ->- **[Redux FAQ](https://redux.js.org/faq)** - ## Developer Experience Dan Abramov (author of Redux) wrote Redux while working on his React Europe talk called [“Hot Reloading with Time Travel”](https://www.youtube.com/watch?v=xsSnOQynTHs). His goal was to create a state management library with a minimal API but completely predictable behavior. Redux makes it possible to implement logging, hot reloading, time travel, universal apps, record and replay, without any buy-in from the developer. @@ -58,22 +40,12 @@ This assumes you are using [npm](https://www.npmjs.com/) as your package manager If you're not, you can [access these files on unpkg](https://unpkg.com/redux/), download them, or point your package manager to them. -Most commonly, people consume Redux as a collection of [CommonJS](http://webpack.github.io/docs/commonjs.html) modules. These modules are what you get when you import `redux` in a [Webpack](https://webpack.js.org/), [Browserify](http://browserify.org/), or a Node environment. If you like to live on the edge and use [Rollup](https://rollupjs.org), we support that as well. +We support almost every frontend workflow. If you're using something other than npm this section is [continued here.](InstallationContinued). -If you don't use a module bundler, it's also fine. The `redux` npm package includes precompiled production and development [UMD](https://github.com/umdjs/umd) builds in the [`dist` folder](https://unpkg.com/redux/dist/). They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. For example, you can drop a UMD build as a [`