-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathother.component.ts
35 lines (30 loc) · 1.23 KB
/
other.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Component } from '@angular/core';
import { EventBus } from '../event-bus';
import { MessageSentEvent } from '../mfe1-component/message-sent-event';
@Component({
selector: 'app-other',
templateUrl: './other.component.html',
styleUrls: ['./other.component.css'],
})
export class OtherComponent {
public constructor(private readonly _eventBus: EventBus) {
this.subscribeToEvents();
}
public greetEventAsJson?: string;
public messageSentEventAsJson?: string;
private subscribeToEvents(): void {
// The `.bind` call is required to flow the `this` context when the
// `messageSentEventHandler` method is executed. Otherwise when the
// `this.messageSentEventAsJson` line of `messageSentEventHandler`
// method is executed, the `this` variable would be undefined.
//
// For more info see "Understanding This, Bind, Call, and Apply in JavaScript":
// https://www.digitalocean.com/community/conceptual-articles/understanding-this-bind-call-and-apply-in-javascript
this._eventBus
.getEvent$(MessageSentEvent)
.subscribe(this.messageSentEventHandler.bind(this));
}
public messageSentEventHandler(event: MessageSentEvent): void {
this.messageSentEventAsJson = JSON.stringify(event);
}
}