SlideShare a Scribd company logo
1 of 91
Download to read offline
Frontin' Like
A Back-er
by @frankdejonge
The PHP League
Flysystem
2 million downloads, thank you!
There's no other
option than using
JavaScript.
- most of my friends
JavaScript is a
means to an end.
- almost all of my friends
If JavaScript is
required, I'll hire
somebody.
- my friends who have companies
If we hate something,
why do we do it?
We all like the result:
Snappy UI / UX
I made a server
browser do this!
Loving JavaScript
Hating JavaScript
Dealing with JavaScript
Take a step back.
React Reflect
$(window).load(function () {
$('a.external-link').on('click', function clickHandler (e) {
e.preventDefault();
if (confirm('Really?')) {
$(this).off('click', clickHandler).click();
}
});
});
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.
Result driven
approach.
Just enough code to make it work.
Looks good
at the front.
Not so pretty
at the back.
Not good enough.
Doesn't supply what I
need.
We need:
1. Generated Elements; Templates?
2. XHR requests; Obviously, it's the future.
3. Data Handling; Models? Collections?
Our saviours:
Backbone.js, Ember.js,
Angular.js
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';
}
});
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>
Ember.JS: Handlebars / Mustache.
23 page doc needed to
explain views.
You don't like JS and
HTML; here's
something different.
It just doesn't work.
I'm OUT!
Back to HTML.
Back-end flow:
Receive HTTP Request.
Process & Collect Data.
Send Data => Template Engine.
Send HTTP Response.
Current Application
State in HTML
Declarative
<h1 class="hello">Hello World!</h1>
 
Composable
<div class="hello">
<h1 class="hello__message">Hello World!</h1>
</div>
State & Behaviour
<input type="checkbox" checked/>
Why can't it just be like that?
Just the UI
Just like HTML
React (JS)
Define
var HelloWorld = React.createClass({
render: function () {
return <h1>Hello, World!</h1>;
}
});
 
Use
React.render(
<HelloWorld/>,
document.getElementById('root')
);
HTML in my JS?!
What The Fudge!
#ProTip: Get over it.
JSX is just a DSL for
HTML in JavaScript
Sugar
var HelloWorld = React.createClass({
render: function () {
return <h1>Hello, World!<h1>;
}
});
Desugared
var HelloWorld = React.createClass({
render: function () {
return React.createElement(
'h1',
{className: 'hello_world'},
'Hello, World!'
);
}
});
Just like HTML:
It's declarative
<ModalWindow/>
Just like HTML:
You can pass
properties
<ModalWindow opened={true}/>
Just like HTML:
It's composable.
<ModalWindow>
<ModalHeader title="Hello World"/>
<ModalBody>
...
</ModalBody>
</ModalWindow>
It shows intent.
<ProfileEditor>
<Username />
<ProfilePicture />
<Biography />
</ProfileEditor>
But where do I put my data?
React is all about the bass UI.
What is data in the UI?
Properties & State
Properties
=
External Input
var Badge = React.createClass({
render: function () {
return <div className="badge">
<h1>{this.props.name}</h1>
<div>;
}
});
React.render(
<Badge name="Kayla" />,
document.getElementById('root')
);
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);
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);
State
=
Internal
var Toggle = React.createClass({
getInitialState: function () {
return { completed: false };
},
render: function () {
var className = this.state.completed
? 'toggle--completed'
: 'toggle';
return <div className={className} />;
}
});
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} />;
}
});
Nice but what about
MY data?
Back-end data flow:
1. Receive an HTTP request.
2. Process + Get relevant data.
3. Respond with a rendered view.
Back-end data flow:
1. Action (intention)
2. Domain (business stuff)
3. Response (json/html/ ... xml?)
How does this map to
JavaScript / React?
Front-end data flow:
1. Action (intention)
2. Domain (?)
3. Response (React)
Front-end data flow:
1. Action (intention)
2. Store / Services (data layer)
3. Response (React)
Stores hold the
application state.
Services interact
with APIs.
 
Flux
Flux is only a pattern
There are many implementations already.
Alt.js
Actions & Stores
/actions/
/stores/
/components/
/alt.js
/actions/TodoActions.js
/stores/TodoStore.js
/components/TodoApplication.js
/components/TodoList.js
import Alt from 'alt';
let alt = new Alt();
export default alt;
// actions/TodoActions.js
import alt from '../alt';
class TodoActions {
createTodo (task) {
this.dispatch({ task });
}
}
export default alt.createActions(TodoActions);
// 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');
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>;
}
});
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();
}
});
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>;
}
});
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>;
}
});
import TodoList from './TodoList';
var TodoApplication = React.createClass({
render() {
return <div className="todos">
<TodoList todos={this.state.todos} />
<input type="text"/>
</div>;
}
});
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>;
}
});
So, what about my
Laravel App?
// routes.php
$app->post('/todos', function (Request $request) {
$todo = $request->json()->all();
// Store the TODO
return new JsonResponse($todo->all());
});
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');
What do we know so
far?
Writing front-end code, like back-end code.
It's all about data-flow.
Intent is everything.
Complexity should be facilitated.
Choose a tool that
supports it.
React can run
on the server.
Declarative UI
across the board.
Thank you for
your time!

More Related Content

What's hot

Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 

What's hot (20)

Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsSymfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Hacking 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 2November 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 CracowForget 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 testsPHPUnit 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 technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
QA for PHP projects
QA for PHP projectsQA 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!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 #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
 
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling 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 JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboards
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.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 beginningjQuery from the very beginning
jQuery from the very beginning
 
Headless Js Testing
Headless Js TestingHeadless Js Testing
Headless Js Testing
 
PHPunit and you
PHPunit and youPHPunit and you
PHPunit and you
 
New in php 7
New in php 7New in php 7
New in php 7
 

Similar to Frontin like-a-backer

Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
Aaronius
 
20150516 modern web_conf_tw
20150516 modern web_conf_tw20150516 modern web_conf_tw
20150516 modern web_conf_tw
Tse-Ching Ho
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
Luke Summerfield
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
Yekmer Simsek
 

Similar to Frontin like-a-backer (20)

Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 
Ditching JQuery
Ditching JQueryDitching JQuery
Ditching JQuery
 
20150516 modern web_conf_tw
20150516 modern web_conf_tw20150516 modern web_conf_tw
20150516 modern web_conf_tw
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
J query training
J query trainingJ query training
J query training
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfaces
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼
 

Recently uploaded

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Frontin like-a-backer