SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
Hasan @ DEV6 – #WEBU17
?
Hasan @ DEV6 – #WEBU17
Hasan @ DEV6 – #WEBU17
Hasan Ahmad
Senior Consultant @ DEV6
Lead @ DevC Toronto
https://www.dev6.com/
https://www.facebook.com/groups/DevCToronto/
Hasan @ DEV6 – #WEBU17
Front-end frameworks have more in common than you might expect
Component based architecture
View-Model / State management
Routing views with URLs
Hasan @ DEV6 – #WEBU17
Components
Angular: Decorate classes with component life-cycle hooks
React: ES6 inheritance provides interfaces for life-cycle hooks
Hasan @ DEV6 – #WEBU17
@Component({selector:	'greet',	template:	'Hello	{{name}}!’})		
class	Greet	{		
	name:	string	=	'World';	
}	
class	Welcome	extends	React.component	{	
	render()	{		
	 	return	<h1>Hello,	{this.props.name}</h1>		
	}		
}
Hasan @ DEV6 – #WEBU17
ngOnChanges()	–	when	a	data	binding	has	changed	
ngOnInit()	–	when	angular	has	already	displayed	bound	data	
ngOnCheck()	–	manual	change	detection	
ngAfterContentInit()	-	…	
ngAfterContentInitChecked()	-	…	
ngAfterViewInit()	-	…	
ngAfterViewInitChecked()	-	…	
ngOnDestroy()	–	right	before	angular	removes	a	component
Hasan @ DEV6 – #WEBU17
constructor()	–	component	is	created	
componentWillMount()	–	before	a	component	has	been	attached	to	view	
render()	–	return	the	react	view	element	
componentDidMount()	–	after	react	has	attached	component	to	view	
componentWillRecieveProps()	-	…	
shouldComponentUpdate()	-	…	
componentWillUpdate()	-	…	
componentDidUpdate()	-	after	react	has	updated	a	component	
componentWillUnmount()	–	before	react	removes	a	component
Hasan @ DEV6 – #WEBU17
export	class	PeekABoo	implements	OnInit	{	
	constructor(private	logger:	LoggerService)	{	}	
	//	implement	OnInit's	`ngOnInit`	method	
	ngOnInit()	{	
	 	this.logIt(`OnInit`);		
	}		
	logIt(msg:	string)	{		
	 	this.logger.log(`#${nextId++}	${msg}`);		
	}	
}
Hasan @ DEV6 – #WEBU17
class	Clock	extends	React.Component	{	
constructor(props)	{		
super(props);		
this.state	=	{date:	new	Date()};		
}	
componentDidMount()	{		
	this.timerID	=	setInterval(	()	=>	this.tick(),	1000	);		
}	
componentWillUnmount()	{		
	clearInterval(this.timerID);		
}		
//...		
}
Hasan @ DEV6 – #WEBU17
Data Binding
Angular - flexible data binding options, including two-way
React - One-way data binding, lift state up
Hasan @ DEV6 – #WEBU17
Component to
DOM
Interpolation and Property Binding
One-way binding: Value goes from component data property to a target
element property
DOM to
Component
Event Binding: user interacted with page, bring that back to the component
Both Two-Way Binding: update data as soon as it has been changed by the user
Hasan @ DEV6 – #WEBU17
Handling State
Angular – Mutable data, services as singletons (can opt for immutable too)
React – state & props, flux, redux
Hasan @ DEV6 – #WEBU17
Service is a singleton – only one instance in memory
Components can mutate data in services, everyone who injects a
service can see the altered state
Angular will automatically re-draw the UI with the new data
(Change Detection + Zones + Data Binding)
Hasan @ DEV6 – #WEBU17
Components have their own state, react renders components when
their state changes
By default, you have to maintain parent-child relationships to state,
using props
redux: have one giant state object
Hasan @ DEV6 – #WEBU17
Store Single big JSON, all state for entire application
Reducer Update store, return a new state
Action Dispatched to trigger a state change
Follow up on redux.js.org
Hasan @ DEV6 – #WEBU17
Layout & Styling
Angular has embraced Shadow DOM +View Encapsulation for styling
components
React is compatible with many styling approaches: traditional CSS,
bootstrap, and flexbox
Hasan @ DEV6 – #WEBU17
@Component({		
selector:	'hero-details',		
template:	`		
<h2>{{hero.name}}</h2>		
<hero-team	[hero]=hero></hero-team>		
<ng-content></ng-content>		
`,		
styleUrls:	['app/hero-details.component.css']		
})	
export	class	HeroDetailsComponent	{	/*	.	.	.	*/	}
Hasan @ DEV6 – #WEBU17
What is Shadow DOM?
Shadow DOM is included in the Web Components standard by W3C
Refers to the ability to include a subtree of DOM elements
Allows DOM implementation to be hidden from the rest of the
document
Hasan @ DEV6 – #WEBU17
<hero-details	_nghost-pmm-5>	
<h2	_ngcontent-pmm-5>Mister	Fantastic</h2>		
<hero-team	_ngcontent-pmm-5	_nghost-pmm-6>		
	<h3	_ngcontent-pmm-6>Team</h3>		
</hero-team>		
</hero-detail>
Hasan @ DEV6 – #WEBU17
render(props,	context)	{		
	const	notes	=	this.props.notes;		
	return	<ul	className='notes'>{notes.map(this.renderNote)}</ul>;	
}	
render(props,	context)	{		
	const	notes	=	this.props.notes;		
	const	style	=	{		
	 	margin:	'0.5em',		
	 	paddingLeft:	0,		
	 	listStyle:	'none'		
	};		
	return	<ul	style={style}>{notes.map(this.renderNote)}</ul>;		
}	
https://survivejs.com/react/advanced-techniques/styling-react/
Hasan @ DEV6 – #WEBU17
import	React	from	'react'		
import	injectSheet	from	'react-jss'		
const	styles	=	{		
	button:	{		
	 	background:	props	=>	props.color	},		
	label:	{		
	 	fontWeight:	'bold'		
	}		
}		
const	Button	=	({classes,	children})	=>	(		
	<button	className={classes.button}>		
	 	<span	className={classes.label}>		
	 	 	{children}		
	 	</span>		
	</button>		
)		
export	default	injectSheet(styles)(Button)	
https://github.com/cssinjs/jss
Hasan @ DEV6 – #WEBU17
var	Block	=	require('jsxstyle/Block');		
var	React	=	require('react');		
var	MyComponent	=	React.createClass({		
render:	function()	{		
	return	<Block	color="red">Hello,	world!</Block>;		
}		
});	
https://github.com/smyte/jsxstyle
Hasan @ DEV6 – #WEBU17
Routing
Angular has one routing model, driven by the URL
@angular/router is engineered for many scenarios
React has many different options, depending on your app architecture
react-router, fluxxor-react-router, react-redux-router
Hasan @ DEV6 – #WEBU17
template:	`		
<h1>Angular	Router</h1>		
<nav>		
<a	routerLink="/crisis-center"	routerLinkActive="active">Crisis	Center</a>		
<a	routerLink="/heroes"	routerLinkActive="active">Heroes</a>		
</nav>		
<router-outlet></router-outlet>		
`	
const	appRoutes:	Routes	=	[		
{	path:	'crisis-center',	component:	CrisisListComponent	},		
{	path:	'hero/:id',	component:	HeroDetailComponent	},		
{	path:	'heroes',	component:	HeroListComponent,	data:	{	title:	'Heroes	List'	}	},		
{	path:	'',	redirectTo:	'/heroes',	pathMatch:	'full'	},		
{	path:	'**',	component:	PageNotFoundComponent	}		
];
Hasan @ DEV6 – #WEBU17
//	./src/index.jsx		
import	React,	{	Component	}	from	'react';		
import	{	render	}	from	'react-dom';		
//	Import	routing	components		
import	{Router,	Route}	from	'react-router';		
class	Home	extends	Component	{		
render(){		
	return	(<h1>Hi</h1>);		
}		
}	
render(		
	<Router>		
	 	<!--Each	route	is	defined	with	Route-->		
	 	<Route	path="/"	component={Home}/>		
	</Router>,		
	document.getElementById('container')		
);	
https://scotch.io/tutorials/routing-react-apps-the-complete-guide
Hasan @ DEV6 – #WEBU17
import	React	from	'react'		
import	ReactDOM	from	'react-dom'		
import	{	createStore,	combineReducers	}	from	'redux'		
import	{	Provider	}	from	'react-redux'		
import	{	Router,	Route,	browserHistory	}	from	'react-router'		
import	{	syncHistoryWithStore,	routerReducer	}	from	'react-router-redux'		
import	reducers	from	'<project-path>/reducers'		
const	store	=	createStore(	combineReducers({	...reducers,	routing:	routerReducer	})	)		
//	Create	an	enhanced	history	that	syncs	navigation	events	with	the	store		
const	history	=	syncHistoryWithStore(browserHistory,	store)		
ReactDOM.render(		
<Provider	store={store}>		
<Router	history={history}>		
<Route	path="/"	component={App}>		
<Route	path="foo"	component={Foo}/>		
<Route	path="bar"	component={Bar}/>		
</Route>		
</Router>		
</Provider>,		
document.getElementById('mount')		
)	
https://github.com/reactjs/react-router-redux
Hasan @ DEV6 – #WEBU17
Testing
Angular comes with extensive support for jasmine with karma and
protractor
React varies by project, some use Jest, others use Mocha/Chai/Enzyme
Hasan @ DEV6 – #WEBU17
Cross-platform apps
Extend cross platform experience beyond the browser
Progressive Web Applications
Cordova / Hybrid Applications
NativeScript / React Native
Hasan @ DEV6 – #WEBU17
Angular + React = ?
react-native-renderer – Angular project in a react native app
ng-redux – Use redux (popularized by React) in your Angular projects
Hasan @ DEV6 – #WEBU17
Summary
Equal, yet different:Two approaches to solving common problems all
developers face.
Choice between Angular and React is ultimately driven by an
organization’s development philosophy.
Hasan @ DEV6 – #WEBU17
ThankYou!
Questions?

Contenu connexe

Tendances

Usability in the GeoWeb
Usability in the GeoWebUsability in the GeoWeb
Usability in the GeoWeb
Dave Bouwman
 

Tendances (20)

Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
 
jQuery 1.9 and 2.0 - Present and Future
jQuery 1.9 and 2.0 - Present and FuturejQuery 1.9 and 2.0 - Present and Future
jQuery 1.9 and 2.0 - Present and Future
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
 
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
 
Building a Secure App with Google Polymer and Java / Spring
Building a Secure App with Google Polymer and Java / SpringBuilding a Secure App with Google Polymer and Java / Spring
Building a Secure App with Google Polymer and Java / Spring
 
Disrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applicationsDisrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applications
 
AtlasCamp 2015: Using add-ons to build add-ons
AtlasCamp 2015: Using add-ons to build add-onsAtlasCamp 2015: Using add-ons to build add-ons
AtlasCamp 2015: Using add-ons to build add-ons
 
You Know WebOS
You Know WebOSYou Know WebOS
You Know WebOS
 
Unlock the next era of UI design with Polymer
Unlock the next era of UI design with PolymerUnlock the next era of UI design with Polymer
Unlock the next era of UI design with Polymer
 
Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video Player
 
AspNetWhitePaper
AspNetWhitePaperAspNetWhitePaper
AspNetWhitePaper
 
Usability in the GeoWeb
Usability in the GeoWebUsability in the GeoWeb
Usability in the GeoWeb
 
Enough with the JavaScript already!
Enough with the JavaScript already!Enough with the JavaScript already!
Enough with the JavaScript already!
 
Enjoy the vue.js
Enjoy the vue.jsEnjoy the vue.js
Enjoy the vue.js
 
Externalizing Chatter Using Heroku, Angular.js, Node.js and Chatter REST APIs
Externalizing Chatter Using Heroku, Angular.js, Node.js and Chatter REST APIsExternalizing Chatter Using Heroku, Angular.js, Node.js and Chatter REST APIs
Externalizing Chatter Using Heroku, Angular.js, Node.js and Chatter REST APIs
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web Components
 
HTML5 and the dawn of rich mobile web applications
HTML5 and the dawn of rich mobile web applicationsHTML5 and the dawn of rich mobile web applications
HTML5 and the dawn of rich mobile web applications
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014
 
Our application got popular and now it breaks
Our application got popular and now it breaksOur application got popular and now it breaks
Our application got popular and now it breaks
 

Similaire à Angular vs React for Web Application Development

Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
Doris Chen
 

Similaire à Angular vs React for Web Application Development (20)

Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
 
Front End Development for Back End Developers - Devoxx UK 2017
 Front End Development for Back End Developers - Devoxx UK 2017 Front End Development for Back End Developers - Devoxx UK 2017
Front End Development for Back End Developers - Devoxx UK 2017
 
Html5
Html5Html5
Html5
 
Html5 & less css
Html5 & less cssHtml5 & less css
Html5 & less css
 
How i made the responsive mobile version of
How i made the responsive mobile version ofHow i made the responsive mobile version of
How i made the responsive mobile version of
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
ReactJS.ppt
ReactJS.pptReactJS.ppt
ReactJS.ppt
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Leveraging the Power of Custom Elements in Gutenberg
Leveraging the Power of Custom Elements in GutenbergLeveraging the Power of Custom Elements in Gutenberg
Leveraging the Power of Custom Elements in Gutenberg
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison
 
Getting Started with React v16
Getting Started with React v16Getting Started with React v16
Getting Started with React v16
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
 
crtical points for customizing Joomla templates
crtical points for customizing Joomla templatescrtical points for customizing Joomla templates
crtical points for customizing Joomla templates
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
It's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking ModernizrIt's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking Modernizr
 

Plus de FITC

Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital Health
FITC
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript Performance
FITC
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight Websites
FITC
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is Terrifying
FITC
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future Human
FITC
 

Plus de FITC (20)

Cut it up
Cut it upCut it up
Cut it up
 
Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital Health
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript Performance
 
Surviving Your Tech Stack
Surviving Your Tech StackSurviving Your Tech Stack
Surviving Your Tech Stack
 
How to Pitch Your First AR Project
How to Pitch Your First AR ProjectHow to Pitch Your First AR Project
How to Pitch Your First AR Project
 
Start by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerStart by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the Answer
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryCocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s Story
 
Everyday Innovation
Everyday InnovationEveryday Innovation
Everyday Innovation
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight Websites
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is Terrifying
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future Human
 
The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)
 
East of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameEast of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR Game
 
Creating a Proactive Healthcare System
Creating a Proactive Healthcare SystemCreating a Proactive Healthcare System
Creating a Proactive Healthcare System
 
World Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignWorld Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product Design
 
The Power of Now
The Power of NowThe Power of Now
The Power of Now
 
High Performance PWAs
High Performance PWAsHigh Performance PWAs
High Performance PWAs
 
Rise of the JAMstack
Rise of the JAMstackRise of the JAMstack
Rise of the JAMstack
 
From Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFrom Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self Discovery
 
Projects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForProjects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time For
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Angular vs React for Web Application Development

  • 1. Hasan @ DEV6 – #WEBU17 ?
  • 2. Hasan @ DEV6 – #WEBU17
  • 3. Hasan @ DEV6 – #WEBU17 Hasan Ahmad Senior Consultant @ DEV6 Lead @ DevC Toronto https://www.dev6.com/ https://www.facebook.com/groups/DevCToronto/
  • 4. Hasan @ DEV6 – #WEBU17 Front-end frameworks have more in common than you might expect Component based architecture View-Model / State management Routing views with URLs
  • 5. Hasan @ DEV6 – #WEBU17 Components Angular: Decorate classes with component life-cycle hooks React: ES6 inheritance provides interfaces for life-cycle hooks
  • 6. Hasan @ DEV6 – #WEBU17 @Component({selector: 'greet', template: 'Hello {{name}}!’}) class Greet { name: string = 'World'; } class Welcome extends React.component { render() { return <h1>Hello, {this.props.name}</h1> } }
  • 7. Hasan @ DEV6 – #WEBU17 ngOnChanges() – when a data binding has changed ngOnInit() – when angular has already displayed bound data ngOnCheck() – manual change detection ngAfterContentInit() - … ngAfterContentInitChecked() - … ngAfterViewInit() - … ngAfterViewInitChecked() - … ngOnDestroy() – right before angular removes a component
  • 8. Hasan @ DEV6 – #WEBU17 constructor() – component is created componentWillMount() – before a component has been attached to view render() – return the react view element componentDidMount() – after react has attached component to view componentWillRecieveProps() - … shouldComponentUpdate() - … componentWillUpdate() - … componentDidUpdate() - after react has updated a component componentWillUnmount() – before react removes a component
  • 9. Hasan @ DEV6 – #WEBU17 export class PeekABoo implements OnInit { constructor(private logger: LoggerService) { } // implement OnInit's `ngOnInit` method ngOnInit() { this.logIt(`OnInit`); } logIt(msg: string) { this.logger.log(`#${nextId++} ${msg}`); } }
  • 10. Hasan @ DEV6 – #WEBU17 class Clock extends React.Component { constructor(props) { super(props); this.state = {date: new Date()}; } componentDidMount() { this.timerID = setInterval( () => this.tick(), 1000 ); } componentWillUnmount() { clearInterval(this.timerID); } //... }
  • 11. Hasan @ DEV6 – #WEBU17 Data Binding Angular - flexible data binding options, including two-way React - One-way data binding, lift state up
  • 12. Hasan @ DEV6 – #WEBU17 Component to DOM Interpolation and Property Binding One-way binding: Value goes from component data property to a target element property DOM to Component Event Binding: user interacted with page, bring that back to the component Both Two-Way Binding: update data as soon as it has been changed by the user
  • 13. Hasan @ DEV6 – #WEBU17 Handling State Angular – Mutable data, services as singletons (can opt for immutable too) React – state & props, flux, redux
  • 14. Hasan @ DEV6 – #WEBU17 Service is a singleton – only one instance in memory Components can mutate data in services, everyone who injects a service can see the altered state Angular will automatically re-draw the UI with the new data (Change Detection + Zones + Data Binding)
  • 15. Hasan @ DEV6 – #WEBU17 Components have their own state, react renders components when their state changes By default, you have to maintain parent-child relationships to state, using props redux: have one giant state object
  • 16. Hasan @ DEV6 – #WEBU17 Store Single big JSON, all state for entire application Reducer Update store, return a new state Action Dispatched to trigger a state change Follow up on redux.js.org
  • 17. Hasan @ DEV6 – #WEBU17 Layout & Styling Angular has embraced Shadow DOM +View Encapsulation for styling components React is compatible with many styling approaches: traditional CSS, bootstrap, and flexbox
  • 18. Hasan @ DEV6 – #WEBU17 @Component({ selector: 'hero-details', template: ` <h2>{{hero.name}}</h2> <hero-team [hero]=hero></hero-team> <ng-content></ng-content> `, styleUrls: ['app/hero-details.component.css'] }) export class HeroDetailsComponent { /* . . . */ }
  • 19. Hasan @ DEV6 – #WEBU17 What is Shadow DOM? Shadow DOM is included in the Web Components standard by W3C Refers to the ability to include a subtree of DOM elements Allows DOM implementation to be hidden from the rest of the document
  • 20. Hasan @ DEV6 – #WEBU17 <hero-details _nghost-pmm-5> <h2 _ngcontent-pmm-5>Mister Fantastic</h2> <hero-team _ngcontent-pmm-5 _nghost-pmm-6> <h3 _ngcontent-pmm-6>Team</h3> </hero-team> </hero-detail>
  • 21. Hasan @ DEV6 – #WEBU17 render(props, context) { const notes = this.props.notes; return <ul className='notes'>{notes.map(this.renderNote)}</ul>; } render(props, context) { const notes = this.props.notes; const style = { margin: '0.5em', paddingLeft: 0, listStyle: 'none' }; return <ul style={style}>{notes.map(this.renderNote)}</ul>; } https://survivejs.com/react/advanced-techniques/styling-react/
  • 22. Hasan @ DEV6 – #WEBU17 import React from 'react' import injectSheet from 'react-jss' const styles = { button: { background: props => props.color }, label: { fontWeight: 'bold' } } const Button = ({classes, children}) => ( <button className={classes.button}> <span className={classes.label}> {children} </span> </button> ) export default injectSheet(styles)(Button) https://github.com/cssinjs/jss
  • 23. Hasan @ DEV6 – #WEBU17 var Block = require('jsxstyle/Block'); var React = require('react'); var MyComponent = React.createClass({ render: function() { return <Block color="red">Hello, world!</Block>; } }); https://github.com/smyte/jsxstyle
  • 24. Hasan @ DEV6 – #WEBU17 Routing Angular has one routing model, driven by the URL @angular/router is engineered for many scenarios React has many different options, depending on your app architecture react-router, fluxxor-react-router, react-redux-router
  • 25. Hasan @ DEV6 – #WEBU17 template: ` <h1>Angular Router</h1> <nav> <a routerLink="/crisis-center" routerLinkActive="active">Crisis Center</a> <a routerLink="/heroes" routerLinkActive="active">Heroes</a> </nav> <router-outlet></router-outlet> ` const appRoutes: Routes = [ { path: 'crisis-center', component: CrisisListComponent }, { path: 'hero/:id', component: HeroDetailComponent }, { path: 'heroes', component: HeroListComponent, data: { title: 'Heroes List' } }, { path: '', redirectTo: '/heroes', pathMatch: 'full' }, { path: '**', component: PageNotFoundComponent } ];
  • 26. Hasan @ DEV6 – #WEBU17 // ./src/index.jsx import React, { Component } from 'react'; import { render } from 'react-dom'; // Import routing components import {Router, Route} from 'react-router'; class Home extends Component { render(){ return (<h1>Hi</h1>); } } render( <Router> <!--Each route is defined with Route--> <Route path="/" component={Home}/> </Router>, document.getElementById('container') ); https://scotch.io/tutorials/routing-react-apps-the-complete-guide
  • 27. Hasan @ DEV6 – #WEBU17 import React from 'react' import ReactDOM from 'react-dom' import { createStore, combineReducers } from 'redux' import { Provider } from 'react-redux' import { Router, Route, browserHistory } from 'react-router' import { syncHistoryWithStore, routerReducer } from 'react-router-redux' import reducers from '<project-path>/reducers' const store = createStore( combineReducers({ ...reducers, routing: routerReducer }) ) // Create an enhanced history that syncs navigation events with the store const history = syncHistoryWithStore(browserHistory, store) ReactDOM.render( <Provider store={store}> <Router history={history}> <Route path="/" component={App}> <Route path="foo" component={Foo}/> <Route path="bar" component={Bar}/> </Route> </Router> </Provider>, document.getElementById('mount') ) https://github.com/reactjs/react-router-redux
  • 28. Hasan @ DEV6 – #WEBU17 Testing Angular comes with extensive support for jasmine with karma and protractor React varies by project, some use Jest, others use Mocha/Chai/Enzyme
  • 29. Hasan @ DEV6 – #WEBU17 Cross-platform apps Extend cross platform experience beyond the browser Progressive Web Applications Cordova / Hybrid Applications NativeScript / React Native
  • 30. Hasan @ DEV6 – #WEBU17 Angular + React = ? react-native-renderer – Angular project in a react native app ng-redux – Use redux (popularized by React) in your Angular projects
  • 31. Hasan @ DEV6 – #WEBU17 Summary Equal, yet different:Two approaches to solving common problems all developers face. Choice between Angular and React is ultimately driven by an organization’s development philosophy.
  • 32. Hasan @ DEV6 – #WEBU17 ThankYou! Questions?