Skip to content

Instantly share code, notes, and snippets.

@cosemansp
Last active July 5, 2016 18:45
Show Gist options
  • Save cosemansp/135850cbd3ac338f344defe2480f124b to your computer and use it in GitHub Desktop.
Save cosemansp/135850cbd3ac338f344defe2480f124b to your computer and use it in GitHub Desktop.
import { Subject, Observable } from 'rxjs';
class EventAggregator {
constructor() {
this.subject = new Subject(); // Can be ReplaySubject too
}
publish(type, data) {
this.subject.onNext({ type, data });
}
listen(type) {
return this.subject.filter(x => x.type === type).pluck('data').share();
}
dispose() {
this.subject.dispose();
}
}
export default new EventAggregator();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment