Slide 1

Slide 1 text

What The Flux? A Quick Primer on React & Flux Peter Piekarczyk June 10, 2015

Slide 2

Slide 2 text

UI Engineer Trunk Club @peterpme github.com/ppiekarczyk

Slide 3

Slide 3 text

Getting Started

Slide 4

Slide 4 text

What Is React Not? • Not a framework like Angular or Backbone • Not a templating engine • Not a framework replacement

Slide 5

Slide 5 text

What Is React? • A library for creating UI • Data flows in, virtual DOM comes out • Diff the next virtual DOM with the current one • When the data changes, re-render! • Render only what I need

Slide 6

Slide 6 text

Past & Present Brunch With Panache A modular approach to building web apps with Brunch github.com/trunkclub/brunch-with-panache speakerdeck.com/jhabdas/brunch-with-panache • Backbone • Chaplin • JQuery • Brunch • Coffeescript • Automatic memory management • Controllers & composition • Rails-like routes in custom router • Consistent CLI interface • CommonJS + Amd Support

Slide 7

Slide 7 text

SOA BWP BWP

Slide 8

Slide 8 text

BWP BWP BWP BWP BWP

Slide 9

Slide 9 text

“Ugh, guys?” Everything worked great for a long time Until it stopped working that great.. • Numerous API calls & hydrations • Lot of useless re-rendering • Increased load times • Huge flame chart spikes • User complaints • Dedicating way too much time 
 for render debugging & optimization • Patches weren’t doing the trick What could UI solve on its own?

Slide 10

Slide 10 text

React to the Rescue! • Reusable, encapsulated components • Single responsibility • Makes no assumptions about your current stack • Efficient diff’ing algorithm re-renders only what it needs to • Declarative style makes it easier to focus on the app itself • Less mental overhead of bringing in templates & views together For the first time, our backend’s were much more comfortable with our code

Slide 11

Slide 11 text

React to the Rescue! Why is React a big deal? • State is hard • UI is a lot of state • Debugging is a pain • Open sourced for over 3 years • Easy to integrate into any project • Used by Facebook, Instagram, Firefox Devtools, Hipchat, Squarespace • Everyone wants to be React React Solves Your Problems. All of them.

Slide 12

Slide 12 text

React to the Rescue! Templates & Views Our code became much more manageable

Slide 13

Slide 13 text

React to the Rescue! CSS Styles as Components Our design & code became much more manageable

Slide 14

Slide 14 text

Passing Down Data What are Props? Properties that are received from above and are immutable
 as far as the component is concerned

Slide 15

Slide 15 text

Passing Down Data What is State? The state starts with a default value when a Component mounts and then suffers from mutations in time (mostly generated from user events).

Slide 16

Slide 16 text

Passing Down Data

Slide 17

Slide 17 text

Now What?

Slide 18

Slide 18 text

Flux • Pattern, not a framework • Data layer • Uni directional data flow • Actions - facilitate data • Stores - application state & logic • Dispatcher - traffic control

Slide 19

Slide 19 text

Uni Directional Flow STORE COMPONENT Model View

Slide 20

Slide 20 text

Flux STORE COMPONENT `CHANGE` event user interaction ACTION
 CREATOR `CREATE` action DISPATCHER STORE callback

Slide 21

Slide 21 text

Component Sign up modal

Slide 22

Slide 22 text

Component Click Handler

Slide 23

Slide 23 text

Action Creator

Slide 24

Slide 24 text

Dispatcher

Slide 25

Slide 25 text

Store

Slide 26

Slide 26 text

Store

Slide 27

Slide 27 text

Component

Slide 28

Slide 28 text

Flux Keeps Things Predictable

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Today React with (Re)Flux Build all the things • React • Reflux • Babel • Webpack • npm • Idea of components • A flavor of Flux • ES6 to 5 transpiler • Module Bundler • No more bower!

Slide 31

Slide 31 text

Thank you