Last active
July 5, 2016 18:45
-
-
Save cosemansp/135850cbd3ac338f344defe2480f124b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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