Skip to content

Commit 60a1038

Browse files
committed
add event-bus
1 parent 297399a commit 60a1038

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { autoinject, transient } from 'aurelia-framework';
2+
import { EventAggregator, Subscription } from 'aurelia-event-aggregator';
3+
4+
export class EventBusEvents {
5+
public static IDS = {
6+
i18n: {
7+
locale: {
8+
changed: 'i18n:locale:changed'
9+
}
10+
}
11+
};
12+
}
13+
14+
@transient()
15+
@autoinject
16+
export class EventBusService {
17+
18+
private disposables: Subscription[] = [];
19+
20+
constructor(
21+
public eventAggregator: EventAggregator
22+
) { }
23+
24+
public addSubscription(eventId: string, callback: Function): EventBusService {
25+
this.disposables.push(this.eventAggregator.subscribe(eventId, callback));
26+
return this;
27+
}
28+
29+
public dispose(): void {
30+
this.disposables.forEach(d => d.dispose());
31+
}
32+
33+
}

0 commit comments

Comments
 (0)