Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Bring your web application architecture to the ...
Search
Bastian Hofmann
June 11, 2015
Programming
240
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Bring your web application architecture to the next level with React.JS
Bastian Hofmann
June 11, 2015
More Decks by Bastian Hofmann
See All by Bastian Hofmann
Monitoring in Kubernetes with Prometheus and Grafana
bastianhofmann
0
360
Creating a fast Kubernetes Development Workflow
bastianhofmann
0
150
Highly available cross-region deployments with Kubernetes
bastianhofmann
1
170
From source to Kubernetes in 30 minutes
bastianhofmann
0
200
Introduction to Kubernetes
bastianhofmann
1
140
CI/CD with Kubernetes
bastianhofmann
0
250
Creating a fast Kubernetes Development Workflow
bastianhofmann
1
290
Deploying your first Micro-Service application to Kubernetes
bastianhofmann
2
210
Creating a fast Kubernetes Development Workflow
bastianhofmann
0
280
Other Decks in Programming
See All in Programming
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
どこまでゆるくて許されるのか
tk3fftk
0
520
act1-costs.pdf
sumedhbala
0
240
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.7k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
120
自作OSでスライド発表する
uyuki234
1
3.9k
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1k
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
5.1k
AIが無かった頃の素敵な出会いの話
codmoninc
1
170
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
270
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
190
Featured
See All Featured
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
190
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
660
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.7k
Code Reviewing Like a Champion
maltzj
528
40k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
390
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
470
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
410
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
240
Designing for Timeless Needs
cassininazir
1
390
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
460
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Transcript
Bring your web application to the next level with React.JS
@BastianHofmann
Let's talk about...
Application architecture
Code and component re-use
Rapid Development
Handling large code-bases
With React.js
With small and independent components
webserver HTML browser JS controller
webserver HTML browser JS Ajax controller
webserver HTML browser JS Ajax controller
de duplication ode duplication code duplication code duplication code duplication
code duplication code duplication code duplication code duplication code duplication code duplication code duplication code duplication code duplicatio code duplicat code duplic code dup code du code cod co co
So?
A few words about me
None
None
http://speakerdeck.com/u/bastianhofmann
Application architecture
many roads
None
status quo
webserver HTML browser JS Ajax controller
webserver loadbalancer pgsql memcached mongodb services
webserver
None
MVC
Duplication and only some Code re- use
We can do better
Small components over big controllers
None
None
None
None
None
None
None
None
Self contained
Can be used everywhere
JS is part of the component
CSS can be part of the component
http://facebook.github.io/react/
JavaScript UI Library
Many small, self contained, reusable components
var HelloMessage = React.createClass( { render: function () { return
<div>Hello {this.props.name}</div>; } } ); React.render(<HelloMessage name="John" />, mountNode);
var Timer = React.createClass({ getInitialState: function () { return {secs:
0}; }, tick: function () { this.setState({secs: this.state.secs + 1}); }, componentDidMount: function () { this.interval = setInterval(this.tick, 1000); }, componentWillUnmount: function () { clearInterval(this.interval); }, render: function () { return (<div> Seconds Elapsed: {this.state.secs}</div> ); } }); React.render(<Timer />, mountNode);
var TodoList = React.createClass( { render: function () { var
createItem = function (itemText) { return <li>{itemText}</li>; }; return ( <ul> {this.props.items.map(createItem)} </ul> ); } } );
var TodoApp = React.createClass({ render: function () { return (
<div> <h3>TODO</h3> <TodoList items={this.props.items} /> </div> ); } });
Getting the data in there
PHP Backend JSON React Frontend
PHP Backend JSON React Frontend
PHP Backend JSON React Frontend
PHP Backend JSON React Frontend
var TodoApp = React.createClass({ getInitialState: function () { return {items:
[…]}; }, render: function () { return ( <div> <h3>TODO</h3> <TodoList items={this.state.items} /> </div> ); } });
Problematic
Remember
Self-contained
Reusable
PHP Backend JSON React Frontend
PHP Backend JSON React Frontend
PHP Backend JSON React Frontend
Overfetching
Underfetching
Solutions
Flux Datastores
PHP Backend React Frontend Datastores
GraphQL https://gist.github.com/wincent/598fa75e22bdfa44cf47
Requirements
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Institution Menu
React Frontend
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu PHP
Backend Request Response Institution
LeftColumn Image Menu React Frontend
LeftColumn Image Menu Request Response PHP Backend
Remember: self contained
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Account
Account Account Account Account Publication1 Publication2 Publication3 Institution
Do not fetch data directly
Sssssssllllooooowww
Require stuff
http://www.infoq.com/presentations/Evolution-of-Code- Design-at-Facebook/
None
Widget Widget Widget Widget Preparer Resolver Resolver Services Connector Interfaces
Connector Implementations
Widget Widget Widget Widget Preparer Fetch Requirements Resolver Resolver Services
Connector Interfaces Connector Implementations
Widget Widget Widget Widget Preparer Resolver Resolver Services Connector Interfaces
Connector Implementations Batch requirements and pass them to resolvers
Widget Widget Widget Widget Preparer Resolver Resolver Services Connector Interfaces
Connector Implementations Call Services as effective as possible (Multi-GET,...)
Widget Widget Widget Widget Preparer Resolver Resolver Services Connector Interfaces
Connector Implementations Attach fetched data to Requirements and pass them back to the preparer
Widget Widget Widget Widget Preparer Resolver Resolver Services Connector Interfaces
Connector Implementations Distribute fetched data to the widgets that required it
public function collect() { return [ new EntityRequirement( 'account', Account::class,
['id' => $this->request->get('id')] ), ]; }
Request Cache
Multi-GET
Futures
Data dependencies within a widget
public function collect() { yield [ new EntityRequirement( 'account', Account::class,
['id' => $this->request->get('id')] ), ]; yield [ new ServiceRequirement( 'scienceDisciplines', AccountService::class, 'getScienceDisciplines', ['account' => $this->account] ) ]; }
Assembling the tree
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu PHP
Backend Request Response Institution
Widget Requirement
class PublicationKeywordSearch { public $publications; public $publicationListItems = [];
public function collect() { yield [ serviceRequirement( 'publications', PublicationService::getCall()->getByKeywords( ['virology', 'cancer'], 10, 0 ) ) ]; foreach ($this->publications as $publication) { yield new WidgetRequirement( 'publicationListItems', PublicationItem::CLASS, [ 'publicationId' => $publication->getId() ] ); } } }
class PublicationItem { public $publicationId; public $publication; public
function collect() { yield new RequestDataRequirement('publicationId'); yield [ new EntityRequirement( 'publication', Publication::class, ['id' => $this->publicationId] ) ]; } }
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution
Getting the data to React.js
public function getData() { return [ 'key' => 'value', 'other'
=> 'data', 'number' => 42, 'subComponent' => $this->subComponent, 'someArray' => [1, 2, 3], 'subComponentList' => [ $this->items[0], $this->items[1] ] ]; }
{ "ParentComponent-1234": { "component": "ParentComponent.jsx", "id": "ParentComponent-1234", "data": { "key":
"value", "other": "data", "number": 42, "subComponent": "SubComponent", "someArray": [1, 2, 3], "subComponentList": [ "ListItem-444", "ListItem-555"] } }, "SubComponent": { "component": "SubComponent.jsx", "id": "SubComponent", "data": { "boolValue": true } }, "ListItem-444": { "component": "ListItem", "id": "ListItem-444", "data": { "title": "444s title“ } }, "ListItem-555": { "component": "ListItem", "id": "ListItem-555", "data": { "title": "555s title" } } }
var React = require('react'); var SubComponent = require('SubComponent'); var ListItem
= require('ListItem'); module.exports = React.createClass( { displayName: 'ParentComponent', render: function () { var items = []; for (var key in this.props.subComponentList) { if (this.props.subComponentList.hasOwnProperty(key)) { items.push( <li> <ListItem componentId={this.props.subComponentList[key]}/> </li> ); } } return ( <div className="{this.props.key}"> <h1>{this.props.other} Hello PHP {this.props.number}</h1> <SubComponent componentId={this.props.subComponent} /> <ul>{items}</ul> </div> ); } } );
var React = require('react'); module.exports = React.createClass( { displayName:
'ListItem', render: function () { return ( <div> {this.props.title} </div> ); } } );
Server side rendering
SEO
Better user experience
Several approaches
NodeJS service
Request HTML Preparer nodeJS service PHP process Data JSON Rendered
HTML string React Hogan
Bundling
http://webpack.github.io/
None
Whoa
This looks awfully complicated to debug
None
None
Benefits
Enables developers to only focus on their components
Rapid prototyping
Easier Refactoring
Easy re-using of components
Error Handling
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu EXCEPTION
Institution
Profile Publications Publication Publication Publication LeftColumn Image Menu Institution
Experiments (A/B Testing)
Feature toggles
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution
Profile Publications Publication Publication Publication AboutMeNew LeftColumn Image Menu Institution
Caching of Components
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu <esi:include
src="..." /> Institution
Load components asynchronously
Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu <div
id="placeholder"></div> <script>loadWidget('/aboutMe', function(w) { w.render({ replace : '#placeholder' }); })</script> Institution
Conclusion?
Think about your architecture
Refactor and make it better continuously
Frontend and backend are part of the same application
Don't rewrite your whole codebase in one go
http://twitter.com/BastianHofmann http://lanyrd.com/people/BastianHofmann http://speakerdeck.com/u/bastianhofmann
[email protected]