I am working with an Angular service that looks like this:
export class EventService {
private subject = new Subject<Event>();
send(code: EventCode, data?: any) {
this.subject.next(event);
}
clear() {
this.subject.next();
}
get(): Observable<Event> {
return this.subject.asObservable();
}
}
The classes used in the service are Event and EventCode:
export class Event {
code: EventCode;
data: any;
constructor(code: EventCode, data?: any) {
this.code = code;
this.data = data;
}
}
export enum EventCode {
Created,
Deleted,
Updated
}
When using the service, I subscribe to events like this:
this.eventService.get().subscribe((event: Event) => {
// Do something
});
Now, I want to only subscribe to Events with a specific EventCode
.
Is there a way to achieve this functionality? How can I implement it?