Submit Search
Upload
Frontin' Like a Back-er: A Guide to React and Flux Patterns
•
18 likes
•
10,571 views
AI-enhanced title
Frank de Jonge
Follow
Apple back-end workflows in front-end code with React and Flux.
Read less
Read more
Software
Technology
Report
Share
Report
Share
1 of 91
Download now
Download to read offline
Recommended
Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015
Konstantin Kudryashov
Min-Maxing Software Costs
Min-Maxing Software Costs
Konstantin Kudryashov
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
Konstantin Kudryashov
Rich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 Application
Kirill Chebunin
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4Developers
Kacper Gunia
The IoC Hydra
The IoC Hydra
Kacper Gunia
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing Strategies
CiaranMcNulty
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
Kacper Gunia
Recommended
Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015
Konstantin Kudryashov
Min-Maxing Software Costs
Min-Maxing Software Costs
Konstantin Kudryashov
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
Konstantin Kudryashov
Rich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 Application
Kirill Chebunin
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4Developers
Kacper Gunia
The IoC Hydra
The IoC Hydra
Kacper Gunia
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing Strategies
CiaranMcNulty
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
Kacper Gunia
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Visual Engineering
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
Łukasz Chruściel
Zero to SOLID
Zero to SOLID
Vic Metcalfe
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Colin O'Dell
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2
Kacper Gunia
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Kacper Gunia
PHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the tests
Michelangelo van Dam
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
Daniel Knell
QA for PHP projects
QA for PHP projects
Michelangelo van Dam
Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
Kacper Gunia
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
Denis Ristic
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDD
Aleix Vergés
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
Guy Royse
06 jQuery #burningkeyboards
06 jQuery #burningkeyboards
Denis Ristic
Backbone js
Backbone js
rstankov
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
jQuery from the very beginning
jQuery from the very beginning
Anis Ahmad
Headless Js Testing
Headless Js Testing
Brian Moschel
PHPunit and you
PHPunit and you
markstory
New in php 7
New in php 7
Vic Metcalfe
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
wpnepal
Dependency Management with RequireJS
Dependency Management with RequireJS
Aaronius
More Related Content
What's hot
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Visual Engineering
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
Łukasz Chruściel
Zero to SOLID
Zero to SOLID
Vic Metcalfe
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Colin O'Dell
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2
Kacper Gunia
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Kacper Gunia
PHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the tests
Michelangelo van Dam
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
Daniel Knell
QA for PHP projects
QA for PHP projects
Michelangelo van Dam
Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
Kacper Gunia
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
Denis Ristic
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDD
Aleix Vergés
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
Guy Royse
06 jQuery #burningkeyboards
06 jQuery #burningkeyboards
Denis Ristic
Backbone js
Backbone js
rstankov
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
jQuery from the very beginning
jQuery from the very beginning
Anis Ahmad
Headless Js Testing
Headless Js Testing
Brian Moschel
PHPunit and you
PHPunit and you
markstory
New in php 7
New in php 7
Vic Metcalfe
What's hot
(20)
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
Zero to SOLID
Zero to SOLID
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
PHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the tests
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
QA for PHP projects
QA for PHP projects
Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDD
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
06 jQuery #burningkeyboards
06 jQuery #burningkeyboards
Backbone js
Backbone js
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
jQuery from the very beginning
jQuery from the very beginning
Headless Js Testing
Headless Js Testing
PHPunit and you
PHPunit and you
New in php 7
New in php 7
Similar to Frontin' Like a Back-er: A Guide to React and Flux Patterns
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
wpnepal
Dependency Management with RequireJS
Dependency Management with RequireJS
Aaronius
Ditching JQuery
Ditching JQuery
howlowck
20150516 modern web_conf_tw
20150516 modern web_conf_tw
Tse-Ching Ho
Introduction to jQuery
Introduction to jQuery
Nagaraju Sangam
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
Building Large jQuery Applications
Building Large jQuery Applications
Rebecca Murphey
Javascript Frameworks for Joomla
Javascript Frameworks for Joomla
Luke Summerfield
jQuery Fundamentals
jQuery Fundamentals
Doncho Minkov
J query training
J query training
FIS - Fidelity Information Services
Rails is not just Ruby
Rails is not just Ruby
Marco Otte-Witte
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React
Robert DeLuca
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
Android Best Practices
Android Best Practices
Yekmer Simsek
Asynchronous Interfaces
Asynchronous Interfaces
maccman
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
Constantin Titarenko
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta
jQuery Best Practice
jQuery Best Practice
chandrashekher786
Clean Javascript
Clean Javascript
Ryunosuke SATO
JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼
Sukjoon Kim
Similar to Frontin' Like a Back-er: A Guide to React and Flux Patterns
(20)
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
Dependency Management with RequireJS
Dependency Management with RequireJS
Ditching JQuery
Ditching JQuery
20150516 modern web_conf_tw
20150516 modern web_conf_tw
Introduction to jQuery
Introduction to jQuery
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
Building Large jQuery Applications
Building Large jQuery Applications
Javascript Frameworks for Joomla
Javascript Frameworks for Joomla
jQuery Fundamentals
jQuery Fundamentals
J query training
J query training
Rails is not just Ruby
Rails is not just Ruby
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
Android Best Practices
Android Best Practices
Asynchronous Interfaces
Asynchronous Interfaces
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
jQuery Best Practice
jQuery Best Practice
Clean Javascript
Clean Javascript
JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼
Recently uploaded
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio, Inc.
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Alberto González Trastoy
What is Binary Language? Computer Number Systems
What is Binary Language? Computer Number Systems
JheuzeDellosa
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
MyIntelliSource, Inc.
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
kalichargn70th171
DNT_Corporate presentation know about us
DNT_Corporate presentation know about us
Dynamic Netsoft
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
Wave PLM
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
shikhaohhpro
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
VitsRangannavar
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
AxelRicardoTrocheRiq
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
Fatema Valibhai
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
kellynguyen01
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
MyIntelliSource, Inc.
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
bodapatigopi8531
Professional Resume Template for Software Developers
Professional Resume Template for Software Developers
Vinodh Ram
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
Ortus Solutions, Corp
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
OnePlan Solutions
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
Frank van der Linden
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
Wave PLM
Recently uploaded
(20)
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
What is Binary Language? Computer Number Systems
What is Binary Language? Computer Number Systems
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
DNT_Corporate presentation know about us
DNT_Corporate presentation know about us
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
Professional Resume Template for Software Developers
Professional Resume Template for Software Developers
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
Frontin' Like a Back-er: A Guide to React and Flux Patterns
1.
Frontin' Like A Back-er by @frankdejonge
2.
The PHP League Flysystem
3.
2 million downloads,
thank you!
4.
5.
6.
7.
There's no other option
than using JavaScript. - most of my friends
8.
JavaScript is a means
to an end. - almost all of my friends
9.
If JavaScript is required,
I'll hire somebody. - my friends who have companies
10.
If we hate
something, why do we do it?
11.
We all like
the result: Snappy UI / UX
12.
I made a
server browser do this!
13.
14.
Loving JavaScript Hating JavaScript Dealing
with JavaScript
15.
Take a step
back. React Reflect
16.
$(window).load(function () { $('a.external-link').on('click',
function clickHandler (e) { e.preventDefault(); if (confirm('Really?')) { $(this).off('click', clickHandler).click(); } }); });
17.
This is not
separation of concerns. <a class="hide-me">Click and I'll disappear</a> <script type="application/javascript"> $('a.hide_me').on('click', function (e) { e.preventDefault(); $(this).hide(); }); </script> It's error-prone.
18.
Result driven approach. Just enough
code to make it work.
19.
Looks good at the
front.
20.
Not so pretty at
the back.
21.
Not good enough. Doesn't
supply what I need.
22.
We need: 1. Generated
Elements; Templates? 2. XHR requests; Obviously, it's the future. 3. Data Handling; Models? Collections?
23.
Our saviours: Backbone.js, Ember.js, Angular.js
24.
Backbone.JS: You figure
it out. var DocumentRow = Backbone.View.extend({ tagName: "li", className: "document-row", events: { "click .icon": "open", }, initialize: function() { this.listenTo(this.model, "change", this.render); }, render: function() { var idea = 'I have none'; } });
25.
Angular.JS: ng-whatever. <html ng-app="phonecatApp"> <head> <script
src="bower_components/angular/angular.js"></script> <script src="js/controllers.js"></script> </head> <body ng-controller="PhoneListCtrl"> <ul> <li ng-repeat="phone in phones"> <span>{{phone.name}}</span> <p>{{phone.snippet}}</p> </li> </ul> </body> </html>
26.
Ember.JS: Handlebars /
Mustache. 23 page doc needed to explain views.
27.
You don't like
JS and HTML; here's something different.
28.
It just doesn't
work.
29.
I'm OUT! Back to
HTML.
30.
Back-end flow: Receive HTTP
Request. Process & Collect Data. Send Data => Template Engine. Send HTTP Response.
31.
Current Application State in
HTML
32.
Declarative <h1 class="hello">Hello World!</h1> Composable <div
class="hello"> <h1 class="hello__message">Hello World!</h1> </div>
33.
State & Behaviour <input
type="checkbox" checked/>
34.
Why can't it
just be like that? Just the UI Just like HTML
35.
React (JS)
36.
Define var HelloWorld =
React.createClass({ render: function () { return <h1>Hello, World!</h1>; } }); Use React.render( <HelloWorld/>, document.getElementById('root') );
37.
HTML in my
JS?! What The Fudge!
38.
#ProTip: Get over
it.
39.
JSX is just
a DSL for HTML in JavaScript
40.
Sugar var HelloWorld =
React.createClass({ render: function () { return <h1>Hello, World!<h1>; } });
41.
Desugared var HelloWorld =
React.createClass({ render: function () { return React.createElement( 'h1', {className: 'hello_world'}, 'Hello, World!' ); } });
42.
Just like HTML: It's
declarative <ModalWindow/>
43.
Just like HTML: You
can pass properties <ModalWindow opened={true}/>
44.
Just like HTML: It's
composable. <ModalWindow> <ModalHeader title="Hello World"/> <ModalBody> ... </ModalBody> </ModalWindow>
45.
It shows intent. <ProfileEditor> <Username
/> <ProfilePicture /> <Biography /> </ProfileEditor>
46.
But where do
I put my data? React is all about the bass UI.
47.
What is data
in the UI? Properties & State
48.
Properties = External Input
49.
var Badge =
React.createClass({ render: function () { return <div className="badge"> <h1>{this.props.name}</h1> <div>; } }); React.render( <Badge name="Kayla" />, document.getElementById('root') );
50.
var Badge =
React.createClass({ render: function () { var description = this.props.is_awesome ? 'is awesome!' : 'is not awesome'; return <div className="badge"> <h1>{this.props.text}</h1> <p> {description} </p> <div>; } }); React.render(<Badge name="Kayla" is_awesome={true} />, rootNode);
51.
var BadgeList =
React.createClass({ render: function () { var badges = this.props.people.map(function (person) { return <Badge key={person.id} {...person} />; }); return <div className="badge_list">{badges}<div>; } }); React.render(<BadgeList people={peopleCollection} />, rootNode);
52.
State = Internal
53.
var Toggle =
React.createClass({ getInitialState: function () { return { completed: false }; }, render: function () { var className = this.state.completed ? 'toggle--completed' : 'toggle'; return <div className={className} />; } });
54.
var Toggle =
React.createClass({ getInitialState: function () { return { completed: false }; }, onClick: function () { this.setState({completed: ! this.state.completed}); }, render: function () { var className = this.state.completed ? 'toggle--completed' : 'toggle'; return <div onClick={this.onClick} className={className} />; } });
55.
Nice but what
about MY data?
56.
Back-end data flow: 1.
Receive an HTTP request. 2. Process + Get relevant data. 3. Respond with a rendered view.
57.
Back-end data flow: 1.
Action (intention) 2. Domain (business stuff) 3. Response (json/html/ ... xml?)
58.
How does this
map to JavaScript / React?
59.
Front-end data flow: 1.
Action (intention) 2. Domain (?) 3. Response (React)
60.
Front-end data flow: 1.
Action (intention) 2. Store / Services (data layer) 3. Response (React)
61.
Stores hold the application
state.
62.
Services interact with APIs.
63.
64.
Flux
65.
Flux is only
a pattern There are many implementations already.
66.
Alt.js Actions & Stores
67.
/actions/ /stores/ /components/
68.
69.
/alt.js /actions/TodoActions.js /stores/TodoStore.js /components/TodoApplication.js /components/TodoList.js
70.
71.
72.
import Alt from
'alt'; let alt = new Alt(); export default alt;
73.
// actions/TodoActions.js import alt
from '../alt'; class TodoActions { createTodo (task) { this.dispatch({ task }); } } export default alt.createActions(TodoActions);
74.
// stores/TodoStore.js import alt
from '../alt'; import TodoActions from '../actions/TodoActions'; class TodoStore { constructor() { this.todos = []; this.bindListeners({ handleCreatedTodo: TodoActions.CREATE_TODO }); } handleCreatedTodo (todo) { this.todos.push(todo); } } export default alt.createStore(TodoStore, 'TodoStore');
75.
import React from
'react'; var TodoApplication = React.createClass({ render() { var todoList = this.state.todos.map(function (todo, index) { return <li key={index}>{todo.task}</li>; }); return <div className="todos"> <ul className="todo__list"> {todoList} </ul> <input type="text"/> </div>; } });
76.
import TodoStore from
'../stores/TodoStore'; var TodoApplication = React.createClass({ componentWillMount () { TodoStore.listen(this.handleChange); } componentWillUnmount () { TodoStore.unlisten(this.handleChange); } handleChange (state) { this.setState(state); } getInitialState() { return TodoStore.getState(); } });
77.
var TodoApplication =
React.createClass({ render() { var todoList = this.state.todos.map(function (todo, index) { return <li key={index}>{todo.task}</li>; }); return <div className="todos"> <ul className="todo__list"> {todoList} </ul> <input type="text"/> </div>; } });
78.
var TodoList =
React.createClass({ render() { var todoList = this.props.todos.map(function (todo, index) { return <li key={index}>{todo.task}</li>; }); return <ul className="todo__list"> {todoList} </ul>; } });
79.
import TodoList from
'./TodoList'; var TodoApplication = React.createClass({ render() { return <div className="todos"> <TodoList todos={this.state.todos} /> <input type="text"/> </div>; } });
80.
import TodoList from
'./TodoList'; import TodoActions from '../actions/TodoActions'; var TodoApplication = React.createClass({ handleCreateTodo (event) { if (event.keyCode !== 13) return; var task = event.target.value; TodoAction.createTodo(task); } render() { return <div className="todos"> <TodoList todos={this.state.todos} /> <input type="text" onKeyDown={this.handleCreateTodo}/> </div>; } });
81.
So, what about
my Laravel App?
82.
// routes.php $app->post('/todos', function
(Request $request) { $todo = $request->json()->all(); // Store the TODO return new JsonResponse($todo->all()); });
83.
import alt from
'../alt'; import TodoActions from '../actions/TodoActions'; class TodoStore { handleCreatedTodo (todo) { fetch('/todos', { method: 'post', body: JSON.stringify(todo) }).then((response) => { this.todos.push(response.json()); this.emitChange(); }); } } export default alt.createStore(TodoStore, 'TodoStore');
84.
What do we
know so far?
85.
Writing front-end code,
like back-end code. It's all about data-flow.
86.
Intent is everything.
87.
Complexity should be
facilitated. Choose a tool that supports it.
88.
89.
React can run on
the server.
90.
Declarative UI across the
board.
91.
Thank you for your
time!
Download now