@@ -5,10 +5,8 @@ export class ToastManager {
55 private static readonly injectKey = Symbol ( ) ;
66
77 private readonly toast = useToast ( ) ;
8- private readonly timers = new Map < string , number > ( ) ;
9- private readonly duplicateTimeout = 700 ; // If two same errors occurred during that time, second is a duplicate
8+ private readonly displayedErrors = new Set < string > ( ) ;
109 private readonly maxDisplayedErrorCount = 4 ;
11- private displayedErrorCount = 0 ;
1210
1311 //
1412 // Public
@@ -33,15 +31,15 @@ export class ToastManager {
3331 }
3432
3533 public error ( message : string ) {
36- if ( this . isDuplicate ( message ) || this . displayedErrorCount >= this . maxDisplayedErrorCount ) {
34+ if ( this . displayedErrors . has ( message ) || this . displayedErrors . size >= this . maxDisplayedErrorCount ) {
3735 // We display message in console
3836 console . log ( 'Hidden error message: "' + message + '"' ) ;
3937 } else {
40- this . displayedErrorCount ++ ;
38+ this . displayedErrors . add ( message ) ;
4139 this . toast . error ( message , {
4240 duration : 0 ,
4341 onDismiss : ( ) => {
44- this . displayedErrorCount -- ;
42+ this . displayedErrors . delete ( message ) ;
4543 } ,
4644 } ) ;
4745 }
@@ -59,25 +57,4 @@ export class ToastManager {
5957 const defaultFactory = ( ) => new ToastManager ( ) ;
6058 return inject < ToastManager > ( ToastManager . injectKey , defaultFactory , true ) ;
6159 }
62-
63- //
64- // Private
65- //
66-
67- private isDuplicate ( message : string ) : boolean {
68- let result : boolean ;
69- const tid = this . timers . get ( message ) ;
70- if ( tid !== undefined ) {
71- // message is a duplicate
72- result = true ;
73- clearTimeout ( tid ) ;
74- } else {
75- result = false ;
76- }
77- const newTID = window . setTimeout ( ( ) => {
78- this . timers . delete ( message ) ;
79- } , this . duplicateTimeout ) ;
80- this . timers . set ( message , newTID ) ;
81- return result ;
82- }
8360}
0 commit comments