SlideShare una empresa de Scribd logo
1 de 95
Descargar para leer sin conexión
Interoperable
Component Patterns
EmberConf 2016
twitter.com/mixonic
Ember.js Core Team
madhatted.com
twitter.com/mixonic
Ember.js Core Team
madhatted.com
>1,800 people!!
emberjs.com/ember-community-survey-2016
emberjs.com/ember-community-survey-2016
“The elements of this language are
entities called patterns. Each pattern
describes a problem that occurs over
and over again in our environment, and
then describes the core of the solution
to that problem, in such a way that you
can use this solution a million times
over, without ever doing it the same
way twice.”
–Christopher Alexander
User-centric
Designed based on
experience
A pattern is a not a guide
to implementation
~~ Prelude ~~
What we talk about
when we talk about
interoperability.
and web components
Rails server builds an HTML string
Browser parses HTML string
Component boots in the browser
Possible Consumer #1
Rails server builds an HTML string
Browser parses HTML string
Component boots in the browser
Possible Consumer #1
React template builds some DOM
Component boots in the browser
Component is implemented w/Vue.js
Possible Consumer #2
Possible Consumer #2
React template builds some DOM
Component boots in the browser
Component is implemented w/Vue.js
Riot template is rendered Server-side
Component boots on the server
Component renders and resulting
HTML goes back in the HTTP response
Possible Consumer #3
Riot template is rendered Server-side
Component boots on the server
Component renders and resulting
HTML goes back in the HTTP response
Possible Consumer #3
A component usable
from any client-side
consumer.
A component usable
from any client-side
consumer.
Ember Template
React/JSX
Angular 1.x Template
Angular 2 Template
DOM
HTML
~~ Pattern #1 ~~
Use Custom Elements
via a polyfill
document.createElement(

'my-component'

);
<my-component>

</my-component>
DOM
HTML
Angular 2 TemplateEmber Template
<my-component>
</my-component>
React/JSX
Angular 1.x Template
document.createElement(

'my-component'

);
<my-component>

</my-component>
DOM
HTML
<my-component>

</my-component>
<my-component>

</my-component>
<my-component>

</my-component>
1 class MyComponent extends HTMLElement {
2 attachedCallback() {
3 console.log('Now attached to the document');
4 }
5 };
6 document.registerElement('my-component', MyComponent);
Custom Elements Working Draft, 26 February 2016
1 class MyComponent extends HTMLElement {
2 attachedCallback() {
3 console.log('Now attached to the document');
4 }
5 };
6 window.customElements.define('my-component', MyComponen
Custom Elements Working Draft, 29 March 2016
webcomponents.org/polyfills/custom-elements
x-tag.github.io
www.polymer-project.org
Angular 2 TemplateEmber Template
React/JSX
Angular 1.x Template
DOM
HTML
<my-component>
</my-component>
document.createElement(

'my-component'

);
<my-component>

</my-component>
<my-component>

</my-component>
<my-component>

</my-component>
<my-component>

</my-component>
~~ Pattern #2 ~~
Pass attributes, then
deserialize them to
properties
~~ Pattern #2 ~~
Pass attributes, then
deserialize them to
properties on change
Component author concerns
<div id="wrapper"></div>
<div id="wrapper"></div>
let d = document.createElement('div');
d.setAttribute('id', 'wrapper');
<div id="wrapper"></div>
let d = document.createElement('div');
d.setAttribute('id', 'wrapper');
d.getAttribute('id'); // => 'wrapper'
d.id; // => 'wrapper'
let d = document.createElement('div');
d.setAttribute('wrapper-id', 'main');
<div wrapper-id="main"></div>
let d = document.createElement('div');
d.setAttribute('wrapper-id', 'main');
d.getAttribute('wrapper-id'); // => 'main'
d['wrapper-id']; // => undefined
<div wrapper-id="main"></div>
let d = document.createElement('div');
d.setAttribute('hidden', '');
<div hidden></div>
d.getAttribute('hidden'); // => ''
d.hidden; // => true
let d = document.createElement('div');
d.setAttribute('hidden', '');
<div hidden></div>
<div id="wrapper" wrapper-id="main" hidden></div>
attribute and
property
attribute and
boolean property
attribute, no
property
<div id="wrapper" wrapper-id="main" hidden></div>
attribute and
property
attribute and
boolean property
attribute, no
property
<div id="wrapper" wrapper-id="main" hidden></div>
<select tabindex="3" multiple="" size="-4" form="login"></select>
1 <my-component count="3" running></my-component>
1 class MyComponent extends HTMLElement {
2 attachedCallback() {
3 console.log('Now attached to the document');
4 }
5 };
6 window.customElements.define('my-component', MyComponen
Component consumer concerns
DOM
Angular 2 TemplateEmber Template
let c = document.createElement(
‘my-component'
);
c.setAttribute('count', '5');
<my-component count=“5">
</my-component>
<my-component count=“5">
</my-component>
<my-component count=“5">
</my-component>
<my-component count=“5">
</my-component>
<my-component count=“5">
</my-component>
React/JSX
Angular 1.x TemplateHTML
DOM
Angular 2 TemplateEmber Template
<my-component count={count}>
</my-component>
<my-component count={{count}}>
</my-component>
<my-component count={{count}}>
</my-component>
<my-component [attr.count]="coun
</my-component>
React/JSX
Angular 1.x TemplateHTML
let c = document.createElement(
‘my-component'
);
c.setAttribute('count', '5');
<my-component count=“5">
</my-component>
Back to author concerns
~~ Pattern #2 ~~
Pass attributes, then
deserialize them to
properties
Polymer: reflecting between an attribute and property
1 Polymer({
2 is: 'my-component',
3 properties: {
4 count: Number
5 }
6 });
1 xtag.register('my-component', {
2 accessors: {
3 count: {
4 attribute: {},
5 get() {
6 let stringCount = this.getAttribute('count');
7 return parseInt(stringCount, 10);
8 },
9 set(numericValue) {
10 let value = ''+numericValue;
11 this.setAttribute('count', value);
12 return value;
13 }
14 }
15 }
16 });
x-tag: reflecting between an attribute and property
~~ Pattern #3 ~~
Communicate with
events
Consumer concerns
<AReactComponent log={function(){ console.log('baz'); }} />
{{an-ember-component log=(action 'log' 'baz')}}
Framework components
Custom Elements
<my-component log="function() { console.log('log') }"></my-component>
HTML Elements
div.setAttribute('onclick', ‘console.log("clicked")');
div.onclick = function() { console.log("clicked"); };
div.addEventListener('click', function(e){
window.event = e;
try {
div.onclick.call(event.target);
} finaly() {
window.event = null;
}
}
<div onclick="console.log('clicked')"></div>
Pass an attribute? A string of a function has
no context (this is lost)
Pass a property? No way to do this in HTML
and some frameworks
Add an event listener? No way to add an event
listener in HTML
Pass an attribute? A string of a function has
no context (this is lost)
Pass a property? No way to do this in HTML
and some frameworks
Add an event listener? No way to add an event
listener in HTML
~~ Pattern #3 ~~
Communicate with
events
Events are how HTML Elements communicate
so
Custom Elements should behave the same way
Why Events? #1
<div></div>
<my-component></my-component>
1 let event = document.createEvent('Event');
2 event.initEvent('click', true, true); // canBubble, cancelable
3 element.dispatchEvent(event);
1 let event = document.createEvent('Event');
2 event.initEvent('click', true, true); // canBubble, cancelable
3 element.dispatchEvent(event);
Events have a somewhat common interface
Why Events? #2
Event Listener
1 element.addEventListener('click', function(e) {
2 e.target; // What element dispatched the event
3 e.currentTarget; // What element the handler is attached to
4 e.timeStamp; // When the event started
5 // Plus properties and methods about phases
6 });
1 element.callbackFunction = function() {
2 // What are the arguments this time?
3 };
Callback as property
<my-component></my-component>
1 let event = document.createEvent('CustomEvent');
2 event.initCustomEvent('mousewobble', true, true, {direction: 'vertical'});
3 element.dispatchEvent(event);
1 element.addEventListener('mousewobble', function(e) {
2 e.detail.direction; // 'vertical'
3 });
Events are compatible with alternative
consumer patterns (delegation)
Why Events? #3
Component consumer concerns
Angular 2 Template
1 <my-component (mousewobble)="methodOnComponent($event)">
2 </my-component>
3
4 <my-component on-mousewobble="methodOnComponent($event)">
5 </my-component>
~~ Pattern #3 ~~
Communicate with
events
~~ Pattern #1 ~~
Use Custom
Elements via a
polyfill
~~ Pattern #3 ~~
Communicate
with events
~~ Pattern #2 ~~
Pass attributes, then
deserialize them to
properties
Practical recommendations for interoperable component authors
use x-tag or Polymer
Practical recommendations for interoperable component authors
use x-tag or Polymer
Practical recommendations for interoperable component authors
document usage in several environments
use x-tag or Polymer
Practical recommendations for interoperable component authors
document usage in several environments
punt on Shadow DOM
use x-tag or Polymer
Practical recommendations for interoperable component authors
document usage in several environments
punt on Shadow DOM
don’t expose implementation details
~~ Coda ~~
Ember
<my-component count="5"></my-component>
<my-component count="5"></my-component>
<my-component {{attribute count=5}}></my-component>
<my-component count="5"></my-component>
<my-component {{attribute count=5}}></my-component>
<my-component {{property count=5}}></my-component>
<my-component count="5"></my-component>
<my-component {{attribute count=5}}></my-component>
<my-component {{property count=5}}></my-component>
<my-component {{style color="red" width=(max a b)}}></my-component>
<my-component count="5"></my-component>
<my-component {{attribute count=5}}></my-component>
<my-component {{property count=5}}></my-component>
<my-component {{style color="red" width=(max a b)}}></my-component>
<my-component {{add-event-listener 'mousewobble' (action 'wobble')}}></my-component>
twitter.com/mixonic
Ember.js Core Team
madhatted.com

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Webcomponents at Frontend meetup 2014.06.25
Webcomponents at Frontend meetup 2014.06.25Webcomponents at Frontend meetup 2014.06.25
Webcomponents at Frontend meetup 2014.06.25
 
Android Testing
Android TestingAndroid Testing
Android Testing
 
Controller specs
Controller specsController specs
Controller specs
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
 
Angular.js Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto University
 
Trustparency web doc spring 2.5 & hibernate
Trustparency web doc   spring 2.5 & hibernateTrustparency web doc   spring 2.5 & hibernate
Trustparency web doc spring 2.5 & hibernate
 
Speed up your GWT coding with gQuery
Speed up your GWT coding with gQuerySpeed up your GWT coding with gQuery
Speed up your GWT coding with gQuery
 
React render props
React render propsReact render props
React render props
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
 
Angular js
Angular jsAngular js
Angular js
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2
 
«От экспериментов с инфраструктурой до внедрения в продакшен»​
«От экспериментов с инфраструктурой до внедрения в продакшен»​«От экспериментов с инфраструктурой до внедрения в продакшен»​
«От экспериментов с инфраструктурой до внедрения в продакшен»​
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
 
Ext GWT 3.0 Theming and Appearances
Ext GWT 3.0 Theming and AppearancesExt GWT 3.0 Theming and Appearances
Ext GWT 3.0 Theming and Appearances
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Jquery examples
Jquery examplesJquery examples
Jquery examples
 
Laravel 5.2 Gates, AuthServiceProvider and Policies
Laravel 5.2 Gates, AuthServiceProvider and PoliciesLaravel 5.2 Gates, AuthServiceProvider and Policies
Laravel 5.2 Gates, AuthServiceProvider and Policies
 
Introduction to React & Redux
Introduction to React & ReduxIntroduction to React & Redux
Introduction to React & Redux
 

Similar a Interoperable Component Patterns

react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react library
janet736113
 
User controls
User controlsUser controls
User controls
aspnet123
 
Models, controllers and views
Models, controllers and viewsModels, controllers and views
Models, controllers and views
priestc
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mohammad Shaker
 

Similar a Interoperable Component Patterns (20)

Angular2 + rxjs
Angular2 + rxjsAngular2 + rxjs
Angular2 + rxjs
 
Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Capstone ms2
Capstone ms2Capstone ms2
Capstone ms2
 
Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013
 
react-slides.pptx
react-slides.pptxreact-slides.pptx
react-slides.pptx
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
React for Re-use: Creating UI Components with Confluence Connect
React for Re-use: Creating UI Components with Confluence ConnectReact for Re-use: Creating UI Components with Confluence Connect
React for Re-use: Creating UI Components with Confluence Connect
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
react-slides.pdf
react-slides.pdfreact-slides.pdf
react-slides.pdf
 
react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react library
 
User controls
User controlsUser controls
User controls
 
Angular 2.0 - What to expect
Angular 2.0 - What to expectAngular 2.0 - What to expect
Angular 2.0 - What to expect
 
Models, controllers and views
Models, controllers and viewsModels, controllers and views
Models, controllers and views
 
Hooks and Events in Drupal 8
Hooks and Events in Drupal 8Hooks and Events in Drupal 8
Hooks and Events in Drupal 8
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
 
Lightning Components Workshop
Lightning Components WorkshopLightning Components Workshop
Lightning Components Workshop
 
Relevance trilogy may dream be with you! (dec17)
Relevance trilogy  may dream be with you! (dec17)Relevance trilogy  may dream be with you! (dec17)
Relevance trilogy may dream be with you! (dec17)
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
 
Magic of web components
Magic of web componentsMagic of web components
Magic of web components
 

Más de Matthew Beale

Scalable vector ember
Scalable vector emberScalable vector ember
Scalable vector ember
Matthew Beale
 

Más de Matthew Beale (15)

Ember.js Module Loading
Ember.js Module LoadingEmber.js Module Loading
Ember.js Module Loading
 
LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017
 
Ember Community 2016 - Be the Bark
Ember Community 2016 - Be the BarkEmber Community 2016 - Be the Bark
Ember Community 2016 - Be the Bark
 
Attribute actions
Attribute actionsAttribute actions
Attribute actions
 
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web Standards
 
New Component Patterns in Ember.js
New Component Patterns in Ember.jsNew Component Patterns in Ember.js
New Component Patterns in Ember.js
 
Scalable vector ember
Scalable vector emberScalable vector ember
Scalable vector ember
 
Testing Ember Apps: Managing Dependency
Testing Ember Apps: Managing DependencyTesting Ember Apps: Managing Dependency
Testing Ember Apps: Managing Dependency
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.js
 
Snappy Means Happy: Performance in Ember Apps
Snappy Means Happy: Performance in Ember AppsSnappy Means Happy: Performance in Ember Apps
Snappy Means Happy: Performance in Ember Apps
 
Client-side Auth with Ember.js
Client-side Auth with Ember.jsClient-side Auth with Ember.js
Client-side Auth with Ember.js
 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.js
 
Complex Architectures in Ember
Complex Architectures in EmberComplex Architectures in Ember
Complex Architectures in Ember
 
Ember and containers
Ember and containersEmber and containers
Ember and containers
 

Último

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
 

Último (20)

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)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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...
 
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?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Interoperable Component Patterns