Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class EventObserver {
- constructor() {
- this.observers = []
- }
- subscribe(fn) {
- this.observers.push(fn)
- }
- unsubscribe(fn) {
- this.observers = this.observers.filter(subscriber => subscriber !== fn)
- }
- broadcast(data) {
- this.observers.forEach(subscriber => subscriber(data))
- }
- }
Add Comment
Please, Sign In to add comment