import { SnotifyToastConfig } from '../interfaces/snotify-toast-config.interface' ; import { Subject , Subscription } from 'rxjs' ; import { SnotifyEventType } from '../types/snotify-event.type' ; import { SnotifyStyle } from '../enums/snotify-style.enum' ; /**
 * Toast main model
 */ export class SnotifyToast { /**
     * Emits SnotifyEventType
     */ readonly eventEmitter = new Subject < SnotifyEventType > ( ) ; /**
     * Holds all subscribers because we need to unsubscribe from all before toast get destroyed
     */ private eventsHolder : Subscription [ ] = [ ] ; /**
     * Toast prompt value
     */ value : string ; /**
     * Toast validator
     */ valid : boolean ; constructor ( public id , public title , public body , public config ) { if ( this . config . type === SnotifyStyle . prompt ) { this . value = '' ; } this . on ( 'hidden' , ( ) => { this . eventsHolder . forEach ( ( subscription ) => { subscription . unsubscribe ( ) ; } ) ; } ) ; } returns param event param action on ( event , action ) { this . eventsHolder . push ( this . eventEmitter . subscribe ( ( e ) => { if ( e === event ) { action ( this ) ; } } ) ) ; return this ; } returns param toast equals ( toast ) { return this . body === toast . body && this . title === toast . title && this . config . type === toast . config . type ; } }