SlideShare a Scribd company logo
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?

More Related Content

What's hot (20)

PDF
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
IT Event
 
PDF
Booting up with polymer
Marcus Hellberg
 
PDF
jQuery 1.9 and 2.0 - Present and Future
Richard Worth
 
PDF
Booting up with polymer
Marcus Hellberg
 
PDF
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
David Kaneda
 
PDF
Building a Secure App with Google Polymer and Java / Spring
sdeeg
 
PPTX
Disrupting the application eco system with progressive web applications
Chris Love
 
PDF
AtlasCamp 2015: Using add-ons to build add-ons
Atlassian
 
PPT
You Know WebOS
360|Conferences
 
PDF
Unlock the next era of UI design with Polymer
Rob Dodson
 
PDF
Building an HTML5 Video Player
Jim Jeffers
 
PDF
AspNetWhitePaper
tutorialsruby
 
PDF
Usability in the GeoWeb
Dave Bouwman
 
PPTX
Enough with the JavaScript already!
Nicholas Zakas
 
PDF
Enjoy the vue.js
TechExeter
 
PDF
Externalizing Chatter Using Heroku, Angular.js, Node.js and Chatter REST APIs
Salesforce Developers
 
PDF
The Complementarity of React and Web Components
Andrew Rota
 
PDF
HTML5 and the dawn of rich mobile web applications
James Pearce
 
PDF
Modern Web Application Development Workflow - EclipseCon Europe 2014
Stéphane Bégaudeau
 
PDF
Our application got popular and now it breaks
ColdFusionConference
 
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
IT Event
 
Booting up with polymer
Marcus Hellberg
 
jQuery 1.9 and 2.0 - Present and Future
Richard Worth
 
Booting up with polymer
Marcus Hellberg
 
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
David Kaneda
 
Building a Secure App with Google Polymer and Java / Spring
sdeeg
 
Disrupting the application eco system with progressive web applications
Chris Love
 
AtlasCamp 2015: Using add-ons to build add-ons
Atlassian
 
You Know WebOS
360|Conferences
 
Unlock the next era of UI design with Polymer
Rob Dodson
 
Building an HTML5 Video Player
Jim Jeffers
 
AspNetWhitePaper
tutorialsruby
 
Usability in the GeoWeb
Dave Bouwman
 
Enough with the JavaScript already!
Nicholas Zakas
 
Enjoy the vue.js
TechExeter
 
Externalizing Chatter Using Heroku, Angular.js, Node.js and Chatter REST APIs
Salesforce Developers
 
The Complementarity of React and Web Components
Andrew Rota
 
HTML5 and the dawn of rich mobile web applications
James Pearce
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Stéphane Bégaudeau
 
Our application got popular and now it breaks
ColdFusionConference
 

Similar to Angular vs React for Web Application Development (20)

PDF
The Road To Redux
Jeffrey Sanchez
 
PPTX
React, Flux and more (p1)
tuanpa206
 
PDF
React js
Rajesh Kolla
 
PDF
unit 3_Adv WTAdvanced Web Tecg Design_HTML_CSS_JAVASCRIPT_AJAX_PPT.pdf
GauravDwivedi695361
 
PPTX
React/Redux
Durgesh Vaishnav
 
PDF
React and redux
Mystic Coders, LLC
 
PDF
ReactJS for Programmers
David Rodenas
 
PPTX
ReactJS
Fatih Şimşek
 
PPTX
React + Flux = Joy
John Need
 
PDF
Intro to React
Jamal Sinclair O'Garro
 
PPTX
O365 Developer Bootcamp NJ 2018 - Material
Thomas Daly
 
PPTX
ReactJS
Ram Murat Sharma
 
PDF
Content-Driven Apps with React
Netcetera
 
PPTX
React + Redux Introduction
Nikolaus Graf
 
PPTX
React-JS.pptx
AnmolPandita7
 
PPTX
React js - The Core Concepts
Divyang Bhambhani
 
PDF
Getting started with React 16
Arun Michael Dsouza
 
PPTX
React, Flux and a little bit of Redux
Ny Fanilo Andrianjafy, B.Eng.
 
PDF
React - The JavaScript Library for User Interfaces
Jumping Bean
 
The Road To Redux
Jeffrey Sanchez
 
React, Flux and more (p1)
tuanpa206
 
React js
Rajesh Kolla
 
unit 3_Adv WTAdvanced Web Tecg Design_HTML_CSS_JAVASCRIPT_AJAX_PPT.pdf
GauravDwivedi695361
 
React/Redux
Durgesh Vaishnav
 
React and redux
Mystic Coders, LLC
 
ReactJS for Programmers
David Rodenas
 
React + Flux = Joy
John Need
 
Intro to React
Jamal Sinclair O'Garro
 
O365 Developer Bootcamp NJ 2018 - Material
Thomas Daly
 
Content-Driven Apps with React
Netcetera
 
React + Redux Introduction
Nikolaus Graf
 
React-JS.pptx
AnmolPandita7
 
React js - The Core Concepts
Divyang Bhambhani
 
Getting started with React 16
Arun Michael Dsouza
 
React, Flux and a little bit of Redux
Ny Fanilo Andrianjafy, B.Eng.
 
React - The JavaScript Library for User Interfaces
Jumping Bean
 
Ad

More from FITC (20)

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

Recently uploaded (20)

PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PDF
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
Practical Applications of AI in Local Government
OnBoard
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 

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?