SlideShare a Scribd company logo
1 of 49
Progressive Enhancement
with Rails
@tylerjohnst
My Name is Tyler Johnston
What is Progressive Enhancement?
Traditional development with Rails works
great. Full page refreshes, static content,
all HTML generation.
But clients and customers want
interactivity and performance.
“Sprinkles of Javascript.”
Keep your Rails workflow but add
Javascript where it’s necessary.
ails 4 it is now a default gem in the generated G
ert your application in to a single page applica
Download all of the Javascript and
Stylesheets once and reuse for multiple
page views.
s. Turbolinks replaces the content of the <body
Turbolinks gracefully falls back to
browser defaults for
POST/PUT/DELETE requests as well as
the absence of Javascript.
While Turbolinks provides lots of benefits
there are a few caveats which caused a lot
of developers to not use it.
Turbolinks causes most requests to not
yield a full page refresh. This means you
must think differently about how you
organize and handle your Javascript.
Your application is now a long living
Javascript application.
You must be wary of memory leaks. This
means ensuring no circular references and
writing your Javascript in a way that allows
for garbage collection when the controller
changes actions.
$(document).on('page:load', function() {
// wire up javascript events for a page load
});
$(document).on('page:before-unload', function() {
// cleanup references from before
});
This means that just about every jQuery
plugin you may find will cause memory
leaks.
Most of these plugins are poorly
designed and
with a fresh page load in mind. They
don’t tend to track references or have a
way to clean them up.
al solutions to these problems that we’ve all tri
if ($('.organization').length > 0) {
$('.organization').each(function(index, element) {
var $el = $(element);
$.getJSON('/meetup/group/' + $el.prop('data-meetup-id'),
function(data) {
$el.find('a.title').prop('href', 'http://meetup.com/'
+ data.meetup_id)
$el.find('a.title h1').html(data.title);
$el.find('span.members').html(data.members_count);
$el.find('img.meetup-logo').html(data.images.group_logo_large);
});
});
}
Now HTML is rendered by Rails and we
have this pyramid of doom to update our
content.
What if we needed logic for different
pieces?
What if the Meetup API starts replying with
varying data based on something in their
state?
What if we want to poll repeatedly for
changes?
We could move HTML rendering to
templates and now we need another
gem to precompile
Handlebars/Jade/Haml Javascript
templates. Even more logic going in to
this single function.
ot a good fit for this style of development. They
Enter React
React is the light-weight functional view layer
from Facebook designed for building UIs with a
focus on immutable data structures.
React is designing your UI around
reusable and self-contained components.
No separation of files with controllers,
views, templates and models. Allows for
ease of maintainability for even the most of
Javascript novices.
React has a wonderfully simple API that
will take 15 minutes to learn.
OrganizationImage
OrganizationEvent
OrganizationName
OrganizationMembers
var Organization = React.createClass({
componentWillMount: function() {
$.getJSON('/meetup/group/' + this.props.meetup_id)
.then(function(json) {
this.setState(json);
}.bind(this));
},
meetupURL: function(path) {
return "http://www.meetup.com/" +
this.props.meetup_id + path;
},
render: function() {
return <div>
<OrganizationImage photos={this.state.group_photo} />
<OrganizationName name={this.state.name}
meetupURL={this.meetupURL} />
<OrganizationEvent event={this.state.next_event}
meetupURL={this.meetupURL} />
<OrganizationMembers members={this.state.members}
meetupURL={this.meetupURL} />
</div>;
}
});
React is designed around a one-way data
flow. Views are considered to be
immutable and state should be kept to
single place.
When state changes the views are
created from scratch and render and all
mutated state/properties are replaced.
var Organization = React.createClass({
componentWillMount: function() {
$.getJSON('/meetup/group/' + this.props.meetup_id).then(function(json) {
this.setState(json);
}.bind(this));
},
meetupURL: function(path) {
return "http://www.meetup.com/" + this.props.meetup_id + path;
},
render: function() {
return <div>
<OrganizationImage photos={this.state.group_photo} />
</div>;
}
});
var OrganizationImage = React.createClass({
render: function() {
return <img src={this.props.photos.highres_link} width="80" height="80"/>;
}
});
data. What about collecting data or doing things
t unidirectional flow. Data goes down and eve
why was the end of Lost so bad?
SearchAutocomplete
var SearchAutocomplete = React.createClass({
handleAutocomplete: function(event) {
var query = event.target.value;
this.setState({ searchQuery: query });
$.getJSON(this.props.autocompleteUrl, { q: query })
.then(function(autocompleteOptions) {
this.setState({ options: autocompleteOptions });
});
},
render: function() {
return <div>
<SearchAutocompleteInput value={this.state.searchQuery}
handleChange={this.handleAutocomplete} />
<SearchAutocompleteResults options={this.state.options} />
</div>;
}
});
AutocompleteSearchInput
AutocompleteSearchResult
s
var SearchAutocomplete = React.createClass({
handleAutocomplete: function(event) {
var query = event.target.value;
this.setState({ searchQuery: query });
$.getJSON(this.props.autocompleteUrl, { q: query })
.then(function(autocompleteOptions) {
this.setState({ options: autocompleteOptions });
});
},
render: function() {
return <div>
<SearchAutocompleteInput value={this.state.searchQuery}
handleChange={this.handleAutocomplete} />
<SearchAutocompleteResults options={this.state.options} />
</div>;
}
});
Whats with all the Javascript? Isn’t this
about Rails?
gem 'react-rails'
unctionality and dependencies of React while t
Remember the Organization component?
<% @organizations.each do |organization| %>
<%= react_component('Organization',
organization.to_json) %>
<% end %>
Mounts the React component
Sets the properties of the component
from the given hash
Automatically cleans up references and
handles memory management with
Turbolinks callbacks
But what about SEO and search
engine crawling?
<%= react_component('Organization',
organization.to_json, prerender: true) %>
React knows how to pre-render using
ExecJS so the component will boot
using the existing HTML that is valid
for React.
I’ve come full circle on my thinking of front
end development.
Rails development feels better than every
alternative, no matter how polished. React
and React-Rails allows for a really great
convergence of great and fast front end
tooling with Rails fast development
cycle.
Go forth and try React with Rails!
Questions? Comments?

More Related Content

What's hot

Spca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesSpca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesNCCOMMS
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax pluginsInbal Geffen
 
(Updated) SharePoint & jQuery Guide
(Updated) SharePoint & jQuery Guide(Updated) SharePoint & jQuery Guide
(Updated) SharePoint & jQuery GuideMark Rackley
 
Assumptions: Check yo'self before you wreck yourself
Assumptions: Check yo'self before you wreck yourselfAssumptions: Check yo'self before you wreck yourself
Assumptions: Check yo'self before you wreck yourselfErin Shellman
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersCaldera Labs
 
Two Webs! : combining the best of Web 1.0, Web 2.0 and the Semantic Web
Two Webs! : combining the best of Web 1.0, Web 2.0 and the Semantic WebTwo Webs! : combining the best of Web 1.0, Web 2.0 and the Semantic Web
Two Webs! : combining the best of Web 1.0, Web 2.0 and the Semantic WebDanny Ayers
 
Search APIs in Spotlight and Safari
Search APIs in Spotlight and SafariSearch APIs in Spotlight and Safari
Search APIs in Spotlight and SafariYusuke Kita
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014Mike Schinkel
 
Create responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSCreate responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSHannes Hapke
 
An Overview of Models in Django
An Overview of Models in DjangoAn Overview of Models in Django
An Overview of Models in DjangoMichael Auritt
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Mike Schinkel
 
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaPutting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaGalen Charlton
 
Server Side Swift with Swag
Server Side Swift with SwagServer Side Swift with Swag
Server Side Swift with SwagJens Ravens
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to ServicesCraig Kerstiens
 
Take Better Care of Library Data and Spreadsheets with Google Visualization A...
Take Better Care of Library Data and Spreadsheets with Google Visualization A...Take Better Care of Library Data and Spreadsheets with Google Visualization A...
Take Better Care of Library Data and Spreadsheets with Google Visualization A...Bohyun Kim
 

What's hot (16)

Spca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesSpca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_libraries
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
 
(Updated) SharePoint & jQuery Guide
(Updated) SharePoint & jQuery Guide(Updated) SharePoint & jQuery Guide
(Updated) SharePoint & jQuery Guide
 
Assumptions: Check yo'self before you wreck yourself
Assumptions: Check yo'self before you wreck yourselfAssumptions: Check yo'self before you wreck yourself
Assumptions: Check yo'self before you wreck yourself
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress Developers
 
Two Webs! : combining the best of Web 1.0, Web 2.0 and the Semantic Web
Two Webs! : combining the best of Web 1.0, Web 2.0 and the Semantic WebTwo Webs! : combining the best of Web 1.0, Web 2.0 and the Semantic Web
Two Webs! : combining the best of Web 1.0, Web 2.0 and the Semantic Web
 
ApacheCon 2005
ApacheCon 2005ApacheCon 2005
ApacheCon 2005
 
Search APIs in Spotlight and Safari
Search APIs in Spotlight and SafariSearch APIs in Spotlight and Safari
Search APIs in Spotlight and Safari
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
 
Create responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSCreate responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJS
 
An Overview of Models in Django
An Overview of Models in DjangoAn Overview of Models in Django
An Overview of Models in Django
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaPutting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
 
Server Side Swift with Swag
Server Side Swift with SwagServer Side Swift with Swag
Server Side Swift with Swag
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to Services
 
Take Better Care of Library Data and Spreadsheets with Google Visualization A...
Take Better Care of Library Data and Spreadsheets with Google Visualization A...Take Better Care of Library Data and Spreadsheets with Google Visualization A...
Take Better Care of Library Data and Spreadsheets with Google Visualization A...
 

Similar to Progressive Enhancment with Rails and React

Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Robert DeLuca
 
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 JavaScriptGuy Royse
 
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 applicationsJeff Durta
 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your AppLuca Mearelli
 
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 MVCpootsbook
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery ApplicationsRebecca Murphey
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineAndy McKay
 
Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology updateDoug Domeny
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegapyangdj
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaveryangdj
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJSAaronius
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfacesmaccman
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScriptbensmithett
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationAndrew Rota
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of usOSCON Byrum
 

Similar to Progressive Enhancment with Rails and React (20)

Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React
 
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
 
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
 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your App
 
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
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
huhu
huhuhuhu
huhu
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
JS-05-Handlebars.ppt
JS-05-Handlebars.pptJS-05-Handlebars.ppt
JS-05-Handlebars.ppt
 
Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology update
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfaces
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScript
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 

Recently uploaded

CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 

Recently uploaded (20)

CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 

Progressive Enhancment with Rails and React

  • 2. My Name is Tyler Johnston
  • 3. What is Progressive Enhancement?
  • 4. Traditional development with Rails works great. Full page refreshes, static content, all HTML generation.
  • 5. But clients and customers want interactivity and performance.
  • 7. Keep your Rails workflow but add Javascript where it’s necessary.
  • 8.
  • 9. ails 4 it is now a default gem in the generated G
  • 10. ert your application in to a single page applica
  • 11. Download all of the Javascript and Stylesheets once and reuse for multiple page views.
  • 12. s. Turbolinks replaces the content of the <body
  • 13. Turbolinks gracefully falls back to browser defaults for POST/PUT/DELETE requests as well as the absence of Javascript.
  • 14. While Turbolinks provides lots of benefits there are a few caveats which caused a lot of developers to not use it.
  • 15. Turbolinks causes most requests to not yield a full page refresh. This means you must think differently about how you organize and handle your Javascript.
  • 16. Your application is now a long living Javascript application. You must be wary of memory leaks. This means ensuring no circular references and writing your Javascript in a way that allows for garbage collection when the controller changes actions.
  • 17. $(document).on('page:load', function() { // wire up javascript events for a page load }); $(document).on('page:before-unload', function() { // cleanup references from before });
  • 18. This means that just about every jQuery plugin you may find will cause memory leaks. Most of these plugins are poorly designed and with a fresh page load in mind. They don’t tend to track references or have a way to clean them up.
  • 19. al solutions to these problems that we’ve all tri
  • 20. if ($('.organization').length > 0) { $('.organization').each(function(index, element) { var $el = $(element); $.getJSON('/meetup/group/' + $el.prop('data-meetup-id'), function(data) { $el.find('a.title').prop('href', 'http://meetup.com/' + data.meetup_id) $el.find('a.title h1').html(data.title); $el.find('span.members').html(data.members_count); $el.find('img.meetup-logo').html(data.images.group_logo_large); }); }); }
  • 21. Now HTML is rendered by Rails and we have this pyramid of doom to update our content. What if we needed logic for different pieces? What if the Meetup API starts replying with varying data based on something in their state? What if we want to poll repeatedly for changes?
  • 22. We could move HTML rendering to templates and now we need another gem to precompile Handlebars/Jade/Haml Javascript templates. Even more logic going in to this single function.
  • 23. ot a good fit for this style of development. They
  • 24. Enter React React is the light-weight functional view layer from Facebook designed for building UIs with a focus on immutable data structures.
  • 25. React is designing your UI around reusable and self-contained components.
  • 26. No separation of files with controllers, views, templates and models. Allows for ease of maintainability for even the most of Javascript novices. React has a wonderfully simple API that will take 15 minutes to learn.
  • 28. var Organization = React.createClass({ componentWillMount: function() { $.getJSON('/meetup/group/' + this.props.meetup_id) .then(function(json) { this.setState(json); }.bind(this)); }, meetupURL: function(path) { return "http://www.meetup.com/" + this.props.meetup_id + path; }, render: function() { return <div> <OrganizationImage photos={this.state.group_photo} /> <OrganizationName name={this.state.name} meetupURL={this.meetupURL} /> <OrganizationEvent event={this.state.next_event} meetupURL={this.meetupURL} /> <OrganizationMembers members={this.state.members} meetupURL={this.meetupURL} /> </div>; } });
  • 29. React is designed around a one-way data flow. Views are considered to be immutable and state should be kept to single place. When state changes the views are created from scratch and render and all mutated state/properties are replaced.
  • 30. var Organization = React.createClass({ componentWillMount: function() { $.getJSON('/meetup/group/' + this.props.meetup_id).then(function(json) { this.setState(json); }.bind(this)); }, meetupURL: function(path) { return "http://www.meetup.com/" + this.props.meetup_id + path; }, render: function() { return <div> <OrganizationImage photos={this.state.group_photo} /> </div>; } }); var OrganizationImage = React.createClass({ render: function() { return <img src={this.props.photos.highres_link} width="80" height="80"/>; } });
  • 31. data. What about collecting data or doing things
  • 32. t unidirectional flow. Data goes down and eve
  • 33. why was the end of Lost so bad? SearchAutocomplete
  • 34. var SearchAutocomplete = React.createClass({ handleAutocomplete: function(event) { var query = event.target.value; this.setState({ searchQuery: query }); $.getJSON(this.props.autocompleteUrl, { q: query }) .then(function(autocompleteOptions) { this.setState({ options: autocompleteOptions }); }); }, render: function() { return <div> <SearchAutocompleteInput value={this.state.searchQuery} handleChange={this.handleAutocomplete} /> <SearchAutocompleteResults options={this.state.options} /> </div>; } });
  • 36. var SearchAutocomplete = React.createClass({ handleAutocomplete: function(event) { var query = event.target.value; this.setState({ searchQuery: query }); $.getJSON(this.props.autocompleteUrl, { q: query }) .then(function(autocompleteOptions) { this.setState({ options: autocompleteOptions }); }); }, render: function() { return <div> <SearchAutocompleteInput value={this.state.searchQuery} handleChange={this.handleAutocomplete} /> <SearchAutocompleteResults options={this.state.options} /> </div>; } });
  • 37.
  • 38. Whats with all the Javascript? Isn’t this about Rails?
  • 40. unctionality and dependencies of React while t
  • 42. <% @organizations.each do |organization| %> <%= react_component('Organization', organization.to_json) %> <% end %>
  • 43. Mounts the React component Sets the properties of the component from the given hash Automatically cleans up references and handles memory management with Turbolinks callbacks
  • 44. But what about SEO and search engine crawling?
  • 46.
  • 47. React knows how to pre-render using ExecJS so the component will boot using the existing HTML that is valid for React.
  • 48. I’ve come full circle on my thinking of front end development. Rails development feels better than every alternative, no matter how polished. React and React-Rails allows for a really great convergence of great and fast front end tooling with Rails fast development cycle.
  • 49. Go forth and try React with Rails! Questions? Comments?

Editor's Notes

  1. A lot of people were not happy with Turbolinks and most people remove it out of frustration.
  2. In this example we can see the state is contained to the “Organization” component. That is responsible for creating and passing data to the child views. When it is “mounted” it sends a network request.
  3. The child input isn’t even responsible for updating the state of the “value.” It is passed in after the searchQuery value changes.
  4. The child input isn’t even responsible for updating the state of the “value.” It is passed in after the searchQuery value changes.
  5. Testing works out of the box. Javascript unit testing works out of the box with `jasmine-rails`. JSX compilation with Sprockets works out of the box.