Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Bring your web application architecture to the ...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Bastian Hofmann
June 11, 2015
Programming
250
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
Transcript
138 slides
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]
More Decks by Bastian Hofmann
See All by Bastian Hofmann
Monitoring in Kubernetes with Prometheus and Grafana
bastianhofmann
0
390
Creating a fast Kubernetes Development Workflow
bastianhofmann
0
160
Highly available cross-region deployments with Kubernetes
bastianhofmann
1
190
From source to Kubernetes in 30 minutes
bastianhofmann
0
210
Introduction to Kubernetes
bastianhofmann
1
140
CI/CD with Kubernetes
bastianhofmann
0
260
Creating a fast Kubernetes Development Workflow
bastianhofmann
1
300
Deploying your first Micro-Service application to Kubernetes
bastianhofmann
2
220
Creating a fast Kubernetes Development Workflow
bastianhofmann
0
290
Other Decks in Programming
See All in Programming
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
17
9.5k
コード生成時代のAPI定義を支えるRequest Spec移行
pvcresin
0
300
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
180
SONY CISC-NEWS NWS-1750 + NWB-225 ハードウェアメンテとフレームバッファカラー対応 / KOF2026
tsutsui
0
130
マルチプロダクトSaaSの アプリ一覧を速くする——複数プロダクトにまたがる「権限行脚」を減らすまで #techramen26conf
mktakuya
1
160
祈るテストから、探索するテストへ 〜Lincheckではじめる並行処理テスト〜
yyh_gl
0
430
Agentic AI with the Power of Jakarta EE
ivargrimstad
0
180
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
470
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
700
複数ドメインを一つのアプリに統合するFlutterの設計と運用_FlutterKaigi2026登壇資料(須永高弘)
takahirosunaga
0
210
Getting Started with Vibe Coding
miccheng
0
250
Proxmox x Talos Linux x Terraform で実現するなんかいい感じの Kubernetes クラスタ / A Sleek Kubernetes Cluster Powered by Proxmox, Talos Linux, and Terraform
nnaka2992
0
300
Featured
See All Featured
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
61k
Everyday Curiosity
cassininazir
0
420
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.2k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
580
Raft: Consensus for Rubyists
vanstee
143
7.9k
Unsuck your backbone
ammeep
672
58k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.8k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Between Models and Reality
mayunak
4
600
Bash Introduction
62gerente
615
220k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
360