concept component hierarchy in category aurelia

appears as: component hierarchy
Aurelia in Action

This is an excerpt from Manning's book Aurelia in Action.

Next, you’ll need to remove this behavior from the app view. You can think of it like changing the level of abstraction. You’ve delegated the book-addition behavior to the child component (book-list) so that it no longer belongs in the app view. This lifts the level of abstraction in the app component by delegating the details of how books should be added down the component hierarchy.

Aurelia applications are built by combining many fine-grained components. This allows you to focus on creating or maintaining one component in isolation without needing to consider the context of the entire application. This development style leads to an application that’s easy to create, reason about, test, and maintain. In chapter 2, we looked at a basic method of sharing data between components via data binding. This approach is perfect when you want to pass data down the component hierarchy from parent to child but can cause problems when you attempt to expand its use to send data up or across the hierarchy. Attempting to use data binding in these scenarios causes intercomponent coupling. This coupling—created by the introduction of a shared state between components—can undo the reasonability, testability, and maintainability you sought to introduce by componentizing the application in the first place.

Figure 6.11. Intercomponent communication flow between the two new components, book and edit-book, and the existing components, book and book-list. One-way data binding is used to pass data down the component hierarchy. A number of events (such as edit-mode-changed and save-book) are pushed through to the EventAggregator, which routes them up the books component hierarchy to the destination components.
  • Binding is useful in scenarios when you need to pass data from a parent component down the component hierarchy.
  • Binding breaks down when you attempt to use it to communicate back up or across a component hierarchy due to the intercomponent coupling created by shared state.
  • A good convention to follow with intercomponent communication is data down, actions up. This can be achieved by using binding to pass data down the component hierarchy, and then using either the Event Aggregator or custom events to pass actions up.
  • The Event Aggregator is your go-to tool for communicating between various levels of the component hierarchy, including child-to-parent and child-to-sibling relationships.