class OptimizedResize { private callbacks = [ ] ; private running = false ; public isRunning ( ) { return this . running ; } private resize ( ) { if ( ! this . running ) { this . running = true ; if ( window . requestAnimationFrame ) { window . requestAnimationFrame ( this . runCallbacks . bind ( this ) ) ; } else { setTimeout ( this . runCallbacks . bind ( this ) , 66 ) ; } } } private runCallbacks ( ) { this . callbacks . forEach ( callback => { callback ( ) ; } ) ; this . running = false ; } private addCallback ( callback ) { if ( callback ) { this . callbacks . push ( callback ) ; } } public add ( callback ) { if ( ! this . callbacks . length ) { window . addEventListener ( 'resize' , this . resize . bind ( this ) ) ; } this . addCallback ( callback ) ; } } export const optimizedResize = new OptimizedResize ( ) ;