SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
Thinking in Components
Web Components, Polymer, React.js, Angular.js
Anton Ivanov, Helsinki.js, 28.04.2015
Why?
● Maintainability
● Code reuse
● Similar to classes, functions
● Familiar concept
1997
2015
div soup
A bit of Philosophy
Powerful Language
“Every powerful language has three mechanisms:
● primitive expressions - which represent the
simplest entities the language is concerned with
● means of combination, by which compound
elements are built from simpler ones, and
● means of abstraction, by which compound
elements can be named and manipulated as units”
“Structure and Interpretation of Computer
Programs”, The MIT Press, ISBN-10: 0262510871
Web Components
● HTML imports
● Custom elements
● Shadow DOM
● Templates
Set of standards, a bit like DOM. Provides low
level mechanisms.
HTML Imports
● #include for HTML
● Styles, scripts, markup imported together
<link rel="import" href="breadcrumbs.html">
Custom Elements
● Extend HTML
● Standard APIs continue working
var prototype = Object.create(HTMLElement.prototype);
prototype.setPath = function(path) {...};
document.registerElement('comp-breadcrumbs', {
prototype: prototype
});
Shadow DOM
● Hide markup implementation details
● Shadow root
prototype.createdCallback = function() {
...
this.createShadowRoot().appendChild(element);
};
Shadow DOM
● Already used by <video> in Chrome
Templates
● Inert pieces of markup
● No advanced binding, not like Mustache
● Styles
<template id="breadcrumbs-template">
<style>
…
</style>
<div class="breadcrumbs"></div>
</template>
Templates
● To activate should be imported
prototype.createdCallback = function() {
var element = document.importNode(template.content,
true);
...
this.createShadowRoot().appendChild(element);
};
Demo
● Source
● Viewable in Chrome
Polymer
● Enables support of new standards
● Advanced templating, inheritance
● Set of ready to extend useful components
● Minor differences with the standards
Library built on top of Web Components
standards, like jQuery in 2000s.
Advanced Templating
● Loops, conditionals
● Data binding
<template id="breadcrumbs-template">
…
<div class="breadcrumbs" on-keypress="{{_onKeypress}}">
<template id="crumbs" repeat="{{crumb, index in crumbs}}">
...
</template>
</div>
</template>
Useful Components
● core-item, core-ajax, core-collapse, etc.
● Inherit to use in your component
<polymer-element name="my-element" extends="core-ajax">
Demo
● Source or standards-only source
● Viewable not only in Chrome
React.js
● Components ~ functions
● Declarative
● Everything is a component
● Own tree of components in memory
● Clever to re-render only what's needed
Transforms data into 'immutable' HTML via a
tree of components. View library not a
framework.
Component
● render method
● Life cycle hooks
● props - immutable state, set as attributes
● state – mutable state
● Hierarchy of components, data 'flows' from
root
Component
var CrumbSeparator = React.createClass({
render: function() {
return (
<span className="crumb-separator"
title={this.props.tooltip}>{this.props.value}</span>
)
}
});
● Declarative, functional-like
● JSX for templates
Component
var BreadcrumbsDemo = React.createClass({
...
render: function() {
return (
<div>
<div id="breadcrumb-container">
<Breadcrumbs path={this.state.path} maxEntries="5"
onChange={this.onPathChange}/>
</div>
...
</div>
)
● Nesting
Flux
● How data should be fed to component tree
● Data flows through one control point
Recommended architecture for React.
Flux
Demo
● Source
● Viewable
Angular.js
● Testability
● Templates, view updates
● Directives
● Predefined directives
● Components implemented as directives,
not a central feature
MVC framework. Enhances HTML annotated
with directives, handles routine tasks.
Testability
angular.module('Components')
.controller('breadcrumbsController', function ($scope) {
…
});
● Dependency injection
● Modularity
Templates
<div class="breadcrumbs">
<span ng-class="{'crumb': !pathPart.dots, 'crumb-separator':
pathPart.dots}"
ng-click="activatePathPart(pathPart)" ...
ng-repeat-start="pathPart in pathToRender">
{{pathPart.value}}
</span>
<span class="crumb-separator" ng-if="$index <
pathToRender.length - 1" ng-repeat-end>&gt;</span>
</div>
● Two-way data binding
● HTML generation
Directives
● Predefined: ng-app, ng-controller, etc.
● Annotating HTML
● As classes, attributes, elements
Directives
angular.module('Components')
.directive('compBreadcrumbs', function () {
return {
restrict: 'E',
scope: {
path: '=',
...
},
controller: 'breadcrumbsController',
templateUrl: 'breadcrumbs.tpl.html'
};
});
Scopes
● Model
● Hierarchy
● Bound to HTML with special directives
Controllers
<body ng-app="BreadcrumbsDemo" ng-controller="Path">
...
</body>
angular.module('Components')
.controller('Path', function Path($scope, fullPath) {
$scope.reset = function() {
$scope.path = fullPath;
};
...
});
● Augment scope with behavior
More core concepts...
● Services
● Factories
● Constants
Angular 2.0
@Component({selector: 'my-app' })
@Template({inline: '<h1>Hello {{ name }}</h1>' })
class MyAppComponent {
constructor() {
this.name = 'Alice';
}
}
● Simplified
● Focus on components
● ES6 support
Demo
● Source
● Viewable
Mental Model
● Thinking in components
Summary
● Web Components just low level standards
● Polymer like jQuery
● If more needed, React or Angular
● React philosophy more in line with JS
● Angular radically redefines JS
development practices. Good or bad?
● Future integration with Web Components
● Other options
Thank you!
Attribution
● Image of Apple Web site in 1997 from https://www.magicdust.com.au/evolution-apples-website/
● Cloud9 IDE image taken as screenshot from https://c9.io/ (example of a Web app in 2015)
● “School of Athens” fresco by Raphael, Apostolic Palace, Vatican City, fragment from
http://en.wikipedia.org/wiki/The_School_of_Athens#/media/File:Sanzio_01.jpg
● “Structure and Interpretation of Computer Programs” book cover image from
https://mitpress.mit.edu/sicp/full-text/book/book.html
● Web Components logo from http://webcomponents.org/
● Polymer logo from https://www.polymer-project.org/0.5/
● React.js logo from https://facebook.github.io/react/
● Flux architecture image from https://facebook.github.io/react/docs/flux-overview.html
● “Java EE Design Patterns” book cover image from
http://www.wrox.com/WileyCDA/WroxTitle/Professional-Java-EE-Design-Patterns.productCd-111884341X.html
● Angular.js logo from https://angular.io/
● App split into components image from https://facebook.github.io/react/docs/thinking-in-react.html
● Curtains image by eveyD http://eveyd.deviantart.com
● Made with LibreOffice Impress https://www.libreoffice.org/discover/impress/

Mais conteúdo relacionado

Mais procurados

AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
Kai Koenig
 

Mais procurados (20)

AngularJS introduction
AngularJS introductionAngularJS introduction
AngularJS introduction
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
 
Workshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVCWorkshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVC
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJS
 
Workshop 16: EmberJS Parte I
Workshop 16: EmberJS Parte IWorkshop 16: EmberJS Parte I
Workshop 16: EmberJS Parte I
 
OpenCms Days 2013 - Details of the OpenCms 9 detail pages
OpenCms Days 2013 - Details of the OpenCms 9 detail pagesOpenCms Days 2013 - Details of the OpenCms 9 detail pages
OpenCms Days 2013 - Details of the OpenCms 9 detail pages
 
Chap4 4 2
Chap4 4 2Chap4 4 2
Chap4 4 2
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Workshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewWorkshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General Overview
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JS
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
 
Angular js 1.3 basic tutorial
Angular js 1.3 basic tutorialAngular js 1.3 basic tutorial
Angular js 1.3 basic tutorial
 
Java script tutorial
Java script tutorialJava script tutorial
Java script tutorial
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
 
준비하세요 Angular js 2.0
준비하세요 Angular js 2.0준비하세요 Angular js 2.0
준비하세요 Angular js 2.0
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 

Destaque

Chapter 12 Reasoning!
Chapter 12 Reasoning!Chapter 12 Reasoning!
Chapter 12 Reasoning!
VickD
 
Week 3 Lecture: Gestalt Theories
Week 3 Lecture: Gestalt TheoriesWeek 3 Lecture: Gestalt Theories
Week 3 Lecture: Gestalt Theories
lizlance
 
Gestalt Psychology
Gestalt PsychologyGestalt Psychology
Gestalt Psychology
Piper Uy
 
Problem solving ppt
Problem solving pptProblem solving ppt
Problem solving ppt
Ika Rose
 
Gestalt presentation
Gestalt presentationGestalt presentation
Gestalt presentation
Lily Pad
 
Cognitive theory
Cognitive theoryCognitive theory
Cognitive theory
yaseen zebary
 
Decision making & problem solving
Decision making & problem solvingDecision making & problem solving
Decision making & problem solving
ashish1afmi
 

Destaque (20)

Thinking Reasoning & Problem Solving (Human Behavior)
Thinking Reasoning & Problem Solving (Human Behavior)Thinking Reasoning & Problem Solving (Human Behavior)
Thinking Reasoning & Problem Solving (Human Behavior)
 
Gestalt Psychology
Gestalt PsychologyGestalt Psychology
Gestalt Psychology
 
Chapter 12 Reasoning!
Chapter 12 Reasoning!Chapter 12 Reasoning!
Chapter 12 Reasoning!
 
Thinking, reasoning, decision making, and problem solving: All in one Present...
Thinking, reasoning, decision making, and problem solving: All in one Present...Thinking, reasoning, decision making, and problem solving: All in one Present...
Thinking, reasoning, decision making, and problem solving: All in one Present...
 
Thinking and Reasoning
Thinking and ReasoningThinking and Reasoning
Thinking and Reasoning
 
Week 3 Lecture: Gestalt Theories
Week 3 Lecture: Gestalt TheoriesWeek 3 Lecture: Gestalt Theories
Week 3 Lecture: Gestalt Theories
 
Gestalt Psychology
Gestalt PsychologyGestalt Psychology
Gestalt Psychology
 
Problem Solving PowerPoint PPT Content Modern Sample
Problem Solving PowerPoint PPT Content Modern SampleProblem Solving PowerPoint PPT Content Modern Sample
Problem Solving PowerPoint PPT Content Modern Sample
 
Problem solving ppt
Problem solving pptProblem solving ppt
Problem solving ppt
 
Gestalt LEARNING THEORY SULTAN THE MONKEY
Gestalt LEARNING THEORY SULTAN THE MONKEYGestalt LEARNING THEORY SULTAN THE MONKEY
Gestalt LEARNING THEORY SULTAN THE MONKEY
 
Gestalt Theory
Gestalt TheoryGestalt Theory
Gestalt Theory
 
information processing theory
information processing theoryinformation processing theory
information processing theory
 
Gestalt psychology slideshare
Gestalt psychology slideshareGestalt psychology slideshare
Gestalt psychology slideshare
 
Thiniking
ThinikingThiniking
Thiniking
 
Problem Solving and Decision Making
Problem Solving and Decision MakingProblem Solving and Decision Making
Problem Solving and Decision Making
 
Problem Solving Method
Problem Solving MethodProblem Solving Method
Problem Solving Method
 
Gestalt presentation
Gestalt presentationGestalt presentation
Gestalt presentation
 
Cognitive theory
Cognitive theoryCognitive theory
Cognitive theory
 
Decision making & problem solving
Decision making & problem solvingDecision making & problem solving
Decision making & problem solving
 
Decision making ppt
Decision making pptDecision making ppt
Decision making ppt
 

Semelhante a Thinking in Components

MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
Dilip Patel
 

Semelhante a Thinking in Components (20)

AngularJS
AngularJSAngularJS
AngularJS
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
AngularJS
AngularJSAngularJS
AngularJS
 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Dust.js
Dust.jsDust.js
Dust.js
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introduction
 
Introduction to Ember.js
Introduction to Ember.jsIntroduction to Ember.js
Introduction to Ember.js
 
CraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJSCraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJS
 
Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
 
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
 
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
 
Angular JS, steal the idea
Angular JS, steal the ideaAngular JS, steal the idea
Angular JS, steal the idea
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014
 
Nicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JSNicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JS
 
Extending CMS Made Simple
Extending CMS Made SimpleExtending CMS Made Simple
Extending CMS Made Simple
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS Fundamentals
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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?
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Thinking in Components

  • 1. Thinking in Components Web Components, Polymer, React.js, Angular.js Anton Ivanov, Helsinki.js, 28.04.2015
  • 2. Why? ● Maintainability ● Code reuse ● Similar to classes, functions ● Familiar concept
  • 6. A bit of Philosophy
  • 7. Powerful Language “Every powerful language has three mechanisms: ● primitive expressions - which represent the simplest entities the language is concerned with ● means of combination, by which compound elements are built from simpler ones, and ● means of abstraction, by which compound elements can be named and manipulated as units” “Structure and Interpretation of Computer Programs”, The MIT Press, ISBN-10: 0262510871
  • 8. Web Components ● HTML imports ● Custom elements ● Shadow DOM ● Templates Set of standards, a bit like DOM. Provides low level mechanisms.
  • 9. HTML Imports ● #include for HTML ● Styles, scripts, markup imported together <link rel="import" href="breadcrumbs.html">
  • 10. Custom Elements ● Extend HTML ● Standard APIs continue working var prototype = Object.create(HTMLElement.prototype); prototype.setPath = function(path) {...}; document.registerElement('comp-breadcrumbs', { prototype: prototype });
  • 11. Shadow DOM ● Hide markup implementation details ● Shadow root prototype.createdCallback = function() { ... this.createShadowRoot().appendChild(element); };
  • 12. Shadow DOM ● Already used by <video> in Chrome
  • 13. Templates ● Inert pieces of markup ● No advanced binding, not like Mustache ● Styles <template id="breadcrumbs-template"> <style> … </style> <div class="breadcrumbs"></div> </template>
  • 14. Templates ● To activate should be imported prototype.createdCallback = function() { var element = document.importNode(template.content, true); ... this.createShadowRoot().appendChild(element); };
  • 16. Polymer ● Enables support of new standards ● Advanced templating, inheritance ● Set of ready to extend useful components ● Minor differences with the standards Library built on top of Web Components standards, like jQuery in 2000s.
  • 17. Advanced Templating ● Loops, conditionals ● Data binding <template id="breadcrumbs-template"> … <div class="breadcrumbs" on-keypress="{{_onKeypress}}"> <template id="crumbs" repeat="{{crumb, index in crumbs}}"> ... </template> </div> </template>
  • 18. Useful Components ● core-item, core-ajax, core-collapse, etc. ● Inherit to use in your component <polymer-element name="my-element" extends="core-ajax">
  • 19. Demo ● Source or standards-only source ● Viewable not only in Chrome
  • 20. React.js ● Components ~ functions ● Declarative ● Everything is a component ● Own tree of components in memory ● Clever to re-render only what's needed Transforms data into 'immutable' HTML via a tree of components. View library not a framework.
  • 21. Component ● render method ● Life cycle hooks ● props - immutable state, set as attributes ● state – mutable state ● Hierarchy of components, data 'flows' from root
  • 22. Component var CrumbSeparator = React.createClass({ render: function() { return ( <span className="crumb-separator" title={this.props.tooltip}>{this.props.value}</span> ) } }); ● Declarative, functional-like ● JSX for templates
  • 23. Component var BreadcrumbsDemo = React.createClass({ ... render: function() { return ( <div> <div id="breadcrumb-container"> <Breadcrumbs path={this.state.path} maxEntries="5" onChange={this.onPathChange}/> </div> ... </div> ) ● Nesting
  • 24. Flux ● How data should be fed to component tree ● Data flows through one control point Recommended architecture for React.
  • 25. Flux
  • 27. Angular.js ● Testability ● Templates, view updates ● Directives ● Predefined directives ● Components implemented as directives, not a central feature MVC framework. Enhances HTML annotated with directives, handles routine tasks.
  • 29. Templates <div class="breadcrumbs"> <span ng-class="{'crumb': !pathPart.dots, 'crumb-separator': pathPart.dots}" ng-click="activatePathPart(pathPart)" ... ng-repeat-start="pathPart in pathToRender"> {{pathPart.value}} </span> <span class="crumb-separator" ng-if="$index < pathToRender.length - 1" ng-repeat-end>&gt;</span> </div> ● Two-way data binding ● HTML generation
  • 30. Directives ● Predefined: ng-app, ng-controller, etc. ● Annotating HTML ● As classes, attributes, elements
  • 31. Directives angular.module('Components') .directive('compBreadcrumbs', function () { return { restrict: 'E', scope: { path: '=', ... }, controller: 'breadcrumbsController', templateUrl: 'breadcrumbs.tpl.html' }; });
  • 32. Scopes ● Model ● Hierarchy ● Bound to HTML with special directives
  • 33. Controllers <body ng-app="BreadcrumbsDemo" ng-controller="Path"> ... </body> angular.module('Components') .controller('Path', function Path($scope, fullPath) { $scope.reset = function() { $scope.path = fullPath; }; ... }); ● Augment scope with behavior
  • 34. More core concepts... ● Services ● Factories ● Constants
  • 35. Angular 2.0 @Component({selector: 'my-app' }) @Template({inline: '<h1>Hello {{ name }}</h1>' }) class MyAppComponent { constructor() { this.name = 'Alice'; } } ● Simplified ● Focus on components ● ES6 support
  • 37. Mental Model ● Thinking in components
  • 38. Summary ● Web Components just low level standards ● Polymer like jQuery ● If more needed, React or Angular ● React philosophy more in line with JS ● Angular radically redefines JS development practices. Good or bad? ● Future integration with Web Components ● Other options
  • 40. Attribution ● Image of Apple Web site in 1997 from https://www.magicdust.com.au/evolution-apples-website/ ● Cloud9 IDE image taken as screenshot from https://c9.io/ (example of a Web app in 2015) ● “School of Athens” fresco by Raphael, Apostolic Palace, Vatican City, fragment from http://en.wikipedia.org/wiki/The_School_of_Athens#/media/File:Sanzio_01.jpg ● “Structure and Interpretation of Computer Programs” book cover image from https://mitpress.mit.edu/sicp/full-text/book/book.html ● Web Components logo from http://webcomponents.org/ ● Polymer logo from https://www.polymer-project.org/0.5/ ● React.js logo from https://facebook.github.io/react/ ● Flux architecture image from https://facebook.github.io/react/docs/flux-overview.html ● “Java EE Design Patterns” book cover image from http://www.wrox.com/WileyCDA/WroxTitle/Professional-Java-EE-Design-Patterns.productCd-111884341X.html ● Angular.js logo from https://angular.io/ ● App split into components image from https://facebook.github.io/react/docs/thinking-in-react.html ● Curtains image by eveyD http://eveyd.deviantart.com ● Made with LibreOffice Impress https://www.libreoffice.org/discover/impress/