SlideShare a Scribd company logo
A J O U R N E Y W I T H R E A C T
TA S V E E R S I N G H
@ t a z s i n g h
A Journey with React
A Journey with React
A Journey with React
3 A P P S
– M I K E H O U R A H I N E
“You can learn trigonometry, physics, C++, and DirectX to make a video game.
Or you can make a video game and learn DirectX, C++, physics, and
trigonometry.”
0
100
Number of times you’ve built a similar app
1 2 3 4 5 6 7 ...
Quality
Mistakes Made
A P P # 1 - R E A C T A S A T E M P L AT I N G E N G I N E
• Server side application framework
• Nashorn JavaScript engine for Java 8
• Vert.x 2.3 - Polyglot Event-Driven Messaging
• Innovative Router
• React to describe HTML
A P P # 2 - F L U X
A Journey with React
A Journey with React
A Journey with React
M
C
C
C
C
V
V
V
V
M
M
C
C
C
C
V
V
V
V
M
A Journey with React
A P P # 2 - F L U X
• My first iteration relied on my experience from MVC
• Business logic resides in Models/Stores
• Fat models, skinny controllers
• Models/Stores make AJAX calls
• Actions were very light weight notifications to the Stores
function signInUser(username, password) {
Dispatcher.dispatch({
type: ActionTypes.USER_SIGN_IN
, username: username
, password: password
});
}
class UserStore extends EventEmitter {
currentUser = null;
dispatchToken = Dispatcher.register((action) => {
switch(action.type) {
case ActionTypes.USER_SIGN_IN:
fetchUser(action.username, action.password).then(
(response) => {
this.currentUser = response.user;
this.emit(“change”);
});
}
});
}
function getState() {
return { currentUser: UserStore.currentUser }
}
class SignInComponent extends React.Component {
state = getState();
handleStateChange() { this.setState(getState()); }
componentDidMount() { UserStore.on(“change”, this.handleStateChange); }
componentWillUnmount() {
UserStore.removeListener(“change”, this.handleStateChange);
}
handleAuth(event) { signInUser(prompt(“What’s your username?”), prompt(“What’s your
password?”)); }
render() {
if(!this.state.currentUser)
return <a onClick={this.handleAuth}>Click here to sign in</a>;
else
return <p>You’re signed in as {this.state.currentUser.name}</p>;
}
}
A P P # 2 - F L U X - F I R S T I T E R AT I O N
• Facebook’s Dispatcher does not allow you to dispatch from a dispatch
• Difficult to compose application flow
• How do you handle errors?
• Relies on the Global State of ActionTypes
• Views worked great!
N E X T I T E R AT I O N
T RY C O M P O S I N G A C T I O N S
class SignInUser extends BaseAction {
constructor(username, password, alreadySignedInUser) {
this.username = username;
this.password = password;
this.alreadySignedInUser = alreadySignedInUser;
if(!this.alreadySignedInUser) this.authUser();
}
authUser() {
fetchUser(this.username, this.password).then(
(newUser) => { new SignInSuccess(newUser); }
, (errors) => { new SignInFailure(errors); }
);
}
A Journey with React
class SignInUser extends BaseAction {
constructor(username, password, alreadySignedInUser) {
this.username = username;
this.password = password;
this.alreadySignedInUser = alreadySignedInUser;
if(!this.alreadySignedInUser) this.authUser();
}
authUser() {
fetchUser(this.username, this.password).then(
(newUser) => { new SignInSuccess(newUser); }
, (errors) => { new SignInFailure(errors); }
);
}
class SignInSuccess
extends BaseAction {
constructor(newUser) {
this.newUser =
newUser;
this.dispatch();
}
}
class SignInFailure
extends BaseAction {
constructor(errors) {
this.errors = errors;
this.dispatch();
new
FlashMessage(“Could not
sign in”);
}
}
class UserStore extends EventEmitter {
currentUser = null;
dispatchToken = Dispatcher.register((action) => {
switch(action.constructor) {
case SignInSuccess:
this.currentUser = action.newUser;
this.emit(“change”);
}
});
}
A P P # 2 - F L U X - 2 N D I T E R AT I O N
• Eliminates the “dispatching from a dispatch” problem
• Stores are synchronous
• Very easy to compose the flow of your application by composing actions
• Eliminated Global State of ActionTypes
• Extremely scalable solution
• Easy to test
• In a later iteration, dropped in WebPack
A P P # 3 - B R O C H U R E W E B S I T E
A P P # 3 - B R O C H U R E W E B S I T E
• SEO is paramount
• AJAX is bad for SEO
• Performant on Desktop and Mobile
• Server Side Rendered
• Incremental Loading
• Introduce server side developers to client side technologies
• ES6/ES2015 via Babel
• React + Flux + WebPack
A P P # 3 - B R O C H U R E W E B S I T E
• Server side React + Server side Flux
• WebPack manages front end assets, inlining, and chunking
• Incremental loading by chunking
• Reduce number of web requests by inlining
• Koa.js serves the application and handles routing
0
100
Number of times you’ve built a similar app
1 2 3 4 5 6 7 ...
Quality
Mistakes Made
0
100
Number of times you’ve built a similar app
1 2 3 4 5 6 7 ...
Quality
Mistakes Made
0
100
Number of times you’ve built a similar app
1 2 3 4 5 6 7 ...
Quality
Mistakes Made
A Journey with React
G R I F F I N . J S
G R I F F I N . J S
• Includes everything I’ve learnt and more
• Facebook’s Dispatcher
• React Views
• Griffin Actions - Same as previous examples
• Redux Stores w/ Griffin Connector to Views
class UserStore extends EventEmitter {
currentUser = null;
dispatchToken = Dispatcher.register((payload) => {
switch(payload.constructor) {
case SignInSuccess:
this.currentUser = payload.newUser;
this.emit(“change”);
}
});
}
class UserStore extends GriffinStore {
reducer(state = null, action) => {
switch(action.constructor) {
case SignInSuccess:
return payload.newUser;
default:
return state;
}
});
}
function getState() {
return { currentUser: UserStore.currentUser }
}
class SignInComponent extends React.Component {
state = getState();
handleStateChange() { this.setState(getState()); }
componentDidMount() { UserStore.on(“change”, this.handleStateChange); }
componentWillUnmount() {
UserStore.removeListener(“change”, this.handleStateChange);
}
handleAuth(event) { signInUser(prompt(“What’s your username?”), prompt(“What’s your
password?”)); }
render() {
if(!this.state.currentUser)
return <a onClick={this.handleAuth}>Click here to sign in</a>;
else
return <p>You’re signed in as {this.state.currentUser.name}</p>;
}
}
@connect({ currentUser: UserStore })
class SignInComponent extends React.Component {
handleAuth(event) { signInUser(prompt(“What’s your
username?”), prompt(“What’s your password?”)); }
render() {
if(!this.props.currentUser)
return <a onClick={this.handleAuth}>Click here to
sign in</a>;
else
return <p>You’re signed in as
{this.props.currentUser.name}</p>;
}
}
R E A C T D E P E N D E N C Y I N J E C T I O N
• Using props to pass in external data is similar to Angular’s dependency
injection
• Only use state to manage internal component state
• <SignInComponent currentUser={{name: “Mock User!”}} />
• <SignInComponent currentUser={null} />
R E A C T R O U T E R
R E A C T R O U T E R
• Amazing routing solution - Inspired heavily by Ember’s router
• Ember has an excellent router
• Uses JSX or JSON to describe routes and nested routes
• React Component will be loaded by a Route
• Version 1.0 has lazy loading of routes and components
• Better Server Side Rendering
React.render((
<Router>
<Route path="/" component={App}>
<Route path="about" component={About} />
<Route path="inbox" component={Inbox}>
<Route path="messages/:id"
component={Message} />
</Route>
</Route>
</Router>
), document.body)
.
├── AppComponent.js => /
├── AboutComponent.js => /about
├── InboxComponent.js => /inbox
└── MessageComponent.js => /inbox/messages/:id
.
├── AppComponent.js => /
├── AboutComponent.js => /about
├── InboxComponent.js => /inbox
└── inbox
   └── MessageComponent.js => /inbox/messages/:id
.
├── index.js => /
├── about
│   └── index.js => /about
└── inbox
   ├── index.js => /inbox
   └── messages
   └── @id
   └── index.js => /inbox/messages/:id
.
├── index.js => /
├── about
│   └── index.js => /about
└── inbox
   ├── DeleteMessage.js
   ├── GetMessages.js
   ├── MessageStore.js
   ├── index.js => /inbox
   └── messages
   └── @id
   └── index.js => /inbox/messages/:id
React.render((
<Router>
<Route path="/" component={App}>
<Route path="about" component={About} />
<Route path="inbox" component={Inbox}>
<Route path="messages/:id"
component={Message} />
</Route>
</Route>
</Router>
), document.body)
G R I F F I N F I L E S Y S T E M B A S E D R O U T I N G
• Easy to initialize your app
• import myApp from “griffin!.”;

myApp({ /* any griffin options here */});
• Easy to mount other apps
• import anotherApp from “griffin!/path/to/app”;

anotherApp({ /* griffin options */});
U N I V E R S A L A P P S W I T H W E B PA C K
• Everything goes through WebPack
• Based on James Long’s excellent “Backend Apps with WebPack” posts
• On the server, it ignores CSS, images, etc.
• WebPack enables lazy-loading of application chunks
• Incrementally load Griffin routes
• Include common modules with initial payload
G R I F F I N . J S S TAT U S
• Almost ready for release
• Planning to release in the next few months
• I’m currently rewriting the WebPack incremental file-system based routing
• Last core item remaining before release
0
100
Number of times you’ve built a similar app
1 2 3 4 5 6 7 ...
Quality
Mistakes Made
T H A N K Y O U
@ t a z s i n g h

More Related Content

PDF
WordPress Admin UI - Future Proofing Your Admin Pages
PDF
2012.sandiego.wordcamp
PDF
Creating 'Vuetiful' Data-Driven User Interfaces
PDF
Secure WordPress Development Practices
PDF
Advantages of Vue JS - Presented at the Rangle.io VueJS Meetup in January
PDF
Advanced redux
PDF
jQuery Presentation to Rails Developers
WordPress Admin UI - Future Proofing Your Admin Pages
2012.sandiego.wordcamp
Creating 'Vuetiful' Data-Driven User Interfaces
Secure WordPress Development Practices
Advantages of Vue JS - Presented at the Rangle.io VueJS Meetup in January
Advanced redux
jQuery Presentation to Rails Developers

What's hot (20)

PDF
Integrating React.js with PHP projects
PDF
ReactJS
PDF
Kakunin E2E framework showcase
PDF
Introduction to ReactJS and Redux
PDF
Reduxing like a pro
PDF
Rails 3: Dashing to the Finish
PPT
JSON Rules Language
PPTX
React with Redux
PDF
jQuery in 15 minutes
PDF
Extending Redux in the Server Side
PPTX
Angular Tutorial Freshers and Experienced
KEY
amsterdamjs - jQuery 1.5
PPT
jQuery 1.7 Events
PDF
Take My Logs. Please!
PDF
Frontin like-a-backer
PDF
Ditching JQuery
KEY
JavaScript Testing for Rubyists
PDF
React.js or why DOM finally makes sense
PDF
High Performance web apps in Om, React and ClojureScript
PDF
JavaScript Promise
Integrating React.js with PHP projects
ReactJS
Kakunin E2E framework showcase
Introduction to ReactJS and Redux
Reduxing like a pro
Rails 3: Dashing to the Finish
JSON Rules Language
React with Redux
jQuery in 15 minutes
Extending Redux in the Server Side
Angular Tutorial Freshers and Experienced
amsterdamjs - jQuery 1.5
jQuery 1.7 Events
Take My Logs. Please!
Frontin like-a-backer
Ditching JQuery
JavaScript Testing for Rubyists
React.js or why DOM finally makes sense
High Performance web apps in Om, React and ClojureScript
JavaScript Promise
Ad

Viewers also liked (20)

PDF
The Working Dead
PDF
Creating a Smile Worthy World
PPTX
Your UX is not my UX
PDF
Gamify Your Life – My Epic Quest of Awesome - Eric Boyd
PDF
Reinvent Your Creative Process with Collaborative Hackathons
PDF
A New Era for Animators
PDF
Design to the Future
PDF
PageCloud Reimagines The Future of Website Creation with Craig Fitzpatrick
PDF
The Shifting Nature of FED Role
PDF
Getting to Know Grunt By Writing Your Own Plugin
PDF
(Re)aligning The Way 400,000 People Think
PDF
Functional Web Development
PDF
Open Sourcing the Secret Sauce
PDF
Fitc whats new in es6 for web devs
PDF
Upgrading the Web with Douglas Crockford @ FITC's Web Unleashed 2015
PDF
Embedding Cognitive Innovation in Design
PDF
Graphic Designer to Object Designer: Your 3D Printing Evolution
PDF
The Future is in Pieces
PDF
Front-end Tools: Sifting Through the Madness
PDF
The Giddiest Kipper
The Working Dead
Creating a Smile Worthy World
Your UX is not my UX
Gamify Your Life – My Epic Quest of Awesome - Eric Boyd
Reinvent Your Creative Process with Collaborative Hackathons
A New Era for Animators
Design to the Future
PageCloud Reimagines The Future of Website Creation with Craig Fitzpatrick
The Shifting Nature of FED Role
Getting to Know Grunt By Writing Your Own Plugin
(Re)aligning The Way 400,000 People Think
Functional Web Development
Open Sourcing the Secret Sauce
Fitc whats new in es6 for web devs
Upgrading the Web with Douglas Crockford @ FITC's Web Unleashed 2015
Embedding Cognitive Innovation in Design
Graphic Designer to Object Designer: Your 3D Printing Evolution
The Future is in Pieces
Front-end Tools: Sifting Through the Madness
The Giddiest Kipper
Ad

Similar to A Journey with React (20)

PDF
Chris Wilson: Progressive Web Apps
PDF
Using ReasonML For Your Next JavaScript Project
PDF
Progressive Enhancement for JavaScript Apps
PDF
Server side rendering with React and Symfony
PDF
A Blog About Using State in Next.js: Valuable Insights
PPT
Week 8
PDF
N Things You Don't Want to Repeat in React Native
KEY
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
PDF
Primefaces Nextgen Lju
PDF
Primefaces Nextgen Lju
PDF
Metrics-Driven Engineering
PDF
Using React, Redux and Saga with Lottoland APIs
PDF
Gmaps Railscamp2008
PDF
SproutCore and the Future of Web Apps
KEY
Plone Interactivity
PDF
Advanced React Component Patterns - ReactNext 2018
PPTX
Async Redux Actions With RxJS - React Rally 2016
PPTX
Implementation of GUI Framework part3
KEY
Jarv.us Showcase — SenchaCon 2011
PPTX
How to perform debounce in react
Chris Wilson: Progressive Web Apps
Using ReasonML For Your Next JavaScript Project
Progressive Enhancement for JavaScript Apps
Server side rendering with React and Symfony
A Blog About Using State in Next.js: Valuable Insights
Week 8
N Things You Don't Want to Repeat in React Native
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
Primefaces Nextgen Lju
Primefaces Nextgen Lju
Metrics-Driven Engineering
Using React, Redux and Saga with Lottoland APIs
Gmaps Railscamp2008
SproutCore and the Future of Web Apps
Plone Interactivity
Advanced React Component Patterns - ReactNext 2018
Async Redux Actions With RxJS - React Rally 2016
Implementation of GUI Framework part3
Jarv.us Showcase — SenchaCon 2011
How to perform debounce in react

More from FITC (20)

PPTX
Cut it up
PDF
Designing for Digital Health
PDF
Profiling JavaScript Performance
PPTX
Surviving Your Tech Stack
PDF
How to Pitch Your First AR Project
PDF
Start by Understanding the Problem, Not by Delivering the Answer
PDF
Cocaine to Carrots: The Art of Telling Someone Else’s Story
PDF
Everyday Innovation
PDF
HyperLight Websites
PDF
Everything is Terrifying
PDF
Post-Earth Visions: Designing for Space and the Future Human
PDF
The Rise of the Creative Social Influencer (and How to Become One)
PDF
East of the Rockies: Developing an AR Game
PDF
Creating a Proactive Healthcare System
PDF
World Transformation: The Secret Agenda of Product Design
PDF
The Power of Now
PDF
High Performance PWAs
PDF
Rise of the JAMstack
PDF
From Closed to Open: A Journey of Self Discovery
PDF
Projects Ain’t Nobody Got Time For
Cut it up
Designing for Digital Health
Profiling JavaScript Performance
Surviving Your Tech Stack
How to Pitch Your First AR Project
Start by Understanding the Problem, Not by Delivering the Answer
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Everyday Innovation
HyperLight Websites
Everything is Terrifying
Post-Earth Visions: Designing for Space and the Future Human
The Rise of the Creative Social Influencer (and How to Become One)
East of the Rockies: Developing an AR Game
Creating a Proactive Healthcare System
World Transformation: The Secret Agenda of Product Design
The Power of Now
High Performance PWAs
Rise of the JAMstack
From Closed to Open: A Journey of Self Discovery
Projects Ain’t Nobody Got Time For

Recently uploaded (20)

PPT
tcp ip networks nd ip layering assotred slides
PPTX
Digital Literacy And Online Safety on internet
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PPTX
Introduction to Information and Communication Technology
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Smart Home Technology for Health Monitoring (www.kiu.ac.ug)
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPT
Ethics in Information System - Management Information System
tcp ip networks nd ip layering assotred slides
Digital Literacy And Online Safety on internet
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Introduction to Information and Communication Technology
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Decoding a Decade: 10 Years of Applied CTI Discipline
Slides PDF The World Game (s) Eco Economic Epochs.pdf
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Cloud-Scale Log Monitoring _ Datadog.pdf
Smart Home Technology for Health Monitoring (www.kiu.ac.ug)
SAP Ariba Sourcing PPT for learning material
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Module 1 - Cyber Law and Ethics 101.pptx
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Job_Card_System_Styled_lorem_ipsum_.pptx
PptxGenJS_Demo_Chart_20250317130215833.pptx
introduction about ICD -10 & ICD-11 ppt.pptx
WebRTC in SignalWire - troubleshooting media negotiation
Ethics in Information System - Management Information System

A Journey with React

  • 1. A J O U R N E Y W I T H R E A C T TA S V E E R S I N G H @ t a z s i n g h
  • 5. 3 A P P S
  • 6. – M I K E H O U R A H I N E “You can learn trigonometry, physics, C++, and DirectX to make a video game. Or you can make a video game and learn DirectX, C++, physics, and trigonometry.”
  • 7. 0 100 Number of times you’ve built a similar app 1 2 3 4 5 6 7 ... Quality Mistakes Made
  • 8. A P P # 1 - R E A C T A S A T E M P L AT I N G E N G I N E • Server side application framework • Nashorn JavaScript engine for Java 8 • Vert.x 2.3 - Polyglot Event-Driven Messaging • Innovative Router • React to describe HTML
  • 9. A P P # 2 - F L U X
  • 16. A P P # 2 - F L U X • My first iteration relied on my experience from MVC • Business logic resides in Models/Stores • Fat models, skinny controllers • Models/Stores make AJAX calls • Actions were very light weight notifications to the Stores
  • 17. function signInUser(username, password) { Dispatcher.dispatch({ type: ActionTypes.USER_SIGN_IN , username: username , password: password }); }
  • 18. class UserStore extends EventEmitter { currentUser = null; dispatchToken = Dispatcher.register((action) => { switch(action.type) { case ActionTypes.USER_SIGN_IN: fetchUser(action.username, action.password).then( (response) => { this.currentUser = response.user; this.emit(“change”); }); } }); }
  • 19. function getState() { return { currentUser: UserStore.currentUser } } class SignInComponent extends React.Component { state = getState(); handleStateChange() { this.setState(getState()); } componentDidMount() { UserStore.on(“change”, this.handleStateChange); } componentWillUnmount() { UserStore.removeListener(“change”, this.handleStateChange); } handleAuth(event) { signInUser(prompt(“What’s your username?”), prompt(“What’s your password?”)); } render() { if(!this.state.currentUser) return <a onClick={this.handleAuth}>Click here to sign in</a>; else return <p>You’re signed in as {this.state.currentUser.name}</p>; } }
  • 20. A P P # 2 - F L U X - F I R S T I T E R AT I O N • Facebook’s Dispatcher does not allow you to dispatch from a dispatch • Difficult to compose application flow • How do you handle errors? • Relies on the Global State of ActionTypes • Views worked great!
  • 21. N E X T I T E R AT I O N T RY C O M P O S I N G A C T I O N S
  • 22. class SignInUser extends BaseAction { constructor(username, password, alreadySignedInUser) { this.username = username; this.password = password; this.alreadySignedInUser = alreadySignedInUser; if(!this.alreadySignedInUser) this.authUser(); } authUser() { fetchUser(this.username, this.password).then( (newUser) => { new SignInSuccess(newUser); } , (errors) => { new SignInFailure(errors); } ); }
  • 24. class SignInUser extends BaseAction { constructor(username, password, alreadySignedInUser) { this.username = username; this.password = password; this.alreadySignedInUser = alreadySignedInUser; if(!this.alreadySignedInUser) this.authUser(); } authUser() { fetchUser(this.username, this.password).then( (newUser) => { new SignInSuccess(newUser); } , (errors) => { new SignInFailure(errors); } ); }
  • 25. class SignInSuccess extends BaseAction { constructor(newUser) { this.newUser = newUser; this.dispatch(); } } class SignInFailure extends BaseAction { constructor(errors) { this.errors = errors; this.dispatch(); new FlashMessage(“Could not sign in”); } }
  • 26. class UserStore extends EventEmitter { currentUser = null; dispatchToken = Dispatcher.register((action) => { switch(action.constructor) { case SignInSuccess: this.currentUser = action.newUser; this.emit(“change”); } }); }
  • 27. A P P # 2 - F L U X - 2 N D I T E R AT I O N • Eliminates the “dispatching from a dispatch” problem • Stores are synchronous • Very easy to compose the flow of your application by composing actions • Eliminated Global State of ActionTypes • Extremely scalable solution • Easy to test • In a later iteration, dropped in WebPack
  • 28. A P P # 3 - B R O C H U R E W E B S I T E
  • 29. A P P # 3 - B R O C H U R E W E B S I T E • SEO is paramount • AJAX is bad for SEO • Performant on Desktop and Mobile • Server Side Rendered • Incremental Loading • Introduce server side developers to client side technologies • ES6/ES2015 via Babel • React + Flux + WebPack
  • 30. A P P # 3 - B R O C H U R E W E B S I T E • Server side React + Server side Flux • WebPack manages front end assets, inlining, and chunking • Incremental loading by chunking • Reduce number of web requests by inlining • Koa.js serves the application and handles routing
  • 31. 0 100 Number of times you’ve built a similar app 1 2 3 4 5 6 7 ... Quality Mistakes Made
  • 32. 0 100 Number of times you’ve built a similar app 1 2 3 4 5 6 7 ... Quality Mistakes Made
  • 33. 0 100 Number of times you’ve built a similar app 1 2 3 4 5 6 7 ... Quality Mistakes Made
  • 35. G R I F F I N . J S
  • 36. G R I F F I N . J S • Includes everything I’ve learnt and more • Facebook’s Dispatcher • React Views • Griffin Actions - Same as previous examples • Redux Stores w/ Griffin Connector to Views
  • 37. class UserStore extends EventEmitter { currentUser = null; dispatchToken = Dispatcher.register((payload) => { switch(payload.constructor) { case SignInSuccess: this.currentUser = payload.newUser; this.emit(“change”); } }); }
  • 38. class UserStore extends GriffinStore { reducer(state = null, action) => { switch(action.constructor) { case SignInSuccess: return payload.newUser; default: return state; } }); }
  • 39. function getState() { return { currentUser: UserStore.currentUser } } class SignInComponent extends React.Component { state = getState(); handleStateChange() { this.setState(getState()); } componentDidMount() { UserStore.on(“change”, this.handleStateChange); } componentWillUnmount() { UserStore.removeListener(“change”, this.handleStateChange); } handleAuth(event) { signInUser(prompt(“What’s your username?”), prompt(“What’s your password?”)); } render() { if(!this.state.currentUser) return <a onClick={this.handleAuth}>Click here to sign in</a>; else return <p>You’re signed in as {this.state.currentUser.name}</p>; } }
  • 40. @connect({ currentUser: UserStore }) class SignInComponent extends React.Component { handleAuth(event) { signInUser(prompt(“What’s your username?”), prompt(“What’s your password?”)); } render() { if(!this.props.currentUser) return <a onClick={this.handleAuth}>Click here to sign in</a>; else return <p>You’re signed in as {this.props.currentUser.name}</p>; } }
  • 41. R E A C T D E P E N D E N C Y I N J E C T I O N • Using props to pass in external data is similar to Angular’s dependency injection • Only use state to manage internal component state • <SignInComponent currentUser={{name: “Mock User!”}} /> • <SignInComponent currentUser={null} />
  • 42. R E A C T R O U T E R
  • 43. R E A C T R O U T E R • Amazing routing solution - Inspired heavily by Ember’s router • Ember has an excellent router • Uses JSX or JSON to describe routes and nested routes • React Component will be loaded by a Route • Version 1.0 has lazy loading of routes and components • Better Server Side Rendering
  • 44. React.render(( <Router> <Route path="/" component={App}> <Route path="about" component={About} /> <Route path="inbox" component={Inbox}> <Route path="messages/:id" component={Message} /> </Route> </Route> </Router> ), document.body)
  • 45. . ├── AppComponent.js => / ├── AboutComponent.js => /about ├── InboxComponent.js => /inbox └── MessageComponent.js => /inbox/messages/:id
  • 46. . ├── AppComponent.js => / ├── AboutComponent.js => /about ├── InboxComponent.js => /inbox └── inbox    └── MessageComponent.js => /inbox/messages/:id
  • 47. . ├── index.js => / ├── about │   └── index.js => /about └── inbox    ├── index.js => /inbox    └── messages    └── @id    └── index.js => /inbox/messages/:id
  • 48. . ├── index.js => / ├── about │   └── index.js => /about └── inbox    ├── DeleteMessage.js    ├── GetMessages.js    ├── MessageStore.js    ├── index.js => /inbox    └── messages    └── @id    └── index.js => /inbox/messages/:id
  • 49. React.render(( <Router> <Route path="/" component={App}> <Route path="about" component={About} /> <Route path="inbox" component={Inbox}> <Route path="messages/:id" component={Message} /> </Route> </Route> </Router> ), document.body)
  • 50. G R I F F I N F I L E S Y S T E M B A S E D R O U T I N G • Easy to initialize your app • import myApp from “griffin!.”;
 myApp({ /* any griffin options here */}); • Easy to mount other apps • import anotherApp from “griffin!/path/to/app”;
 anotherApp({ /* griffin options */});
  • 51. U N I V E R S A L A P P S W I T H W E B PA C K • Everything goes through WebPack • Based on James Long’s excellent “Backend Apps with WebPack” posts • On the server, it ignores CSS, images, etc. • WebPack enables lazy-loading of application chunks • Incrementally load Griffin routes • Include common modules with initial payload
  • 52. G R I F F I N . J S S TAT U S • Almost ready for release • Planning to release in the next few months • I’m currently rewriting the WebPack incremental file-system based routing • Last core item remaining before release
  • 53. 0 100 Number of times you’ve built a similar app 1 2 3 4 5 6 7 ... Quality Mistakes Made
  • 54. T H A N K Y O U @ t a z s i n g h