@@ -73,6 +73,8 @@ const SHIMMED_MODULE: Module = {
7373} ;
7474const debug = _debug ( 'cs:compiler:manager' ) ;
7575
76+ type HMRStatus = 'idle' | 'check' | 'apply' | 'fail' | 'dispose' ;
77+
7678export default class Manager {
7779 id : string ;
7880 transpiledModules : {
@@ -91,7 +93,8 @@ export default class Manager {
9193 dependencies: Object ;
9294 webpackHMR: boolean ;
9395 hardReload: boolean ;
94- hmrStatus: 'idle' | 'check' | 'apply' | 'fail' | 'dispose' = 'idle' ;
96+ hmrStatus: HMRStatus = 'idle' ;
97+ hmrStatusChangeListeners: Set < Function > ;
9598 testRunner: TestRunner ;
9699 isFirstLoad: boolean ;
97100
@@ -114,6 +117,7 @@ export default class Manager {
114117 this . webpackHMR = false ;
115118 this . hardReload = false ;
116119 this . hmrStatus = 'idle' ;
120+ this . hmrStatusChangeListeners = new Set ( ) ;
117121 this . isFirstLoad = true ;
118122 this . transpiledModulesByHash = { } ;
119123 this . configurations = { } ;
@@ -230,7 +234,7 @@ export default class Manager {
230234 try {
231235 const exports = this . evaluateTranspiledModule ( transpiledModule ) ;
232236
233- this . hmrStatus = 'idle' ;
237+ this . setHmrStatus ( 'idle' ) ;
234238
235239 return exports ;
236240 } catch ( e ) {
@@ -357,7 +361,7 @@ export default class Manager {
357361 * @param {* } entry
358362 */
359363 async transpileModules ( entry : Module , isTestFile : boolean = false ) {
360- this . hmrStatus = 'check' ;
364+ this . setHmrStatus ( 'check' ) ;
361365 this . setEnvironmentVariables ( ) ;
362366 const transpiledModule = this . getTranspiledModule ( entry ) ;
363367
@@ -565,6 +569,21 @@ export default class Manager {
565569 }
566570 } ;
567571
572+ setHmrStatus = ( status : HMRStatus ) => {
573+ this . hmrStatusChangeListeners . forEach ( v => {
574+ v ( status ) ;
575+ } ) ;
576+ this . hmrStatus = status ;
577+ } ;
578+
579+ addStatusHandler = ( cb : Function ) => {
580+ this . hmrStatusChangeListeners . add ( cb ) ;
581+ } ;
582+
583+ removeStatusHandler = ( cb : Function ) = > {
584+ this . hmrStatusChangeListeners . delete ( cb ) ;
585+ } ;
586+
568587 /**
569588 * Resolve the transpiled module from the path, note that the path can actually
570589 * include loaders. That's why we're focussing on first extracting this query
@@ -729,7 +748,7 @@ export default class Manager {
729748 * continuing
730749 */
731750 markHardReload ( ) {
732- this . hmrStatus = 'fail' ;
751+ this . setHmrStatus ( 'fail' ) ;
733752 this . hardReload = true ;
734753 }
735754
0 commit comments