Upload
codemotion
View
37
Download
0
Embed Size (px)
Citation preview
@AndrewRota
Component-Based UI Architectures for the Web
Andrew Rota | @andrewrota
ROME 24-25 MARCH 2017
@AndrewRota
bit.ly/components_codemotionSlides online at:
@AndrewRota
Andrew RotaBoston, MA, USA
Software Architect at Wayfair
wayfair.com | wayfair.co.uk | wayfair.de
@AndrewRota
@AndrewRota
“ All models are wrong, but some are useful ”
George Box, statistician, Empirical Model-Building and Response Surfaces (1987)
@AndrewRota
Let’s put aside the client/server split as an implementation detail.*
* A very very important detail, just not one addressed in this model
@AndrewRota
“A component is a custom HTML tag whose behavior you implement using JavaScript and
whose appearance you describe using Handlebars templates. They allow you to create reusable
controls…”https://guides.emberjs.com/v1.10.0/concepts/core-concepts/#toc_components
This presentation is unaffiliated with the Ember project.Ember is a trademark of Tilde Inc.
@AndrewRota
“A component controls a patch of screen called a view.”
https://angular.io/docs/ts/latest/guide/architecture.html#!#components
@AndrewRota
“With Web Components, you can create reusable custom elements that...break your
app up into right-sized components.”https://www.polymer-project.org/1.0/
@AndrewRota
“Components let you split the UI into independent, reusable pieces, and think
about each piece in isolation.”https://facebook.github.io/react/
@AndrewRota
<music-playlist>
<music-playlist-item>
<h1>Symphony No. 40</h1>
<h2>Wolfgang Amadeus Mozart</h2>
</music-playlist-item>
</music-playlist>
<music-player track="1" playing />
@AndrewRota
<MusicPlaylist>
<MusicPlaylistItem>
<h1>Symphony No. 40</h1>
<h2>Wolfgang Amadeus Mozart</h2>
</MusicPlaylistItem>
</MusicPlaylist>
<MusicPlayer track={1} playing />
@AndrewRota
const List = (props) => {
return (
<ul>
{props.items.map(item => (
<li key={item.id}>{item.text}</li>
))}
</ul>
);
}
@AndrewRota
const List = (props) => {
return (
<ul>
{props.items.map(item => (
<li key={item.id}>{item.text}</li>
))}
</ul>
);
}
Input
@AndrewRota
const List = (props) => {
return (
<ul>
{props.items.map(item => (
<li key={item.id}>{item.text}</li>
))}
</ul>
);
}
Output
@AndrewRota
<app-wrapper>
<app-header>
<app-navigation />
</app-header>
<app-body>
<app-content />
</app-body>
</app-wrapper>
@AndrewRota
<my-nametag><strong>world</strong></my-nametag>
<div>
<h1>Hello, <slot></slot>.</h1>
</div>
<div>
<h1>Hello, <strong>world</strong>.</h1>
</div>
@AndrewRota
How composable are your components?
✅ - Can a component have children?
✅ - Do components define their interfaces?
✅ - ...with types?
✅ - Can you extend by composition?
@AndrewRota
“Cohesion within a module is the degree to which the module's elements belong together. In other words, it is a measure of how focused a module is. The idea is not just to divide software into arbitrary parts (i.e., modularity), but to keep
related issues in the same part.”
Software Engineering: Modern Approaches, 2nd ed. (pg. 352), Eric J. Braude, Michael E. Bernstein
@AndrewRota
How cohesive are your components?
✅ - Is there little “wiring-up” necessary?
✅ - Does a component have everything it needs?
✅ - If you change a property, how many places
does that change need to be made in?
@AndrewRota
Context-Independent
A context-independent component can be used
in different environments without modification.
@AndrewRota
How context independent are your components?
✅ - Can you “copy/paste” a component?
✅ - Can components define style boundaries?
✅ - ...error boundaries?
✅ - Do components require global state?
@AndrewRota
Colocated
A colocated component places related code in
the same place, regardless of technology.
@AndrewRota
Colocated
https://github.com/ant-design/ant-design/
@AndrewRota
Colocated
https://github.com/ant-design/ant-design/
Unit Tests
@AndrewRota
Colocated
https://github.com/ant-design/ant-design/
CSS Styles (LESS)
@AndrewRota
Colocated
https://github.com/ant-design/ant-design/
Localization
@AndrewRota
Colocated
https://github.com/ant-design/ant-design/
Markdown files with examples
@AndrewRota
How colocated are your components?
✅ - How many files does a component need?
✅ - What does the directory structure look like?
✅ - Can you review a component in once place?
@AndrewRota
“...an abstract system specification consisting primarily of functional components described in
terms of their behaviors and interfaces and component-component interconnections.”
Hayes-Roth, 1994, written for the ARPA Domain-Specific Software Architecture (DSSA) program
@AndrewRota
“...the organizational structure of a software system including components, connections, constraints,
and rationale”
Clements, Kogut, 1994, The Software Architecture Renaissance
@AndrewRota
In a component-based UI architecture we treat UI components and their connections as part of our
overall software architecture.
@AndrewRota
Components in the UI are no longer implementation details, they’re a core unit of the overall system.
@AndrewRota
UI Component
UI Component
UI Component
UI Component
UI Component
+ Client / Server Constraints
+ Platform Differences
+ Performance Considerations
+ Design / UX Concerns
@AndrewRota
1. Components are familiar2. Interfaces benefit from reusability3. Abstraction can be shared across disciplines
@AndrewRota
Familiarity<div>
<h1>Hello world</h1>
<img src="foo.jpg" />
</div>
HTML works a lot like components.
@AndrewRota
Familiarity<div>
<h1>Hello world</h1>
<img src="foo.jpg" />
</div>
HTML works a lot like components.**see web components
@AndrewRota
<MusicPlaylist>
<MusicPlaylistItem>
<h1>Symphony No. 40</h1>
<h2>Wolfgang Amadeus Mozart</h2>
</MusicPlaylistItem>
</MusicPlaylist>
<MusicPlayer track={1} playing />
Familiarity
@AndrewRota
React.createElement(
MusicPlaylist, null, React.createElement(
MusicPlaylistItem, null, React.createElement(
"H1", null, "Symphony No. 40"
), React.createElement(
"H2", null, "Wolfgang Amadeus Mozart"
)
)
),
React.createElement(MusicPlayer,
{ track: 1, playing: true }
);
Familiarity
(there’s a reason JSX is so popular)
@AndrewRota
ReusabilityThe more components are composable, context-independent,
cohesive, and colocated, the more easily they can be shared.
@AndrewRota
Reusability
https://www.webcomponents.org
@AndrewRota
Reusability
https://react.rocks/?q=calendar
@AndrewRota
Shared AbstractionUI work touches a lot of teams: design, product, and (often
multiple) engineering teams.
@AndrewRota
Shared AbstractionComponents as a UI concept can be useful across many different
types of teams and disciplines.
@AndrewRota
Shared Abstraction
https://material.io/guidelines/components/buttons.html#buttons-style
@AndrewRota
Shared Abstraction
https://material.io/guidelines/components/buttons.html#buttons-style
@AndrewRota
StateBut state is a core feature of software.
Especially UIs where state changes based on user input.
@AndrewRota
Managing state is hard
https://youtu.be/x7cQ3mrcKaY?t=15m55s
@AndrewRota
Universality - across platforms?Components for…
the web?
iOS apps?
Android apps?
desktop apps?
virtual reality?
@AndrewRota
Universality - across libraries?Components for…
react?
angular?
ember?
polymer?
plain JavaScript?
@AndrewRota
“ All models are wrong, but some are useful ”
George Box, statistician, Empirical Model-Building and Response Surfaces (1987)
@AndrewRota
Does a component-based UI model impact how you think about your overall application
architecture?
@AndrewRota
Grazie!
@AndrewRota
bit.ly/components_codemotionSlides online at: