import { NgModuleRef } from "@angular/core" ; import { StoreModule , Store } from "@ngrx/store" ; let appState ; export function hotModuleReplacement ( bootloader , module ) { let MODULE_REF ; let DATA = ! ! module . hot . data ? module . hot . data . state : undefined ; if ( document . readyState === "complete" ) { bootloader ( ) . then ( ( modRef ) => MODULE_REF = modRef ) . then ( ( ) => console . timeEnd ( "bootstrap" ) ) ; } else { document . addEventListener ( "DOMContentLoaded" , ( ) => { bootloader ( ) . then ( ( modRef ) => MODULE_REF = modRef ) . then ( ( ) => console . timeEnd ( "bootstrap" ) ) ; } ) ; } function getState ( store ) { let state ; store . take ( 1 ) . subscribe ( s => state = s ) ; return state ; } module . hot . accept ( ) ; module . hot . dispose ( ( data ) => { const store = MODULE_REF . injector . get ( Store ) ; appState = getState ( store ) ; ( < any > Object ) . assign ( data , { appState } ) ; } ) ; } export function provideStore ( reducer ) { if ( ( < any > module ) . hot ) { return StoreModule . provideStore ( reducer , appState ) ; } return StoreModule . provideStore ( reducer ) ; }