
By Yakov Fain | Article Rating: |
|
March 30, 2016 09:00 AM EDT | Reads: |
3,317 |

In any component-based framework you’ll need to implement component communications. The main principle is that components should be loosely coupled hence reusable hence testable. The mediator design pattern allows you to arrange component communications via “the man in the middle” so a component A never communicates with the component B directly. If a component needs data, someone will provide the data via bindings to the component’s input properties. Who’s this someone?Ain’t no business of the component. If a component needs to provide some data to the external world, it’ll emit events (with the data payload). Emits to whom? Ain’t no business of the component. Let whoever needs the data listen to the events from this component.
The mediator pattern is one of the ways to arrange a loosely coupled communication between components. In the following video I show an example of one of the ways of implementing Mediator in Angular 2. Here the sibling components communication via their parent, but this could be also arranged via injecting a service into both component that need to “talk” to each other.
This video is an extract from the online training session I ran recently. If you’re interested of learning Angular 2 in a live session, here’s my speaking/training schedule. If you can’t attend the training, get consider reading our book: https://manning.com/books/angular-2-development-with-typescript.
Read the original blog entry...
Published March 30, 2016 Reads 3,317
Copyright © 2016 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Yakov Fain
Yakov Fain is a Java Champion and a co-founder of the IT consultancy Farata Systems and the product company SuranceBay. He wrote a thousand blogs (http://yakovfain.com) and several books about software development. Yakov authored and co-authored such books as "Angular 2 Development with TypeScript", "Java 24-Hour Trainer", and "Enterprise Web Development". His Twitter tag is @yfain
![]() Sep. 24, 2016 04:00 AM EDT Reads: 1,325 |
By Elizabeth White ![]() Sep. 24, 2016 03:45 AM EDT Reads: 1,335 |
By Liz McMillan ![]() Sep. 24, 2016 03:45 AM EDT Reads: 852 |
![]() Sep. 24, 2016 02:45 AM EDT Reads: 577 |
By Pat Romanski ![]() Sep. 24, 2016 02:30 AM EDT Reads: 772 |
By Liz McMillan ![]() Sep. 24, 2016 12:30 AM EDT Reads: 1,886 |
By Pat Romanski ![]() Sep. 23, 2016 11:00 PM EDT Reads: 1,403 |
By Liz McMillan ![]() Sep. 23, 2016 08:30 PM EDT Reads: 945 |
By Elizabeth White ![]() Sep. 23, 2016 08:15 PM EDT Reads: 1,329 |
By Elizabeth White ![]() Sep. 23, 2016 06:15 PM EDT Reads: 1,148 |
By Pat Romanski ![]() Sep. 23, 2016 06:00 PM EDT Reads: 1,472 |
By Glenn Rossman ![]() Sep. 23, 2016 05:00 PM EDT Reads: 1,217 |
By Pat Romanski ![]() Sep. 23, 2016 03:30 PM EDT Reads: 3,281 |
By Elizabeth White ![]() Sep. 23, 2016 03:15 PM EDT Reads: 2,711 |
![]() Sep. 23, 2016 03:00 PM EDT Reads: 559 |
By Elizabeth White ![]() Sep. 23, 2016 01:00 PM EDT Reads: 1,635 |
By Pat Romanski ![]() Sep. 23, 2016 12:00 PM EDT Reads: 1,463 |
By Liz McMillan ![]() Sep. 23, 2016 12:00 PM EDT Reads: 1,402 |
By Elizabeth White ![]() Sep. 23, 2016 10:30 AM EDT Reads: 973 |
By Elizabeth White ![]() Sep. 23, 2016 10:00 AM EDT Reads: 809 |