Commit 332c24ec507b257cdde4806f6fdb5dad3a6fb2bc
1 parent
b3953cbd
Exists in
master
and in
7 other branches
added changes to allow pass string[] or EventsHubKnownEventNames to EventsHubService constructor
Showing
4 changed files
with
27 additions
and
18 deletions
Show diff stats
src/app/events-hub-known-events.ts
@@ -1,14 +0,0 @@ | @@ -1,14 +0,0 @@ | ||
1 | -import { EventsHubKnownEventNames } from './shared/services/events-hub.service'; | ||
2 | - | ||
3 | -export class NoosferoEventsHubKnownEventNames implements EventsHubKnownEventNames { | ||
4 | - IMAGE_PROFILE_UPDATED: string = 'IMAGE_PROFILE_UPDATED'; | ||
5 | - PROFILE_INFO_UPDATED: string = 'IMAGE_PROFILE_UPDATED'; | ||
6 | - ARTICLE_UPDATED: string = 'ARTICLE_UPDATED'; | ||
7 | - | ||
8 | - constructor() { | ||
9 | - } | ||
10 | - | ||
11 | - getNames() { | ||
12 | - return Object.getOwnPropertyNames(this); | ||
13 | - } | ||
14 | -} | ||
15 | \ No newline at end of file | 0 | \ No newline at end of file |
src/app/index.ts
@@ -25,10 +25,10 @@ angular.module('noosfero.init', ['noosfero.templates.app', 'noosfero.templates.p | @@ -25,10 +25,10 @@ angular.module('noosfero.init', ['noosfero.templates.app', 'noosfero.templates.p | ||
25 | 25 | ||
26 | 26 | ||
27 | import { EVENTS_HUB_KNOW_EVENT_NAMES } from './shared/services/events-hub.service'; | 27 | import { EVENTS_HUB_KNOW_EVENT_NAMES } from './shared/services/events-hub.service'; |
28 | -import { NoosferoEventsHubKnownEventNames } from './events-hub-known-events'; | 28 | +import { NoosferoKnownEvents } from './known-events'; |
29 | 29 | ||
30 | bootstrap(MainComponent, | 30 | bootstrap(MainComponent, |
31 | [ | 31 | [ |
32 | - provide(EVENTS_HUB_KNOW_EVENT_NAMES, { useClass: NoosferoEventsHubKnownEventNames }) | 32 | + provide(EVENTS_HUB_KNOW_EVENT_NAMES, { useClass: NoosferoKnownEvents }) |
33 | ] | 33 | ] |
34 | ); | 34 | ); |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +import { EventsHubKnownEventNames } from './shared/services/events-hub.service'; | ||
2 | + | ||
3 | +export class NoosferoKnownEvents implements EventsHubKnownEventNames { | ||
4 | + IMAGE_PROFILE_UPDATED: string = 'IMAGE_PROFILE_UPDATED'; | ||
5 | + PROFILE_INFO_UPDATED: string = 'IMAGE_PROFILE_UPDATED'; | ||
6 | + ARTICLE_UPDATED: string = 'ARTICLE_UPDATED'; | ||
7 | + | ||
8 | + constructor() { | ||
9 | + } | ||
10 | + | ||
11 | + getNames() { | ||
12 | + return Object.getOwnPropertyNames(this); | ||
13 | + } | ||
14 | +} | ||
0 | \ No newline at end of file | 15 | \ No newline at end of file |
src/app/shared/services/events-hub.service.ts
@@ -6,6 +6,10 @@ export interface EventsHubKnownEventNames { | @@ -6,6 +6,10 @@ export interface EventsHubKnownEventNames { | ||
6 | getNames(): string[]; | 6 | getNames(): string[]; |
7 | } | 7 | } |
8 | 8 | ||
9 | +function isEventsHubKnownEventNames(object: any): object is EventsHubKnownEventNames { | ||
10 | + return 'getNames' in object; | ||
11 | +} | ||
12 | + | ||
9 | @Injectable() | 13 | @Injectable() |
10 | @Inject(EVENTS_HUB_KNOW_EVENT_NAMES) | 14 | @Inject(EVENTS_HUB_KNOW_EVENT_NAMES) |
11 | export class EventsHubService { | 15 | export class EventsHubService { |
@@ -13,8 +17,13 @@ export class EventsHubService { | @@ -13,8 +17,13 @@ export class EventsHubService { | ||
13 | private emitters: Map<string, EventEmitter<any>>; | 17 | private emitters: Map<string, EventEmitter<any>>; |
14 | private knownEvents: string[] = []; | 18 | private knownEvents: string[] = []; |
15 | 19 | ||
16 | - constructor(private eventsHubKnownEventNames: EventsHubKnownEventNames) { | ||
17 | - this.knownEvents = eventsHubKnownEventNames.getNames(); | 20 | + constructor(private eventsHubKnownEventNames: EventsHubKnownEventNames | string[]) { |
21 | + if (isEventsHubKnownEventNames(eventsHubKnownEventNames)) { | ||
22 | + this.knownEvents = eventsHubKnownEventNames.getNames(); | ||
23 | + } else if (Array.isArray(eventsHubKnownEventNames)) { | ||
24 | + this.knownEvents = eventsHubKnownEventNames; | ||
25 | + } | ||
26 | + | ||
18 | this.emitters = new Map<string, EventEmitter<any>>(); | 27 | this.emitters = new Map<string, EventEmitter<any>>(); |
19 | this.setupEmitters(); | 28 | this.setupEmitters(); |
20 | } | 29 | } |