Chapter 6. Intercomponent communication
This chapter covers
- Getting to know the Aurelia component lifecycle
- Exploring intercomponent data flow and binding
- Understanding how and when to use the Event Aggregator
- Determining how and when to use custom events
- Extending my-books with more-advanced intercomponent communication scenarios
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.
Though this chapter focuses mainly on how components communicate, it’s worth getting a brief recap of the various kinds of components available in the Aurelia framework to put this discussion into context: