import { Subject , Observer } from '@archimedes/utils' ; import { Notification } from './notification' ; export class NotificationCenter implements Subject { observers : Observer [ ] = [ ] ; notifications : Notification [ ] = [ ] ; new ( notification ) { this . notifications . push ( notification ) ; this . publish ( ) ; window . setTimeout ( ( ) => { this . notifications . pop ( ) ; this . publish ( ) ; } , 5000 ) ; } publish ( ) { this . observers . forEach ( x => x . update ( this ) ) ; } register ( observer ) { this . observers . push ( observer ) ; } unregister ( observer ) { this . observers = this . observers . filter ( x => x !== observer ) ; } }