Components
Components play an increasingly central role in modern web app development, as a mean for defining encapsulated pieces of UI and having well-defined contracts with the outside world.
-
ComponentsComponent Basics
We'll examine a simple component and clearly define the types of things that belong in the hbs and js files. By passing data through the component's interface to the outside world, we can control its initial state, and the signals we receive in response to user actions. Finally, we'll study the component lifecycle hooks, and provide examples for common uses of each one.
-
ComponentsExercise: A Simple Component
We'll build a simple component, whose purpose is to encapsulate a piece of UI, including its:
- Style (CSS)
- Behavior (JS)
- Structure (HTML)
Through a combination of passing data through the component's interface to the outside world, properties passed to
Ember.Component.extend
, and values set in the component'sinit()
method, we'll establish a solid understanding for how a component's state is determined.Finally, we'll use a "classic" component action and a closure action to allow the outside world to respond to user interactions that began inside our component, and illustrate the differences between best practices for each approach.
-
ComponentsComplex Components
In the real world, we build components up to form larger components, and often need to weave pieces of complex UI together. We'll look at two concepts in particular:
- The
{{component}}
helper - The
{{yield}}
helper, and the concept of exposing component internals to the outside world
- The
-
ComponentsExercise: Complex Components
We'll use our knowledge of yield to make two new components:
- One that generates a list of items based on an array
- One that exposes important values to its block
-
ComponentsCustomizing the Component Boundary
Like W3C Web Components, Ember components are always defined as a boundary element with some private structure contained therein. We'll study a few ways of customizing the boundary element, including:
- Changing its tag
- Binding CSS classes to properties
- Binding DOM attributes to properties
- Adding classes to components on the fly
We'll also cover component CSS best practices, as they relate to the boundary element.
-
ComponentsExercise: Customizing the Component Boundary
We'll practice our new knowledge of component boundary customization by:
- Adding some classes to a few
{{link-to}}
components in our app - Building a basic textarea component, with CSS for basic validation styling
- Adding a DOM attribute to the textarea component, with any validation error messages
- Displaying and styling the validation error(s) with CSS
- Adding some classes to a few
-
ComponentsLunch
Break for lunch