There is a very small limit of characters on the Slideshare description. For a full transcript, see the presentation at SpeakerDeck.
https://speakerdeck.com/morewry/reusable-components-in-angular-architecture-transclusion-and-more
We’re hiring!
opentable.com/careers/
OpenTable is hiring! http://opentable.com/careers/
Questions?
Rachael L Moore
UI Engineer
Twitter: @morewry
Github: morewry
Kara Erickson
Web Engineer
Github: kara
About Us
[Rachael L Moore] At OpenTable we have two sides to our products, restaurant and diner. Since most of us here probably don't own restaurants, behind me is a small tour of what that looks like.
Our restaurant team is currently converting a large, feature-rich legacy system for restaurants into a web application called Guest Center. Guest Center is a growing application with a large backlog of features.
Since the functionality of those features is pretty self-contained, because they're highly task-specific, we realized we could get great results if we approached our product as a series of micro sites, or an app of apps, created and maintained by small teams.
But for that to really work, at the scale we need, we have to have really seamless and hopefully painless integration between those applications. For our own sake, because why make our work hours miserable; but more importantly because we have to have a consistent user experience.
There can’t be any hiccups in the end user's experience navigating through the product, even though different teams work in on different parts of the application in different repositories.
One way we can achieve this is by creating re-usable user interface components.
About UI Components
What does that mean, exactly? Well, let's take a step back for a moment.
Graphical web user interfaces are a chimeric combination of script, style, markup, assets, and text. Currently, what we have in most UI libraries are a bunch of separate files that we’re hoping people will combine as we intend and/or to their own satisfaction. Each one of those separate files may use language-specific components, but we currently lack any way to ensure that all this code which is required to work together in concert actually does so.
Benefits of UI Components
Ideally, what we would want is something that can combine all those pieces associated with the user interface. AngularJS directives do this for script and HTML in ways that fit very well within our already-Angular applications, so it's a good place to start to use these in production while learning concepts that will be useful to us in the future.
Because, when we create UI components, we gain a number of benefits....
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Reusable Components in Angular: Architecture, transclusion, and more
1. SF Angular Meetup
OpenTable
January 12, 2015
MTV Angular Meetup
Google
January 20, 2015
Reusable Components
in Angular
Architecture, transclusion, and more
2.
3. Who We Are
Rachael L Moore
UI Engineer
morewry
Kara Erickson
Web Engineer
kara
20. FIREWORKS NIGHT CC BY GPS
Consistency
Faster development
Quality
Better deployment
Accuracy
Better focus
Custom elements
Coherent config
Benefits of UI Components
21. How to Design UI ComponentsHow to Design UI Components
54. ES6 Review - Template Strings
var name = "Kara";
var greeting = "Hi " + name + "!"; // Hi Kara!
var name = "Kara";
var greeting = `Hi ${name}!`; // Hi Kara!
ES5
ES6
55. ES6 Review - Fat Arrows
var that = this;
var toggleMenu = function() {
that.menuShowing = !that.menuShowing;
};
var toggleMenu = () => {
this.menuShowing = !this.menuShowing;
};
ES5
ES6
71. Custom transclusion
For element in clone:
1. Get target ID
2. Find target element with that ID
3. Append clone element to target
72. angular.forEach(clone, (cloneEl) => {
// get desired target ID
// find target element with that ID
// append element to target
});
custom-transclude.js
73. angular.forEach(clone, (cloneEl) => {
// get desired target ID
var tId = cloneEl.attributes["transclude-to"].value;
// find target element with that ID
// append element to target
});
custom-transclude.js
74. angular.forEach(clone, (cloneEl) => {
// get desired target ID
var tId = cloneEl.attributes["transclude-to"].value;
// find target element with that ID
var target = templ.find(`[transclude-id="${tId}"]`);
// append element to target
});
custom-transclude.js
75. angular.forEach(clone, (cloneEl) => {
// get desired target ID
var tId = cloneEl.attributes["transclude-to"].value;
// find target element with that ID
var target = templ.find(`[transclude-id="${tId}"]`);
// append element to target
target.append(cloneEl);
});
custom-transclude.js
108. Transclude function in ...
link / controller....
○ Auto-generates scope
○ No wrapper
○ Link: safest for DOM
manipulation
compile...
○ Scope issues
○ Wrapper code
○ Deprecated
200. Multi-transclude vs sub-directives
○ “HTML-like”
○ Built with separate parts
□ Maintain style of parts separately
□ Split options up into separate tags
218. Directive to directive communication
○ Controller as directive API
○ “Require” controller from other directives
□ link: (scope, elem, attrs, controller) =>
□ Caveat: must be on element or parents
219. ○ Controller as directive API
○ “Require” controller from other directives
□ link: (scope, elem, attrs, controller) =>
□ Caveat: must be on element or parents
Directive to directive communication
225. ○ Controller as directive API
○ “Require” controller from other directives
□ link: (scope, elem, attrs, controller) =>
□ Caveat: must be on element or parents
Directive to directive communication
236. Sub-directive model
Pros Cons
Flexible UI Open system
HTML-ish More boilerplate
Can modularize parts of the component Not extensible for new entry points