SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
React.js
or why DOM finally makes sense
JSX ⊙_⊙
/**	
  @jsx	
  React.DOM	
  */	
  
var	
  name	
  =	
  "Foo",	
  commentText	
  =	
  "Bar",	
  avatarUrl="Baz";	
  
	
  	
  
var	
  avatar	
  =	
  <img	
  src	
  =	
  {avatarUrl}/>;	
  
	
  	
  
var	
  comment	
  =	
  <div	
  className="comment">	
  
	
  	
  {avatar}	
  @{name}:	
  {commentText}	
  
</div>
JSX is nice!
⊙⌣⊙
!
var	
  name	
  =	
  "Foo",	
  commentText	
  =	
  "Bar",	
  avatarUrl="Baz";	
  
	
  	
  
var	
  avatar	
  =	
  React.DOM.img(	
  {src:	
  	
  avatarUrl});	
  
	
  	
  
var	
  comment	
  =	
  React.DOM.div(	
  {className:"comment"},	
  	
  
	
  	
  avatar,	
  "	
  @",name,":	
  ",	
  commentText	
  
)
/**	
  @jsx	
  React.DOM	
  */	
  
var	
  name	
  =	
  "Foo",	
  commentText	
  =	
  "Bar",	
  avatarUrl="Baz";	
  
	
  	
  
var	
  avatar	
  =	
  <img	
  src	
  =	
  {avatarUrl}/>;	
  
	
  	
  
var	
  comment	
  =	
  <div	
  className="comment">	
  
	
  	
  {avatar}	
  @{name}:	
  {commentText}	
  
</div>
JSX rocks!
⊙⌣⊙
• tags are functions
• you can use closures
• scope is straightforward
• normalized DOM
the rules!
• do not mix logic and presentation
• do not write inline javascript
FUCK!
the rules!
• do not mix logic and presentation
• do not write inline javascript
components

components
components
/**	
  @jsx	
  React.DOM	
  */	
  
var	
  User	
  =	
  React.createClass({	
  
	
  	
  render:	
  function()	
  {	
  
	
  	
  	
  	
  return	
  (<div>	
  
	
  	
  	
  	
  	
  	
  	
  	
  <img	
  src={this.props.avatar}/>:	
  
	
  	
  	
  	
  	
  	
  	
  	
  @{this.props.username}	
  
	
  	
  	
  	
  	
  	
  </div>);	
  
	
  	
  }	
  
});	
  
!
React.renderComponent(	
  
	
  	
  <User	
  username="Eldar"	
  avatar="http://img.src/edjafarov"/>,	
  
	
  	
  document.getElementById('example')	
  
);
components

components
components
/**	
  @jsx	
  React.DOM	
  */	
  
var	
  Avatar	
  =	
  React.createClass({	
  
	
  	
  render:	
  function()	
  {	
  
	
  	
  	
  	
  return	
  <img	
  src={this.props.uri}/>;	
  
	
  	
  }	
  
});	
  
var	
  User	
  =	
  React.createClass({	
  
	
  	
  render:	
  function()	
  {	
  
	
  	
  	
  	
  return	
  (<div>	
  
	
  	
  	
  	
  	
  	
  	
  	
  <Avatar	
  uri={this.props.avatar}/>:	
  
	
  	
  	
  	
  	
  	
  	
  	
  @{this.props.username}	
  
	
  	
  	
  	
  	
  	
  </div>);	
  
	
  	
  }	
  
});
components

components
components
Props & State
var	
  User	
  =	
  React.createClass({	
  
	
  	
  getInitialState:	
  function(){	
  
	
   	
  	
  return	
  {	
  
	
   	
   	
  	
  name:this.props.user.name,	
  
	
   	
   	
  	
  uri:	
  this.props.user.uri	
  
	
   	
  	
  }	
  
	
  	
  },	
  	
  	
   	
  
	
  	
  render:	
  function()	
  {	
  
	
  	
  	
  	
  return	
  (<div>	
  
	
  	
  	
  	
  	
  	
  	
  	
  <Avatar	
  uri={this.props.avatar}/>:	
  
	
  	
  	
  	
  	
  	
  	
  	
  @{this.state.name}	
  
	
  	
  	
  	
  	
  	
  </div>);	
  
	
  	
  }	
  
});
Props & State
routing
doesn’t matter
http://visionmedia.github.io/page.js/
var	
  User	
  =	
  require('./User');	
  
	
  	
  
page('/user/:user',	
  user.load,	
  function(ctx){	
  
	
  	
  React.renderComponent(	
  
	
  	
  	
  	
  <User	
  user={ctx.user}/>,	
  
	
  	
  	
  	
  document.getElementById('root')	
  
	
  	
  );	
  
})
2 way binding/**	
  @jsx	
  React.DOM	
  */	
  
var	
  WithLink	
  =	
  React.createClass({	
  
	
  	
  mixins:	
  [React.addons.LinkedStateMixin],	
  
	
  	
  getInitialState:	
  function()	
  {	
  
	
  	
  	
  	
  return	
  {value:	
  'Hello!'};	
  
	
  	
  },	
  
	
  	
  render:	
  function()	
  {	
  
	
  	
  	
  	
  return	
  <input	
  type="text"	
  valueLink={this.linkState('value')}	
  />;	
  
	
  	
  }	
  
});
var	
  Hello	
  =	
  React.createClass({	
  
	
  	
  mixins:[ModelMixin,	
  BindMixin],	
  
	
  	
  getBackboneModels:	
  function(){	
  
	
  	
  	
  	
  return	
  [this.props.instance]	
  
	
  	
  },	
  
	
  	
  render:	
  function()	
  {	
  
	
  	
  	
  	
  var	
  model	
  =	
  this.props.instance;	
  
	
  	
  	
  	
  return	
  <div>	
  
	
  	
  	
  	
  	
  	
  	
  	
  <div>Hello	
  {model.get(‘initial')}</div>	
  
	
  	
  	
  	
  	
  	
  	
  	
  <input	
  type="text"	
  valueLink={this.bindTo(model,	
  'initial')}/>	
  
	
  	
  	
  	
  	
  	
  </div>	
  
	
  	
  }	
  
});
models
or
emitters?
What if models and collections are not enough?
https://github.com/component/emitter
var	
  Emitter	
  =	
  require('emitter');	
  
var	
  UserModel	
  =	
  new	
  Emitter({}	
  
	
  	
  data:	
  {},	
  
	
  	
  update:	
  function(){	
  
	
  	
  	
  	
  //some	
  async	
  update	
  
	
  	
  	
  	
  this.data	
  =	
  newData;	
  
	
  	
  	
  	
  this.emit('change');	
  
	
  	
  	
  	
  //-­‐-­‐-­‐	
  
	
  	
  }	
  
);	
  
UserModel.on('change',	
  /*update	
  component*/);	
  	
  
//You	
  can	
  use	
  mixin	
  to	
  do	
  that	
  automatically
be Lazy with
factory
• get bunch of id’s
• get empty model’s from factory by these id’s
• pass them to component
• PROFIT!
Q&A
@edjafarov
eldar.djafarov.com
just visit
reactjs.com
✌

Weitere ähnliche Inhalte

Was ist angesagt?

Redux training
Redux trainingRedux training
Redux trainingdasersoft
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingBinary Studio
 
React for Dummies
React for DummiesReact for Dummies
React for DummiesMitch Chen
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developerEugene Zharkov
 
ReactJs presentation
ReactJs presentationReactJs presentation
ReactJs presentationnishasowdri
 
REACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptREACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptDeepu S Nath
 
React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15Rob Gietema
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practicesClickky
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxVisual Engineering
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesomeAndrew Hull
 
Mobile Day - React Native
Mobile Day - React NativeMobile Day - React Native
Mobile Day - React NativeSoftware Guru
 
Introduction to React & Redux
Introduction to React & ReduxIntroduction to React & Redux
Introduction to React & ReduxBoris Dinkevich
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionVisual Engineering
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 DreamLab
 

Was ist angesagt? (20)

React & Redux
React & ReduxReact & Redux
React & Redux
 
Redux training
Redux trainingRedux training
Redux training
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developer
 
ReactJs presentation
ReactJs presentationReactJs presentation
ReactJs presentation
 
Redux vs Alt
Redux vs AltRedux vs Alt
Redux vs Alt
 
Let's Redux!
Let's Redux!Let's Redux!
Let's Redux!
 
REACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptREACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScript
 
React redux
React reduxReact redux
React redux
 
React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practices
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesome
 
React on es6+
React on es6+React on es6+
React on es6+
 
ReactJS
ReactJSReactJS
ReactJS
 
Mobile Day - React Native
Mobile Day - React NativeMobile Day - React Native
Mobile Day - React Native
 
Introduction to React & Redux
Introduction to React & ReduxIntroduction to React & Redux
Introduction to React & Redux
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS Introduction
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3
 

Ähnlich wie React.js or why DOM finally makes sense with JSX

Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentationBrian Hogg
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Foreverstephskardal
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"GeeksLab Odessa
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs[T]echdencias
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScriptbensmithett
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)Beau Lebens
 
SilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringSilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringIngo Schommer
 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Robert DeLuca
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
Building complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactBuilding complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactJonne Kats
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascriptaglemann
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 

Ähnlich wie React.js or why DOM finally makes sense with JSX (20)

Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentation
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Forever
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScript
 
React lecture
React lectureReact lecture
React lecture
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
SilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringSilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript Refactoring
 
React js
React jsReact js
React js
 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React
 
ReactJS
ReactJSReactJS
ReactJS
 
React 101
React 101React 101
React 101
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
React
React React
React
 
Building complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactBuilding complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and React
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
 
How to React Native
How to React NativeHow to React Native
How to React Native
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 

Mehr von Eldar Djafarov

The Grail: React based Isomorph apps framework
The Grail: React based Isomorph apps frameworkThe Grail: React based Isomorph apps framework
The Grail: React based Isomorph apps frameworkEldar Djafarov
 
Frontend - экосистема и будущее: iforum 2015
Frontend - экосистема и будущее: iforum 2015Frontend - экосистема и будущее: iforum 2015
Frontend - экосистема и будущее: iforum 2015Eldar Djafarov
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascriptEldar Djafarov
 
Your project tested #nodejs
Your project tested #nodejsYour project tested #nodejs
Your project tested #nodejsEldar Djafarov
 

Mehr von Eldar Djafarov (6)

PromisePipe inception
PromisePipe inceptionPromisePipe inception
PromisePipe inception
 
The Grail: React based Isomorph apps framework
The Grail: React based Isomorph apps frameworkThe Grail: React based Isomorph apps framework
The Grail: React based Isomorph apps framework
 
Frontend - экосистема и будущее: iforum 2015
Frontend - экосистема и будущее: iforum 2015Frontend - экосистема и будущее: iforum 2015
Frontend - экосистема и будущее: iforum 2015
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascript
 
Compy slides
Compy slidesCompy slides
Compy slides
 
Your project tested #nodejs
Your project tested #nodejsYour project tested #nodejs
Your project tested #nodejs
 

Kürzlich hochgeladen

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Kürzlich hochgeladen (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

React.js or why DOM finally makes sense with JSX

  • 1. React.js or why DOM finally makes sense
  • 2. JSX ⊙_⊙ /**  @jsx  React.DOM  */   var  name  =  "Foo",  commentText  =  "Bar",  avatarUrl="Baz";       var  avatar  =  <img  src  =  {avatarUrl}/>;       var  comment  =  <div  className="comment">      {avatar}  @{name}:  {commentText}   </div>
  • 3. JSX is nice! ⊙⌣⊙ ! var  name  =  "Foo",  commentText  =  "Bar",  avatarUrl="Baz";       var  avatar  =  React.DOM.img(  {src:    avatarUrl});       var  comment  =  React.DOM.div(  {className:"comment"},        avatar,  "  @",name,":  ",  commentText   ) /**  @jsx  React.DOM  */   var  name  =  "Foo",  commentText  =  "Bar",  avatarUrl="Baz";       var  avatar  =  <img  src  =  {avatarUrl}/>;       var  comment  =  <div  className="comment">      {avatar}  @{name}:  {commentText}   </div>
  • 4. JSX rocks! ⊙⌣⊙ • tags are functions • you can use closures • scope is straightforward • normalized DOM
  • 5. the rules! • do not mix logic and presentation • do not write inline javascript
  • 6. FUCK! the rules! • do not mix logic and presentation • do not write inline javascript
  • 7. components
 components components /**  @jsx  React.DOM  */   var  User  =  React.createClass({      render:  function()  {          return  (<div>                  <img  src={this.props.avatar}/>:                  @{this.props.username}              </div>);      }   });   ! React.renderComponent(      <User  username="Eldar"  avatar="http://img.src/edjafarov"/>,      document.getElementById('example')   );
  • 8. components
 components components /**  @jsx  React.DOM  */   var  Avatar  =  React.createClass({      render:  function()  {          return  <img  src={this.props.uri}/>;      }   });   var  User  =  React.createClass({      render:  function()  {          return  (<div>                  <Avatar  uri={this.props.avatar}/>:                  @{this.props.username}              </div>);      }   });
  • 10. Props & State var  User  =  React.createClass({      getInitialState:  function(){        return  {          name:this.props.user.name,          uri:  this.props.user.uri        }      },            render:  function()  {          return  (<div>                  <Avatar  uri={this.props.avatar}/>:                  @{this.state.name}              </div>);      }   });
  • 12. routing doesn’t matter http://visionmedia.github.io/page.js/ var  User  =  require('./User');       page('/user/:user',  user.load,  function(ctx){      React.renderComponent(          <User  user={ctx.user}/>,          document.getElementById('root')      );   })
  • 13. 2 way binding/**  @jsx  React.DOM  */   var  WithLink  =  React.createClass({      mixins:  [React.addons.LinkedStateMixin],      getInitialState:  function()  {          return  {value:  'Hello!'};      },      render:  function()  {          return  <input  type="text"  valueLink={this.linkState('value')}  />;      }   }); var  Hello  =  React.createClass({      mixins:[ModelMixin,  BindMixin],      getBackboneModels:  function(){          return  [this.props.instance]      },      render:  function()  {          var  model  =  this.props.instance;          return  <div>                  <div>Hello  {model.get(‘initial')}</div>                  <input  type="text"  valueLink={this.bindTo(model,  'initial')}/>              </div>      }   });
  • 14. models or emitters? What if models and collections are not enough? https://github.com/component/emitter var  Emitter  =  require('emitter');   var  UserModel  =  new  Emitter({}      data:  {},      update:  function(){          //some  async  update          this.data  =  newData;          this.emit('change');          //-­‐-­‐-­‐      }   );   UserModel.on('change',  /*update  component*/);     //You  can  use  mixin  to  do  that  automatically
  • 15. be Lazy with factory • get bunch of id’s • get empty model’s from factory by these id’s • pass them to component • PROFIT!