Giter VIP home page Giter VIP logo

react-app's Introduction

react-app

Learning React, Flux, and Webpack.

Following along Tyler Mcginnis's tutorial here: http://tylermcginnis.com/reactjs-tutorial-pt-2-building-react-applications-with-gulp-and-browserify/

###Getting Started###

git clone https://github.com/ammarm08/react-app
cd react-app
npm install

// this command will build public/bundle.js w/ webpack, then fire up the server on localhost:8000
npm start  

###Basics###

Here's a (very crude) picture what's going on here b/t React & Flux.

Flux sits in with React to outsource data management. The key idea w/ Flux is that it keeps data flowing unidirectionally. This means that a view (in this case, a React component) cannot and should not be modifying the data.

If you've worked with Backbone before, this is sorta kinda similar to the distinction between Views and Models/Collections -- what you see on the screen is simply a visual representation of the data in models/collections. A view shouldn't be able to modify this data, but it can send a message along to someone who can (in Backbone, the Models/Collections; in React + Flux, to a Flux Dispatcher).

So when adding an item to the to-do list:

  1. Before a React component renders, it communicates with the Flux Dispatcher about what needs to happen when there's a Change. ("Dude, if anything changes, please send me any updates you have." "Ok. Just let me know what's going on on your end.")
  2. User adds item to the to-do list. The React component fires out an instruction ("I need to add an item. Here's the item")
  3. The Flux Dispatcher tells its Store to deal with it ("Okay, Store, React wanted to add an item. Here.")
  4. The Flux Store adds the item to its collection.
  5. The Store then emits a message to the Dispatcher ("Yo Flux, there's been a CHANGE!")
  6. The Dispatcher, remembering the agreement in step 1, does what React component wanted. ("Alright, I've got an updated list of to-do items for you. Here, take them.")
  7. The React component updates its state, which triggers a re-rendering of the page.
  8. The user is super stoked that he has one more fucking thing to finish before the day is over.

To reiterate: What we see on the screen only changes when the data underlying the view somehow changes.

Managing the client-side this way maintains a very pleasant separation of concerns. The View only handles what's being seen on the screen. It communicates with a Dispatcher, whose job is to just relay messages between the View and the Store. The Store is what actually handles all the business logic (aka the BIG DATA). Now when we have to make API requests to a remote server, we know who should be taking care of that (hint: not the View).

react-app's People

Contributors

ammarm08 avatar

Watchers

James Cloos avatar  avatar

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.