Guest User

Untitled

a guest
Jun 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. export class EventObserver {
  2. constructor() {
  3. this.observers = []
  4. }
  5.  
  6. subscribe(fn) {
  7. this.observers.push(fn)
  8. }
  9.  
  10. unsubscribe(fn) {
  11. this.observers = this.observers.filter(subscriber => subscriber !== fn)
  12. }
  13.  
  14. broadcast(data) {
  15. this.observers.forEach(subscriber => subscriber(data))
  16. }
  17. }
Add Comment
Please, Sign In to add comment