Code Monkey home page Code Monkey logo

learn-redux's Introduction

learn-redux-header

Learn Redux

Redux simplifies writing well-structured, predictable, testable & maintainable JavaScript Web Applications.

Note: this guide is aimed at people who already have "intermediate" JavaScript experience. e.g. you have already built a couple of small apps without using a framework and/or have used an older more complex library such as Angular, Ember, Backbone or Flux. If you are just starting out on your web programming journey, we recommend you checkout: https://github.com/dwyl/start-here#javascript first and then come back here!
Bookmark/Star this GitHub repository so you don't forget where it is!

Why?

xkcd code quality

JavaScript web applications can become messy if they don't have a clear organisation from the beginning.

Redux is an elegant way to structure your JavaScript web applications.

Having built many web applications over the past few years using all the most popular frameworks/libraries, we were delighted to discover Redux's refreshingly simple approach.

While there is an initial learning curve we feel the simplicity of the single store (snapshot of your app's state) and applying changes to your app by dispatching succinct functional actions offers a significant benefit over other ways of organising your code.

Please, don't take our word for it, skim through the notes we have made and always decide for yourself.

What?

Redux1 borrows the reducer pattern from Elm Architecture which simplifies writing web apps.
If you have never heard of Elm, don't worry, you don't need to go read another doc before you can understand this... Just keep reading and (hopefully) everything will become clear.

If anything is unclear, please tell us where you are stuck so we can help! Join the chat at https://gitter.im/dwyl/chat

Three Principals

Redux is based on three principals.
see: https://redux.js.org/understanding/thinking-in-redux/three-principles

1. Single Source of Truth

The state of your whole application is stored in a single object tree; the "Store".
This makes it much easier to keep track of the "State" of your application at any time and roll back to any previous state.

If its not intermediately obvious why this is a good thing, we urge you to have faith and keep reading...

2. State is Read-Only ("Immutable")

Instead of directly updating data in the store, we describe the update as a function which gets applied to the existing store and returns a new version.

See: https://en.wikipedia.org/wiki/Immutable_object

3. Changes are made Using Pure Functions

To change the state tree we use "actions" called "reducers", these are simple functions which perform a single action.


tl;dr

Read more about JavaScript's Reduce (Array method): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
and how to reduce an array of Objects: https://stackoverflow.com/questions/5732043/javascript-reduce-on-array-of-objects
understanding these two things will help you grasp why Redux is so simple.

You will see this abbreviated/codified as (state, action) => state
to understand what this means, watch: youtu.be/xsSnOQynTHs?t=15m51s

How?

Learn Where Redux Got It's Best Ideas From!

Redux "takes cues from" (i.e. takes all it's best ideas/features from) Elm. redux-borrows-elm
So... by learning The Elm Architecture, you will intrinsically understand Redux
which will help you learn/develop React apps.

We wrote a complete beginner's step-by-step introduction to The Elm Architecture for JavaScript developers:
github.com/dwyl/learn-elm-architecture-in-javascript

If after you've learned Redux and built a couple of React Apps, you decide you want to discover where all the best ideas in the React ecosystem came from, checkout: github.com/dwyl/learn-elm

Learn from the Creator of Redux!

The fastest way to learn Redux is to watch the Introductory Video Tutorials recoded by Dan Abramov (the Creator of Redux).
The videos are broken down into "bite size" chunks which are easily digestible. Total viewing time for the videos is 66 minutes

We have made a set of comprehensive notes/transcriptions on the videos, these are in: egghead.io_video_tutorial_notes.md

We recommend keeping the notes open in a distinct window/browser while you are watching the videos; you can go a lot faster because all the sample code is included and if for any reason you do not understand what Dan is saying you have the notes to refer to.

learn-redux-video-notes-side-by-side

Please give feedback and suggest improvements by creating issues on GitHub: https://github.com/dwyl/learn-redux/issues Thanks!


Background Reading / Watching / Listening

Architecture

If you are building a React-based app you will most likely be using react-router to manage the routing of your client-side app ... React-Router manages an important piece of your application state: the URL. If you are using redux, you want your app state to fully represent your UI; if you snapshotted the app state, you should be able to load it up later and see the same thing.

Size (Matters)

At the time of writing, the minified version of Redux is 5.4kb which is even smaller when GZipped!

Frequently Asked Questions (FAQ)

(Do I Need to use) React ?

Short Answer: No, Redux does not depend on or require you to use React; the two are separate and can be learned/used independently.

Longer Answer: While many Redux apps and tutorials use React, Redux is totally separate from React. Dan's EggHead Video Tutorials do feature React heavily from Lesson 8 onwards.

React is a good fit for rendering views in a Redux-based app, however there are many other great alternative component-based virtual-DOM-enabled view rendering libraries (#mouth-full) that work really well with Redux; e.g: https://github.com/anthonyshort/deku

Considering that React is the fastest growing "view" (DOM Rendering) library of 2015 and the pace of its' adoption looks set to continue in 2016 ... so it won't hurt you to know how to use React.

We've made some notes to help you get started learning React: https://github.com/dwyl/learn-react

You can/should use Redux to organise your application and optionally use React to render your views.

(Should I use) Immutable.js ?

Short Answer: Not Yet!

Longer Answer: The convention in Redux apps is for the state to be immutable this makes your app far more predictable because any/all changes to the state have to be done via an action.

Immutable.js makes the data structures in your application state more efficient (in larger apps) however, while you are learning Redux we suggest you ignore immutable.js as you will have more than enough to master for now.

Once you have published your first app using Redux, come back to immutable.js to appreciate how it makes large apps run faster. As Lee Byron, the creator of Immutable.js states, for small apps without much change in state, adding Immutable.js will actually make your app perform worse!

If you want to understand why using Immutable.js can be a good thing in large apps, watch Lee Byron's intro to Immutable

Todo: pull requests welcomed!

  • Explain why Unidirectional Data Flow is this "better" than bi-directional e.g: Angular.js

Kudos to Fellow DWYLers

Props to Rafe for telling us about Redux and Elm: https://github.com/rjmk/reducks before it was cool
Thanks to Milo for his fantastic demo/example: https://github.com/bananaoomarang/isomorphic-redux
(which he has painstakingly kept up-to-date with the latest Redux/React versions!)
and love to Niki & Jack for their enthusiasm and patience while explaining it all to us ...

Thanks for Learning with Us!

If you found our notes useful, please share them with others by starring this repo and/or re-tweeting:

dan_abramov_retweeted

https://twitter.com/dwylhq/status/687703493264732160

learn-redux's People

Contributors

ajmeese7 avatar arhell avatar dan-h-ch avatar gabrielperales avatar hdrdavies avatar iteles avatar karinakozarova avatar manonthemat avatar nelsonic avatar newswim avatar qaraluch avatar rouzazari avatar shouston3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learn-redux's Issues

Getting issue during deployment of nodejs file locally using heroku toolbelt

Hi, I am new to it and am getting below error. Thanks in advance.

C:\Program Files\nodejs>heroku local web
[WARN] No ENV file found
[WARN] ENOENT: no such file or directory, open 'C:\Program Files\nodejs\Procfile
'
[OKAY] package.json file found - trying 'npm start'
9:44:01 AM web.1 | > [email protected] start C:\Program Files\nodejs
9:44:01 AM web.1 | > node quickstart.js
9:44:01 AM web.1 | usage: node examples/quickstart.js ORIGDWXKSWGSLKSOT7RQIJLHR
NWMELD2
9:44:01 AM web.1 | npm
9:44:01 AM web.1 | ERR! Windows_NT 6.2.9200
9:44:01 AM web.1 | npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Pro
gram Files\nodejs\node_modules\npm\bin\npm-cli.js" "start"
9:44:01 AM web.1 | npm ERR! node v6.4.0
9:44:01 AM web.1 | npm ERR! npm v3.10.3
9:44:01 AM web.1 | npm ERR! code ELIFECYCLE
9:44:01 AM web.1 | npm ERR!
9:44:01 AM web.1 | [email protected] start: node quickstart.js
9:44:01 AM web.1 | npm ERR! Exit status 1
9:44:01 AM web.1 | npm ERR!
9:44:01 AM web.1 | npm ERR! Failed at the [email protected] start script 'nod
e quickstart.js'.
9:44:01 AM web.1 | npm ERR! Make sure you have the latest version of node.js an
d npm installed.
9:44:01 AM web.1 | npm ERR! If you do, this is most likely a problem with the w
eathernodejs package,
9:44:01 AM web.1 | npm ERR! not with npm itself.
9:44:01 AM web.1 | npm ERR! Tell the author that this fails on your system:
9:44:01 AM web.1 | npm ERR! node quickstart.js
9:44:01 AM web.1 | npm ERR! You can get information on how to open an issue for
this project with:
9:44:01 AM web.1 | npm ERR! npm bugs weathernodejs
9:44:01 AM web.1 | npm ERR! Or if that isn't available, you can get their info
via:
9:44:01 AM web.1 | npm ERR! npm owner ls weathernodejs
9:44:01 AM web.1 | npm ERR! There is likely additional logging output above.
9:44:01 AM web.1 | npm ERR! Please include the following file with any support
request:
9:44:01 AM web.1 | npm ERR! C:\Program Files\nodejs\npm-debug.log
[DONE] Killing all processes with signal null
9:44:01 AM web.1 Exited with exit code 1

And here is the log file:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]prestart: [email protected]
6 silly lifecycle [email protected]
prestart: no script for prestart, continuing
7 info lifecycle [email protected]start: [email protected]
8 verbose lifecycle [email protected]
start: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]start: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Program Files\nodejs\node_modules.bin;C:\Program Files\nodejs;"C:\Program Files (x86)\Heroku\ruby-2.1.7\bin";C:\Program Files\Microsoft SDKs\Azure.NET SDK\v2.8\bin;C:\Program Files\Microsoft SDKs\Azure\emulator;C:\Program Files\Microsoft SDKs\Azure\emulator\devstore;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Microsoft Office Servers\15.0\Bin;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0;C:\Program Files\Microsoft SQL Server\120\Tools\Binn;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x86)\git\cmd;C:\Program Files (x86)\Git\cmd;C:\Program Files\nodejs;C:\Users\ericame\AppData\Roaming\npm;C:\Program Files (x86)\Git\bin
10 verbose lifecycle [email protected]
start: CWD: C:\Program Files\nodejs
11 silly lifecycle [email protected]start: Args: [ '/d /s /c', 'node quickstart.js' ]
12 silly lifecycle [email protected]
start: Returned: code: 1 signal: null
13 info lifecycle [email protected]~start: Failed to exec start script
14 verbose stack Error: [email protected] start: node quickstart.js
14 verbose stack Exit status 1
14 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:242:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:852:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid [email protected]
16 verbose cwd C:\Program Files\nodejs
17 error Windows_NT 6.2.9200
18 error argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "start"
19 error node v6.4.0
20 error npm v3.10.3
21 error code ELIFECYCLE
22 error [email protected] start: node quickstart.js
22 error Exit status 1
23 error Failed at the [email protected] start script 'node quickstart.js'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the weathernodejs package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error node quickstart.js
23 error You can get information on how to open an issue for this project with:
23 error npm bugs weathernodejs
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls weathernodejs
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

Redux went from having 0 (Zero) Dependencies to having 4 (Four) ...

The repo was moved to: https://github.com/reactjs/redux so the dependency badge in the readme is "broken" ... Dependency Status

Furthermore the entire "no dependencies" section (also readme):
image
see: https://github.com/dwyl/learn-redux/tree/9b463df55e115ad6fa2e26f670270d94a1cd9d08#no-dependencies-

is obsolete (because redux now has four dependencies...): ๐Ÿ˜–
image
see: https://github.com/reactjs/redux/blob/6f6150470367c539d9bbc33bff3684919f04d5ea/package.json#L62

Suggestion

  • Remove the dependencies section from the README.md entirely.

'addTodo' and 'setVisibilityFilter' actions are unused in index.html example

I was just annotating a print out of the code to remind myself of some of the concepts learned in the video tutorials, and found the following issues:

  • addTodo action is unused: should replace the dispatch action in the AddTodo component
  • setVisibilityFilter action is unused: should be used by the dispatch action in the mapDispatchToLinkProps method

Usage of AJAX in Redux

Hello All,

I am working on a project which involves the React+Redux+GraphQL(Apollo Tools) and Backend is HapiJS+Rest+GraphQL(Apollo)

I had created a PoC to see the feasibility of this tech combination (stack). It worked very well.

Though I was already halfway on the current project and had built the Auth system in basic REST API which can be seen at https://github.com/pankajpatel/heimdall; and other supporting system plugins like following to quickly make the REST APIs.

Now the problem I am stuck with is that I want to use the Auth system with REST API and remaining system with GraphQL and struggling to get it up and running.

This is my first project with Redux; I had built the projects with Flux and calling the API was not much of the problem. I know that its easy here in Redux as well, but maybe I'm missing something because of which it is not working.

Thanks.

Update/Improve instructions for how to use the Egghead.io notes/transcriptions

The whole purpose for writing the notes on the Egghead.io videos is that the notes make it quick(er)/easier to watch the tutorials which means you can learn Redux faster!

Currently

At present we have the following copy:
image
see: https://github.com/dwyl/learn-redux/tree/9b463df55e115ad6fa2e26f670270d94a1cd9d08#learn-from-the-creator-of-redux

Suggestion

I think it's worth updating the "How?" section of the README.md to include a Screenshot of an example setup people can adopt while watching the videos and some instructive copy, e.g:


Learn from the Creator of Redux!

The fastest way to learn Redux is to watch the
Introductory Video Tutorials
recoded by Dan Abramov (the Creator of Redux).

The videos are broken down into "bite size" chunks which are easily digestible.
Total viewing time for the videos is 66 minutes

We have made a set of comprehensive notes/transcriptions on the videos, these are in:
egghead.io_video_tutorial_notes.md

We recommend keeping the notes open in a distinct window/browser
while you are watching the videos; you can go a lot faster because all the sample code is included
and if for any reason you do not understand what Dan is saying you have the notes to refer to.

learn-redux-video-notes-side-by-side

Please give feedback and suggest improvements by creating issues on GitHub:
https://github.com/dwyl/learn-redux/issues
Thanks!


Thoughts?

Add CONTRIBUTING.md File to Repo

As a person who is new to the DWYL Org/Community ๐Ÿ†•
I need to know how to contribute to the project effectively ๐Ÿ’ญ
so that I can start my journey towards Doing What I Love with my Life! โค๏ธ โœ… ๐Ÿ˜‚

Markdown:

_**Please read** our_
[**contribution guide**](https://github.com/dwyl/contributing)
(_thank you_!)

Note: these are line-separated but in the actual rendered page it's all one line.
see: https://github.com/dwyl/contributing/blob/master/CONTRIBUTING.md

Good Video on Uni-Directional Data Flow (in Flux)

If you want to understand why uni-directional data flow makes sense in larger applications watch:

uni directional data flow

While the video covers Flux the principals are applicable to a Redux application which is an * even simpler* way of writing JS Apps.

Why are we using ES2015 (ES6) Features that aren't supported in Chrome?!$%^@!!

I've been waiting for default parameters for ages ... they are going to make JS code much easier/cleaner to write: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/default_parameters
but people who use them in examples of front-end code are just being irresponsible:

es6-default-arguments-error-chrome

I'm using the latest version of Chrome:

chrome-version

Which does not have support for default parameters ...

default-parameters-javascript-compatibility

(only _Canary_ - the _Dev Build_ of Chrome - has support ...!!!)

So why are we showing beginners this feature? so they can trip themselves up and create errors...?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.