import { decorate , observable , action } from "mobx" ; import { IObservableArray } from "mobx" ; import { NotificationItem , NotificationType } from "../utils/types" ; class NotificationStore { items : IObservableArray < NotificationItem > ; constructor ( ) { this . items = [ ] ; } showInfo ( text ) { this . show ( "info" , text , 1000 ) ; } showChat ( from , text ) { this . show ( "chat" , `${ from }: ${ text }` , 6000 ) ; } showReaction ( from , reaction ) { this . show ( "insert_emoticon" , `${ from }: ${ reaction }` , 3000 ) ; } showJoin ( name ) { this . show ( "person" , `${ name } joined` , 2000 ) ; } showLeave ( name ) { this . show ( "person" , `${ name } left` , 2000 ) ; } private show ( type , text , duration ) { const item = { id : Math . random ( ) , type , text } ; this . items . push ( item ) ; setTimeout ( ( ) => this . items . remove ( item ) , duration ) ; } } decorate ( NotificationStore , { items : observable . shallow , showInfo : action , showChat : action , showReaction : action , showJoin : action , showLeave : action , show : action , } ) ; export default NotificationStore ;