@ngxs/hmr-plugin 19.0.0-dev.master-ae76ef6 → 19.0.0-dev.master-d3dad28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ import { Store } from '@ngxs/store';
4
4
  import { isStateOperator } from '@ngxs/store/operators';
5
5
 
6
6
  class HmrInitAction {
7
+ payload;
7
8
  static get type() {
8
9
  // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
9
10
  return '@@HMR_INIT';
@@ -14,6 +15,7 @@ class HmrInitAction {
14
15
  }
15
16
 
16
17
  class HmrBeforeDestroyAction {
18
+ payload;
17
19
  static get type() {
18
20
  // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
19
21
  return '@@HMR_BEFORE_DESTROY';
@@ -24,6 +26,7 @@ class HmrBeforeDestroyAction {
24
26
  }
25
27
 
26
28
  class HmrStateContextFactory {
29
+ store;
27
30
  constructor(module) {
28
31
  const store = module.injector.get(Store, undefined);
29
32
  if (!store) {
@@ -58,6 +61,8 @@ class HmrStateContextFactory {
58
61
  }
59
62
 
60
63
  class HmrOptionBuilder {
64
+ deferTime;
65
+ autoClearLogs;
61
66
  constructor({ deferTime, autoClearLogs }) {
62
67
  this.deferTime = deferTime || 100;
63
68
  this.autoClearLogs = autoClearLogs === undefined ? true : autoClearLogs;
@@ -70,6 +75,11 @@ class HmrOptionBuilder {
70
75
  }
71
76
 
72
77
  class HmrLifecycle {
78
+ ngAppModule;
79
+ appBootstrappedState;
80
+ storage;
81
+ context;
82
+ options;
73
83
  constructor(ngAppModule, appBootstrappedState, storage, context, options) {
74
84
  this.ngAppModule = ngAppModule;
75
85
  this.appBootstrappedState = appBootstrappedState;
@@ -137,6 +147,11 @@ class HmrLifecycle {
137
147
  }
138
148
 
139
149
  class HmrManager {
150
+ storage;
151
+ context;
152
+ lifecycle;
153
+ optionsBuilder;
154
+ ngModule;
140
155
  constructor(options, storage) {
141
156
  this.storage = storage;
142
157
  this.optionsBuilder = new HmrOptionBuilder(options);
@@ -204,6 +219,7 @@ class HmrManager {
204
219
  }
205
220
 
206
221
  class HmrStorage {
222
+ _snapshot;
207
223
  constructor(_snapshot = {}) {
208
224
  this._snapshot = _snapshot;
209
225
  }
@@ -215,13 +231,18 @@ class HmrStorage {
215
231
  }
216
232
  }
217
233
 
234
+ var HmrRuntime;
235
+ (function (HmrRuntime) {
236
+ HmrRuntime["Status"] = "NGXS_HMR_LIFECYCLE_STATUS";
237
+ })(HmrRuntime || (HmrRuntime = {}));
238
+
218
239
  function setHmrReloadedTo(value) {
219
- if (window["NGXS_HMR_LIFECYCLE_STATUS" /* HmrRuntime.Status */]) {
220
- window["NGXS_HMR_LIFECYCLE_STATUS" /* HmrRuntime.Status */].hmrReloaded = value;
240
+ if (window[HmrRuntime.Status]) {
241
+ window[HmrRuntime.Status].hmrReloaded = value;
221
242
  }
222
243
  }
223
244
  function markApplicationAsHmrReloaded() {
224
- window["NGXS_HMR_LIFECYCLE_STATUS" /* HmrRuntime.Status */] = window["NGXS_HMR_LIFECYCLE_STATUS" /* HmrRuntime.Status */] || {
245
+ window[HmrRuntime.Status] = window[HmrRuntime.Status] || {
225
246
  hmrReloaded: false
226
247
  };
227
248
  }
@@ -252,7 +273,7 @@ async function hmr(webpackModule, bootstrapFn, options = {}) {
252
273
  }
253
274
 
254
275
  function hmrIsReloaded() {
255
- return !!(window["NGXS_HMR_LIFECYCLE_STATUS" /* HmrRuntime.Status */] && window["NGXS_HMR_LIFECYCLE_STATUS" /* HmrRuntime.Status */].hmrReloaded);
276
+ return !!(window[HmrRuntime.Status] && window[HmrRuntime.Status].hmrReloaded);
256
277
  }
257
278
 
258
279
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ngxs-hmr-plugin.mjs","sources":["../../../packages/hmr-plugin/src/actions/hmr-init.action.ts","../../../packages/hmr-plugin/src/actions/hmr-before-destroy.action.ts","../../../packages/hmr-plugin/src/internal/hmr-state-context-factory.ts","../../../packages/hmr-plugin/src/internal/hmr-options-builder.ts","../../../packages/hmr-plugin/src/internal/hmr-lifecycle.ts","../../../packages/hmr-plugin/src/hmr-manager.ts","../../../packages/hmr-plugin/src/internal/hmr-storage.ts","../../../packages/hmr-plugin/src/utils/internals.ts","../../../packages/hmr-plugin/src/hmr-bootstrap.ts","../../../packages/hmr-plugin/src/utils/externals.ts","../../../packages/hmr-plugin/index.ts","../../../packages/hmr-plugin/ngxs-hmr-plugin.ts"],"sourcesContent":["import { NgxsHmrSnapshot } from '../symbols';\n\nexport class HmrInitAction {\n static get type() {\n // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138\n return '@@HMR_INIT';\n }\n\n constructor(public payload: Partial<NgxsHmrSnapshot>) {}\n}\n","import { NgxsHmrSnapshot } from '../symbols';\n\nexport class HmrBeforeDestroyAction {\n static get type() {\n // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138\n return '@@HMR_BEFORE_DESTROY';\n }\n\n constructor(public payload: Partial<NgxsHmrSnapshot>) {}\n}\n","import { StateContext, Store } from '@ngxs/store';\nimport { isStateOperator } from '@ngxs/store/operators';\nimport { NgModuleRef } from '@angular/core';\n\nexport class HmrStateContextFactory<T, S> {\n public store: Store;\n\n constructor(module: NgModuleRef<T>) {\n const store = module.injector.get<Store>(Store, undefined);\n\n if (!store) {\n throw new Error('Store not found, maybe you forgot to import the NgxsModule');\n }\n\n this.store = store;\n }\n\n /**\n * @description\n * must be taken out into @ngxs/store/internals\n */\n public createStateContext(): StateContext<S> {\n return {\n dispatch: actions => this.store!.dispatch(actions),\n getState: () => <S>this.store!.snapshot(),\n setState: val => {\n if (isStateOperator(val)) {\n const currentState = this.store!.snapshot();\n val = val(currentState);\n }\n\n this.store!.reset(val);\n return <S>val;\n },\n patchState: val => {\n const currentState = this.store!.snapshot();\n const newState = { ...currentState, ...(<object>val) };\n this.store!.reset(newState);\n return newState;\n }\n };\n }\n}\n","import { NgxsHmrOptions } from '../symbols';\n\nexport class HmrOptionBuilder {\n public readonly deferTime: number;\n public readonly autoClearLogs: boolean;\n\n constructor({ deferTime, autoClearLogs }: NgxsHmrOptions) {\n this.deferTime = deferTime || 100;\n this.autoClearLogs = autoClearLogs === undefined ? true : autoClearLogs;\n }\n\n public clearLogs(): void {\n if (this.autoClearLogs) {\n console.clear();\n }\n }\n}\n","import { ɵNgxsAppBootstrappedState } from '@ngxs/store/internals';\nimport { Observable, Subscription } from 'rxjs';\nimport { StateContext } from '@ngxs/store';\n\nimport { HmrOptionBuilder } from './hmr-options-builder';\nimport { HmrCallback, NgxsHmrLifeCycle } from '../symbols';\nimport { HmrStateContextFactory } from './hmr-state-context-factory';\nimport { HmrBeforeDestroyAction } from '../actions/hmr-before-destroy.action';\nimport { HmrStorage } from './hmr-storage';\n\nexport class HmrLifecycle<T extends Partial<NgxsHmrLifeCycle<S>>, S> {\n constructor(\n private ngAppModule: T,\n private appBootstrappedState: ɵNgxsAppBootstrappedState,\n private storage: HmrStorage<S>,\n private context: HmrStateContextFactory<T, S>,\n private options: HmrOptionBuilder\n ) {}\n\n public hmrNgxsStoreOnInit(hmrAfterOnInit: HmrCallback<S>) {\n let moduleHmrInit: HmrCallback<S> = this.getModuleHmrInitCallback();\n moduleHmrInit = moduleHmrInit.bind(this.ngAppModule);\n this.detectIvyWithJIT();\n this.stateEventLoop((ctx, state) => {\n moduleHmrInit(ctx, state);\n hmrAfterOnInit(ctx, state);\n });\n }\n\n private getModuleHmrInitCallback(): HmrCallback<S> {\n if (typeof this.ngAppModule.hmrNgxsStoreOnInit === 'function') {\n return this.ngAppModule.hmrNgxsStoreOnInit;\n }\n return function defaultModuleHmrInit(ctx, state) {\n ctx.patchState(state);\n };\n }\n\n public hmrNgxsStoreBeforeOnDestroy(): Partial<S> {\n let state: Partial<S> = {};\n const ctx: StateContext<S> = this.context.createStateContext();\n if (typeof this.ngAppModule.hmrNgxsStoreBeforeOnDestroy === 'function') {\n state = this.ngAppModule.hmrNgxsStoreBeforeOnDestroy(ctx);\n } else {\n state = ctx.getState();\n }\n\n ctx.dispatch(new HmrBeforeDestroyAction(state));\n return state;\n }\n\n private stateEventLoop(callback: HmrCallback<S>): void {\n if (!this.storage.hasData()) return;\n\n const state$: Observable<any> = this.context.store.select(state => state);\n\n this.appBootstrappedState.subscribe(bootstrapped => {\n if (!bootstrapped) return;\n let eventId: number;\n const storeEventId: Subscription = state$.subscribe(() => {\n // setTimeout used for zone detection after set hmr state\n clearInterval(eventId);\n eventId = window.setTimeout(() => {\n // close check on the message queue\n storeEventId.unsubscribe();\n // if events are no longer running on the call stack,\n // then we can update the state\n callback(this.context.createStateContext(), this.storage.snapshot as Partial<S>);\n }, this.options.deferTime);\n });\n });\n }\n\n private detectIvyWithJIT(): void {\n const jit: boolean = this.ngAppModule.constructor.hasOwnProperty('__annotations__');\n const ivy: boolean = this.ngAppModule.constructor.hasOwnProperty('ɵmod');\n if (jit && ivy) {\n throw new Error(\n `@ngxs/hmr-plugin doesn't work with JIT mode in Angular Ivy. Please use AOT mode.`\n );\n }\n }\n}\n","import { ApplicationRef, ComponentRef, NgModuleRef } from '@angular/core';\nimport { ɵInitialState, ɵNgxsAppBootstrappedState } from '@ngxs/store/internals';\n\nimport { HmrStorage } from './internal/hmr-storage';\nimport {\n BootstrapModuleFn,\n NgxsHmrLifeCycle,\n NgxsHmrOptions,\n NgxsHmrSnapshot\n} from './symbols';\nimport { HmrStateContextFactory } from './internal/hmr-state-context-factory';\nimport { HmrOptionBuilder } from './internal/hmr-options-builder';\nimport { HmrInitAction } from './actions/hmr-init.action';\nimport { HmrLifecycle } from './internal/hmr-lifecycle';\n\ntype OldHostRemoverFn = () => void;\n\nexport class HmrManager<T extends Partial<NgxsHmrLifeCycle<S>>, S = NgxsHmrSnapshot> {\n public storage: HmrStorage<S>;\n public context: HmrStateContextFactory<T, S>;\n public lifecycle: HmrLifecycle<T, S>;\n public optionsBuilder: HmrOptionBuilder;\n private ngModule: NgModuleRef<T>;\n\n constructor(options: NgxsHmrOptions, storage: HmrStorage<S>) {\n this.storage = storage;\n this.optionsBuilder = new HmrOptionBuilder(options);\n }\n\n private get applicationRef(): ApplicationRef {\n return this.ngModule.injector.get(ApplicationRef);\n }\n\n private get appBootstrappedState() {\n return this.ngModule.injector.get(ɵNgxsAppBootstrappedState);\n }\n\n public async hmrModule(\n bootstrapFn: BootstrapModuleFn<T>,\n tick: () => void\n ): Promise<NgModuleRef<T>> {\n ɵInitialState.set(this.storage.snapshot);\n this.ngModule = await bootstrapFn();\n this.context = new HmrStateContextFactory(this.ngModule);\n this.lifecycle = this.createLifecycle();\n\n tick();\n\n ɵInitialState.pop();\n return this.ngModule;\n }\n\n public beforeModuleBootstrap(): void {\n this.lifecycle.hmrNgxsStoreOnInit((ctx, state) => {\n ctx.dispatch(new HmrInitAction(state));\n });\n }\n\n public beforeModuleOnDestroy(): Partial<S> {\n this.optionsBuilder.clearLogs();\n return this.lifecycle.hmrNgxsStoreBeforeOnDestroy();\n }\n\n public createNewModule(): void {\n const removeOldHosts: () => void = this.cloneHostsBeforeDestroy();\n this.removeNgStyles();\n this.ngModule.destroy();\n removeOldHosts();\n }\n\n private createLifecycle(): HmrLifecycle<T, S> {\n return new HmrLifecycle(\n this.ngModule.instance,\n this.appBootstrappedState,\n this.storage,\n this.context,\n this.optionsBuilder\n );\n }\n\n private cloneHostsBeforeDestroy(): () => void {\n const elements: Element[] = this.applicationRef.components.map(\n (component: ComponentRef<Element>) => component.location.nativeElement\n );\n\n const removableList: OldHostRemoverFn[] = elements.map((componentNode: Element) => {\n const newNode = document.createElement(componentNode.tagName);\n const parentNode: Node = componentNode.parentNode as Node;\n const currentDisplay: string | null = newNode.style.display;\n\n newNode.style.display = 'none';\n parentNode.insertBefore(newNode, componentNode);\n\n return (): void => {\n newNode.style.display = currentDisplay;\n try {\n parentNode.removeChild(componentNode);\n } catch {}\n };\n });\n\n return function removeOldHosts(): void {\n removableList.forEach((removeOldHost: OldHostRemoverFn) => removeOldHost());\n };\n }\n\n private removeNgStyles(): void {\n const head: HTMLHeadElement = document.head!;\n const styles: HTMLStyleElement[] = Array.from(head!.querySelectorAll('style'));\n\n styles\n .filter((style: HTMLStyleElement) => style.innerText.includes('_ng'))\n .map((style: HTMLStyleElement) => head!.removeChild(style));\n }\n}\n","export class HmrStorage<S> {\n constructor(private _snapshot: Partial<S> = {}) {}\n\n public hasData(): boolean {\n return Object.keys(this._snapshot).length > 0;\n }\n\n public get snapshot(): Partial<S> {\n return this._snapshot;\n }\n}\n","import { HmrRuntime } from '../symbols';\n\ndeclare const window: any;\n\nexport function setHmrReloadedTo(value: boolean): void {\n if (window[HmrRuntime.Status]) {\n window[HmrRuntime.Status].hmrReloaded = value;\n }\n}\n\nexport function markApplicationAsHmrReloaded(): void {\n window[HmrRuntime.Status] = window[HmrRuntime.Status] || {\n hmrReloaded: false\n };\n}\n","import { NgModuleRef } from '@angular/core';\nimport { HmrManager } from './hmr-manager';\nimport { BootstrapModuleFn, NgxsHmrOptions, WebpackModule } from './symbols';\nimport { HmrStorage } from './internal/hmr-storage';\nimport { markApplicationAsHmrReloaded, setHmrReloadedTo } from './utils/internals';\n\n/**\n * Hot Module Replacement plugin for NGXS\n * @deprecated As of Angular v10, HMR is no longer supported and will be deprecated.\n * More information [here](https://www.ngxs.io/plugins/hmr).\n */\nexport async function hmr<T>(\n webpackModule: WebpackModule,\n bootstrapFn: BootstrapModuleFn<T>,\n options: NgxsHmrOptions = {}\n): Promise<NgModuleRef<T>> {\n if (!webpackModule.hot) {\n console.error('Are you using the --hmr flag for ng serve?');\n throw new Error('HMR is not enabled for webpack-dev-server!');\n }\n\n markApplicationAsHmrReloaded();\n\n webpackModule.hot.accept();\n\n interface HmrDataTransfer {\n snapshot?: any;\n }\n const dataTransfer: HmrDataTransfer = webpackModule.hot.data || {};\n\n const storage = new HmrStorage<any>(dataTransfer.snapshot || {});\n const manager = new HmrManager<any>(options, storage);\n\n return await manager.hmrModule(bootstrapFn, () => {\n manager.beforeModuleBootstrap();\n\n webpackModule.hot!.dispose((data: HmrDataTransfer) => {\n setHmrReloadedTo(true);\n data.snapshot = manager.beforeModuleOnDestroy();\n manager.createNewModule();\n });\n });\n}\n","import { HmrRuntime } from '../symbols';\n\ndeclare const window: any;\n\nexport function hmrIsReloaded(): boolean {\n return !!(window[HmrRuntime.Status] && window[HmrRuntime.Status].hmrReloaded);\n}\n","/**\n * The public api for consumers of @ngxs/hmr-plugin\n */\nexport * from './src/public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["ɵNgxsAppBootstrappedState","ɵInitialState"],"mappings":";;;;;MAEa,aAAa,CAAA;AACxB,IAAA,WAAW,IAAI,GAAA;;AAEb,QAAA,OAAO,YAAY;;AAGrB,IAAA,WAAA,CAAmB,OAAiC,EAAA;QAAjC,IAAO,CAAA,OAAA,GAAP,OAAO;;AAC3B;;MCPY,sBAAsB,CAAA;AACjC,IAAA,WAAW,IAAI,GAAA;;AAEb,QAAA,OAAO,sBAAsB;;AAG/B,IAAA,WAAA,CAAmB,OAAiC,EAAA;QAAjC,IAAO,CAAA,OAAA,GAAP,OAAO;;AAC3B;;MCLY,sBAAsB,CAAA;AAGjC,IAAA,WAAA,CAAY,MAAsB,EAAA;AAChC,QAAA,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAQ,KAAK,EAAE,SAAS,CAAC;QAE1D,IAAI,CAAC,KAAK,EAAE;AACV,YAAA,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC;;AAG/E,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK;;AAGpB;;;AAGG;IACI,kBAAkB,GAAA;QACvB,OAAO;AACL,YAAA,QAAQ,EAAE,OAAO,IAAI,IAAI,CAAC,KAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;YAClD,QAAQ,EAAE,MAAS,IAAI,CAAC,K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CgB,aAAa,GAAA;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAA,2BAAA,yBAAmB,IAAI,MAAM,CAAmB,2BAAA,yBAAA,CAAC,WAAW,CAAC;AAC/E;;ACNA;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"ngxs-hmr-plugin.mjs","sources":["../../../packages/hmr-plugin/src/actions/hmr-init.action.ts","../../../packages/hmr-plugin/src/actions/hmr-before-destroy.action.ts","../../../packages/hmr-plugin/src/internal/hmr-state-context-factory.ts","../../../packages/hmr-plugin/src/internal/hmr-options-builder.ts","../../../packages/hmr-plugin/src/internal/hmr-lifecycle.ts","../../../packages/hmr-plugin/src/hmr-manager.ts","../../../packages/hmr-plugin/src/internal/hmr-storage.ts","../../../packages/hmr-plugin/src/symbols.ts","../../../packages/hmr-plugin/src/utils/internals.ts","../../../packages/hmr-plugin/src/hmr-bootstrap.ts","../../../packages/hmr-plugin/src/utils/externals.ts","../../../packages/hmr-plugin/index.ts","../../../packages/hmr-plugin/ngxs-hmr-plugin.ts"],"sourcesContent":["import { NgxsHmrSnapshot } from '../symbols';\n\nexport class HmrInitAction {\n static get type() {\n // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138\n return '@@HMR_INIT';\n }\n\n constructor(public payload: Partial<NgxsHmrSnapshot>) {}\n}\n","import { NgxsHmrSnapshot } from '../symbols';\n\nexport class HmrBeforeDestroyAction {\n static get type() {\n // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138\n return '@@HMR_BEFORE_DESTROY';\n }\n\n constructor(public payload: Partial<NgxsHmrSnapshot>) {}\n}\n","import { StateContext, Store } from '@ngxs/store';\nimport { isStateOperator } from '@ngxs/store/operators';\nimport { NgModuleRef } from '@angular/core';\n\nexport class HmrStateContextFactory<T, S> {\n public store: Store;\n\n constructor(module: NgModuleRef<T>) {\n const store = module.injector.get<Store>(Store, undefined);\n\n if (!store) {\n throw new Error('Store not found, maybe you forgot to import the NgxsModule');\n }\n\n this.store = store;\n }\n\n /**\n * @description\n * must be taken out into @ngxs/store/internals\n */\n public createStateContext(): StateContext<S> {\n return {\n dispatch: actions => this.store!.dispatch(actions),\n getState: () => <S>this.store!.snapshot(),\n setState: val => {\n if (isStateOperator(val)) {\n const currentState = this.store!.snapshot();\n val = val(currentState);\n }\n\n this.store!.reset(val);\n return <S>val;\n },\n patchState: val => {\n const currentState = this.store!.snapshot();\n const newState = { ...currentState, ...(<object>val) };\n this.store!.reset(newState);\n return newState;\n }\n };\n }\n}\n","import { NgxsHmrOptions } from '../symbols';\n\nexport class HmrOptionBuilder {\n public readonly deferTime: number;\n public readonly autoClearLogs: boolean;\n\n constructor({ deferTime, autoClearLogs }: NgxsHmrOptions) {\n this.deferTime = deferTime || 100;\n this.autoClearLogs = autoClearLogs === undefined ? true : autoClearLogs;\n }\n\n public clearLogs(): void {\n if (this.autoClearLogs) {\n console.clear();\n }\n }\n}\n","import { ɵNgxsAppBootstrappedState } from '@ngxs/store/internals';\nimport { Observable, Subscription } from 'rxjs';\nimport { StateContext } from '@ngxs/store';\n\nimport { HmrOptionBuilder } from './hmr-options-builder';\nimport { HmrCallback, NgxsHmrLifeCycle } from '../symbols';\nimport { HmrStateContextFactory } from './hmr-state-context-factory';\nimport { HmrBeforeDestroyAction } from '../actions/hmr-before-destroy.action';\nimport { HmrStorage } from './hmr-storage';\n\nexport class HmrLifecycle<T extends Partial<NgxsHmrLifeCycle<S>>, S> {\n constructor(\n private ngAppModule: T,\n private appBootstrappedState: ɵNgxsAppBootstrappedState,\n private storage: HmrStorage<S>,\n private context: HmrStateContextFactory<T, S>,\n private options: HmrOptionBuilder\n ) {}\n\n public hmrNgxsStoreOnInit(hmrAfterOnInit: HmrCallback<S>) {\n let moduleHmrInit: HmrCallback<S> = this.getModuleHmrInitCallback();\n moduleHmrInit = moduleHmrInit.bind(this.ngAppModule);\n this.detectIvyWithJIT();\n this.stateEventLoop((ctx, state) => {\n moduleHmrInit(ctx, state);\n hmrAfterOnInit(ctx, state);\n });\n }\n\n private getModuleHmrInitCallback(): HmrCallback<S> {\n if (typeof this.ngAppModule.hmrNgxsStoreOnInit === 'function') {\n return this.ngAppModule.hmrNgxsStoreOnInit;\n }\n return function defaultModuleHmrInit(ctx, state) {\n ctx.patchState(state);\n };\n }\n\n public hmrNgxsStoreBeforeOnDestroy(): Partial<S> {\n let state: Partial<S> = {};\n const ctx: StateContext<S> = this.context.createStateContext();\n if (typeof this.ngAppModule.hmrNgxsStoreBeforeOnDestroy === 'function') {\n state = this.ngAppModule.hmrNgxsStoreBeforeOnDestroy(ctx);\n } else {\n state = ctx.getState();\n }\n\n ctx.dispatch(new HmrBeforeDestroyAction(state));\n return state;\n }\n\n private stateEventLoop(callback: HmrCallback<S>): void {\n if (!this.storage.hasData()) return;\n\n const state$: Observable<any> = this.context.store.select(state => state);\n\n this.appBootstrappedState.subscribe(bootstrapped => {\n if (!bootstrapped) return;\n let eventId: number;\n const storeEventId: Subscription = state$.subscribe(() => {\n // setTimeout used for zone detection after set hmr state\n clearInterval(eventId);\n eventId = window.setTimeout(() => {\n // close check on the message queue\n storeEventId.unsubscribe();\n // if events are no longer running on the call stack,\n // then we can update the state\n callback(this.context.createStateContext(), this.storage.snapshot as Partial<S>);\n }, this.options.deferTime);\n });\n });\n }\n\n private detectIvyWithJIT(): void {\n const jit: boolean = this.ngAppModule.constructor.hasOwnProperty('__annotations__');\n const ivy: boolean = this.ngAppModule.constructor.hasOwnProperty('ɵmod');\n if (jit && ivy) {\n throw new Error(\n `@ngxs/hmr-plugin doesn't work with JIT mode in Angular Ivy. Please use AOT mode.`\n );\n }\n }\n}\n","import { ApplicationRef, ComponentRef, NgModuleRef } from '@angular/core';\nimport { ɵInitialState, ɵNgxsAppBootstrappedState } from '@ngxs/store/internals';\n\nimport { HmrStorage } from './internal/hmr-storage';\nimport {\n BootstrapModuleFn,\n NgxsHmrLifeCycle,\n NgxsHmrOptions,\n NgxsHmrSnapshot\n} from './symbols';\nimport { HmrStateContextFactory } from './internal/hmr-state-context-factory';\nimport { HmrOptionBuilder } from './internal/hmr-options-builder';\nimport { HmrInitAction } from './actions/hmr-init.action';\nimport { HmrLifecycle } from './internal/hmr-lifecycle';\n\ntype OldHostRemoverFn = () => void;\n\nexport class HmrManager<T extends Partial<NgxsHmrLifeCycle<S>>, S = NgxsHmrSnapshot> {\n public storage: HmrStorage<S>;\n public context!: HmrStateContextFactory<T, S>;\n public lifecycle!: HmrLifecycle<T, S>;\n public optionsBuilder: HmrOptionBuilder;\n private ngModule!: NgModuleRef<T>;\n\n constructor(options: NgxsHmrOptions, storage: HmrStorage<S>) {\n this.storage = storage;\n this.optionsBuilder = new HmrOptionBuilder(options);\n }\n\n private get applicationRef(): ApplicationRef {\n return this.ngModule.injector.get(ApplicationRef);\n }\n\n private get appBootstrappedState() {\n return this.ngModule.injector.get(ɵNgxsAppBootstrappedState);\n }\n\n public async hmrModule(\n bootstrapFn: BootstrapModuleFn<T>,\n tick: () => void\n ): Promise<NgModuleRef<T>> {\n ɵInitialState.set(this.storage.snapshot);\n this.ngModule = await bootstrapFn();\n this.context = new HmrStateContextFactory(this.ngModule);\n this.lifecycle = this.createLifecycle();\n\n tick();\n\n ɵInitialState.pop();\n return this.ngModule;\n }\n\n public beforeModuleBootstrap(): void {\n this.lifecycle.hmrNgxsStoreOnInit((ctx, state) => {\n ctx.dispatch(new HmrInitAction(state));\n });\n }\n\n public beforeModuleOnDestroy(): Partial<S> {\n this.optionsBuilder.clearLogs();\n return this.lifecycle.hmrNgxsStoreBeforeOnDestroy();\n }\n\n public createNewModule(): void {\n const removeOldHosts: () => void = this.cloneHostsBeforeDestroy();\n this.removeNgStyles();\n this.ngModule.destroy();\n removeOldHosts();\n }\n\n private createLifecycle(): HmrLifecycle<T, S> {\n return new HmrLifecycle(\n this.ngModule.instance,\n this.appBootstrappedState,\n this.storage,\n this.context,\n this.optionsBuilder\n );\n }\n\n private cloneHostsBeforeDestroy(): () => void {\n const elements: Element[] = this.applicationRef.components.map(\n (component: ComponentRef<Element>) => component.location.nativeElement\n );\n\n const removableList: OldHostRemoverFn[] = elements.map((componentNode: Element) => {\n const newNode = document.createElement(componentNode.tagName);\n const parentNode: Node = componentNode.parentNode as Node;\n const currentDisplay: string | null = newNode.style.display;\n\n newNode.style.display = 'none';\n parentNode.insertBefore(newNode, componentNode);\n\n return (): void => {\n newNode.style.display = currentDisplay;\n try {\n parentNode.removeChild(componentNode);\n } catch {}\n };\n });\n\n return function removeOldHosts(): void {\n removableList.forEach((removeOldHost: OldHostRemoverFn) => removeOldHost());\n };\n }\n\n private removeNgStyles(): void {\n const head: HTMLHeadElement = document.head!;\n const styles: HTMLStyleElement[] = Array.from(head!.querySelectorAll('style'));\n\n styles\n .filter((style: HTMLStyleElement) => style.innerText.includes('_ng'))\n .map((style: HTMLStyleElement) => head!.removeChild(style));\n }\n}\n","export class HmrStorage<S> {\n constructor(private _snapshot: Partial<S> = {}) {}\n\n public hasData(): boolean {\n return Object.keys(this._snapshot).length > 0;\n }\n\n public get snapshot(): Partial<S> {\n return this._snapshot;\n }\n}\n","import { StateContext } from '@ngxs/store';\nimport { NgModuleRef } from '@angular/core';\n\nexport const enum HmrRuntime {\n Status = 'NGXS_HMR_LIFECYCLE_STATUS'\n}\n\nexport interface NgxsHmrSnapshot {\n [key: string]: any;\n}\n\nexport interface NgxsHmrLifeCycle<T = NgxsHmrSnapshot> {\n /**\n * hmrNgxsStoreOnInit is called when the AppModule on init\n * @param ctx - StateContext for the current app state from Store\n * @param snapshot - previous state from Store after last hmr on destroy\n */\n hmrNgxsStoreOnInit(ctx: StateContext<T>, snapshot: Partial<T>): void;\n\n /**\n * hmrNgxsStoreOnInit is called when the AppModule on destroy\n * @param ctx - StateContext for the current app state from Store\n */\n hmrNgxsStoreBeforeOnDestroy(ctx: StateContext<T>): Partial<T>;\n}\n\nexport type HmrCallback<T> = (ctx: StateContext<T>, state: Partial<T>) => void;\nexport type BootstrapModuleFn<T = any> = () => Promise<NgModuleRef<T>>;\n\nexport interface NgxsHmrOptions {\n /**\n * @description\n * Clear logs after each refresh\n * (default: true)\n */\n autoClearLogs?: boolean;\n\n /**\n * @description\n * Deferred time before loading the old state\n * (default: 100ms)\n */\n deferTime?: number;\n}\n\ntype ModuleId = string | number;\ninterface WebpackHotModule {\n hot?: {\n data: any;\n accept(dependencies: string[], callback?: (updatedDependencies: ModuleId[]) => void): void;\n accept(dependency: string, callback?: () => void): void;\n accept(errHandler?: (err: Error) => void): void;\n dispose(callback: (data: any) => void): void;\n };\n}\n\n/**\n * @description\n * any - because need setup\n * npm i @types/webpack-env\n */\nexport type WebpackModule = WebpackHotModule | any;\n","import { HmrRuntime } from '../symbols';\n\ndeclare const window: any;\n\nexport function setHmrReloadedTo(value: boolean): void {\n if (window[HmrRuntime.Status]) {\n window[HmrRuntime.Status].hmrReloaded = value;\n }\n}\n\nexport function markApplicationAsHmrReloaded(): void {\n window[HmrRuntime.Status] = window[HmrRuntime.Status] || {\n hmrReloaded: false\n };\n}\n","import { NgModuleRef } from '@angular/core';\nimport { HmrManager } from './hmr-manager';\nimport { BootstrapModuleFn, NgxsHmrOptions, WebpackModule } from './symbols';\nimport { HmrStorage } from './internal/hmr-storage';\nimport { markApplicationAsHmrReloaded, setHmrReloadedTo } from './utils/internals';\n\n/**\n * Hot Module Replacement plugin for NGXS\n * @deprecated As of Angular v10, HMR is no longer supported and will be deprecated.\n * More information [here](https://www.ngxs.io/plugins/hmr).\n */\nexport async function hmr<T>(\n webpackModule: WebpackModule,\n bootstrapFn: BootstrapModuleFn<T>,\n options: NgxsHmrOptions = {}\n): Promise<NgModuleRef<T>> {\n if (!webpackModule.hot) {\n console.error('Are you using the --hmr flag for ng serve?');\n throw new Error('HMR is not enabled for webpack-dev-server!');\n }\n\n markApplicationAsHmrReloaded();\n\n webpackModule.hot.accept();\n\n interface HmrDataTransfer {\n snapshot?: any;\n }\n const dataTransfer: HmrDataTransfer = webpackModule.hot.data || {};\n\n const storage = new HmrStorage<any>(dataTransfer.snapshot || {});\n const manager = new HmrManager<any>(options, storage);\n\n return await manager.hmrModule(bootstrapFn, () => {\n manager.beforeModuleBootstrap();\n\n webpackModule.hot!.dispose((data: HmrDataTransfer) => {\n setHmrReloadedTo(true);\n data.snapshot = manager.beforeModuleOnDestroy();\n manager.createNewModule();\n });\n });\n}\n","import { HmrRuntime } from '../symbols';\n\ndeclare const window: any;\n\nexport function hmrIsReloaded(): boolean {\n return !!(window[HmrRuntime.Status] && window[HmrRuntime.Status].hmrReloaded);\n}\n","/**\n * The public api for consumers of @ngxs/hmr-plugin\n */\nexport * from './src/public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["ɵNgxsAppBootstrappedState","ɵInitialState"],"mappings":";;;;;MAEa,aAAa,CAAA;AAML,IAAA,OAAA;AALnB,IAAA,WAAW,IAAI,GAAA;;AAEb,QAAA,OAAO,YAAY;;AAGrB,IAAA,WAAA,CAAmB,OAAiC,EAAA;QAAjC,IAAO,CAAA,OAAA,GAAP,OAAO;;AAC3B;;MCPY,sBAAsB,CAAA;AAMd,IAAA,OAAA;AALnB,IAAA,WAAW,IAAI,GAAA;;AAEb,QAAA,OAAO,sBAAsB;;AAG/B,IAAA,WAAA,CAAmB,OAAiC,EAAA;QAAjC,IAAO,CAAA,OAAA,GAAP,OAAO;;AAC3B;;MCLY,sBAAsB,CAAA;AAC1B,IAAA,KAAK;AAEZ,IAAA,WAAA,CAAY,MAAsB,EAAA;AAChC,QAAA,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAQ,KAAK,EAAE,SAAS,CAAC;QAE1D,IAAI,CAAC,KAAK,EAAE;AACV,YAAA,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC;;AAG/E,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK;;AAGpB;;;AAGG;IACI,kBAAkB,GAAA;QACvB,OAAO;AACL,YAAA,QAAQ,EAAE,OAA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AAa,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE;IAElE,MAAM,OAAO,GAAG,IAAI,UAAU,CAAM,YAAY,CAAC,QAAQ,IAAI,EAAE,CAAC;IAChE,MAAM,OAAO,GAAG,IAAI,UAAU,CAAM,OAAO,EAAE,OAAO,CAAC;IAErD,OAAO,MAAM,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,MAAK;QAC/C,OAAO,CAAC,qBAAqB,EAAE;QAE/B,aAAa,CAAC,GAAI,CAAC,OAAO,CAAC,CAAC,IAAqB,KAAI;YACnD,gBAAgB,CAAC,IAAI,CAAC;AACtB,YAAA,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,qBAAqB,EAAE;YAC/C,OAAO,CAAC,eAAe,EAAE;AAC3B,SAAC,CAAC;AACJ,KAAC,CAAC;AACJ;;SCtCgB,aAAa,GAAA;AAC3B,IAAA,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC;AAC/E;;ACNA;;AAEG;;ACFH;;AAEG;;;;"}
package/index.d.ts CHANGED
@@ -1,4 +1,74 @@
1
+ import { StateContext } from '@ngxs/store';
2
+ import { NgModuleRef } from '@angular/core';
3
+
4
+ interface NgxsHmrSnapshot {
5
+ [key: string]: any;
6
+ }
7
+ interface NgxsHmrLifeCycle<T = NgxsHmrSnapshot> {
8
+ /**
9
+ * hmrNgxsStoreOnInit is called when the AppModule on init
10
+ * @param ctx - StateContext for the current app state from Store
11
+ * @param snapshot - previous state from Store after last hmr on destroy
12
+ */
13
+ hmrNgxsStoreOnInit(ctx: StateContext<T>, snapshot: Partial<T>): void;
14
+ /**
15
+ * hmrNgxsStoreOnInit is called when the AppModule on destroy
16
+ * @param ctx - StateContext for the current app state from Store
17
+ */
18
+ hmrNgxsStoreBeforeOnDestroy(ctx: StateContext<T>): Partial<T>;
19
+ }
20
+ type BootstrapModuleFn<T = any> = () => Promise<NgModuleRef<T>>;
21
+ interface NgxsHmrOptions {
22
+ /**
23
+ * @description
24
+ * Clear logs after each refresh
25
+ * (default: true)
26
+ */
27
+ autoClearLogs?: boolean;
28
+ /**
29
+ * @description
30
+ * Deferred time before loading the old state
31
+ * (default: 100ms)
32
+ */
33
+ deferTime?: number;
34
+ }
35
+ type ModuleId = string | number;
36
+ interface WebpackHotModule {
37
+ hot?: {
38
+ data: any;
39
+ accept(dependencies: string[], callback?: (updatedDependencies: ModuleId[]) => void): void;
40
+ accept(dependency: string, callback?: () => void): void;
41
+ accept(errHandler?: (err: Error) => void): void;
42
+ dispose(callback: (data: any) => void): void;
43
+ };
44
+ }
1
45
  /**
2
- * The public api for consumers of @ngxs/hmr-plugin
46
+ * @description
47
+ * any - because need setup
48
+ * npm i @types/webpack-env
3
49
  */
4
- export * from './src/public_api';
50
+ type WebpackModule = WebpackHotModule | any;
51
+
52
+ declare class HmrInitAction {
53
+ payload: Partial<NgxsHmrSnapshot>;
54
+ static get type(): string;
55
+ constructor(payload: Partial<NgxsHmrSnapshot>);
56
+ }
57
+
58
+ declare class HmrBeforeDestroyAction {
59
+ payload: Partial<NgxsHmrSnapshot>;
60
+ static get type(): string;
61
+ constructor(payload: Partial<NgxsHmrSnapshot>);
62
+ }
63
+
64
+ /**
65
+ * Hot Module Replacement plugin for NGXS
66
+ * @deprecated As of Angular v10, HMR is no longer supported and will be deprecated.
67
+ * More information [here](https://www.ngxs.io/plugins/hmr).
68
+ */
69
+ declare function hmr<T>(webpackModule: WebpackModule, bootstrapFn: BootstrapModuleFn<T>, options?: NgxsHmrOptions): Promise<NgModuleRef<T>>;
70
+
71
+ declare function hmrIsReloaded(): boolean;
72
+
73
+ export { HmrBeforeDestroyAction, HmrInitAction, hmr, hmrIsReloaded };
74
+ export type { BootstrapModuleFn, NgxsHmrLifeCycle, NgxsHmrOptions, NgxsHmrSnapshot, WebpackModule };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@ngxs/hmr-plugin",
3
- "version": "19.0.0-dev.master-ae76ef6",
3
+ "version": "19.0.0-dev.master-d3dad28",
4
4
  "license": "MIT",
5
5
  "sideEffects": true,
6
6
  "peerDependencies": {
7
- "@angular/core": ">=19.0.0 <20.0.0"
7
+ "@angular/core": ">=20.0.0 <21.0.0"
8
8
  },
9
9
  "module": "fesm2022/ngxs-hmr-plugin.mjs",
10
10
  "typings": "index.d.ts",
@@ -1,6 +0,0 @@
1
- import { NgxsHmrSnapshot } from '../symbols';
2
- export declare class HmrBeforeDestroyAction {
3
- payload: Partial<NgxsHmrSnapshot>;
4
- static get type(): string;
5
- constructor(payload: Partial<NgxsHmrSnapshot>);
6
- }
@@ -1,6 +0,0 @@
1
- import { NgxsHmrSnapshot } from '../symbols';
2
- export declare class HmrInitAction {
3
- payload: Partial<NgxsHmrSnapshot>;
4
- static get type(): string;
5
- constructor(payload: Partial<NgxsHmrSnapshot>);
6
- }
@@ -1,8 +0,0 @@
1
- import { NgModuleRef } from '@angular/core';
2
- import { BootstrapModuleFn, NgxsHmrOptions, WebpackModule } from './symbols';
3
- /**
4
- * Hot Module Replacement plugin for NGXS
5
- * @deprecated As of Angular v10, HMR is no longer supported and will be deprecated.
6
- * More information [here](https://www.ngxs.io/plugins/hmr).
7
- */
8
- export declare function hmr<T>(webpackModule: WebpackModule, bootstrapFn: BootstrapModuleFn<T>, options?: NgxsHmrOptions): Promise<NgModuleRef<T>>;
@@ -1,23 +0,0 @@
1
- import { NgModuleRef } from '@angular/core';
2
- import { HmrStorage } from './internal/hmr-storage';
3
- import { BootstrapModuleFn, NgxsHmrLifeCycle, NgxsHmrOptions, NgxsHmrSnapshot } from './symbols';
4
- import { HmrStateContextFactory } from './internal/hmr-state-context-factory';
5
- import { HmrOptionBuilder } from './internal/hmr-options-builder';
6
- import { HmrLifecycle } from './internal/hmr-lifecycle';
7
- export declare class HmrManager<T extends Partial<NgxsHmrLifeCycle<S>>, S = NgxsHmrSnapshot> {
8
- storage: HmrStorage<S>;
9
- context: HmrStateContextFactory<T, S>;
10
- lifecycle: HmrLifecycle<T, S>;
11
- optionsBuilder: HmrOptionBuilder;
12
- private ngModule;
13
- constructor(options: NgxsHmrOptions, storage: HmrStorage<S>);
14
- private get applicationRef();
15
- private get appBootstrappedState();
16
- hmrModule(bootstrapFn: BootstrapModuleFn<T>, tick: () => void): Promise<NgModuleRef<T>>;
17
- beforeModuleBootstrap(): void;
18
- beforeModuleOnDestroy(): Partial<S>;
19
- createNewModule(): void;
20
- private createLifecycle;
21
- private cloneHostsBeforeDestroy;
22
- private removeNgStyles;
23
- }
@@ -1,18 +0,0 @@
1
- import { ɵNgxsAppBootstrappedState } from '@ngxs/store/internals';
2
- import { HmrOptionBuilder } from './hmr-options-builder';
3
- import { HmrCallback, NgxsHmrLifeCycle } from '../symbols';
4
- import { HmrStateContextFactory } from './hmr-state-context-factory';
5
- import { HmrStorage } from './hmr-storage';
6
- export declare class HmrLifecycle<T extends Partial<NgxsHmrLifeCycle<S>>, S> {
7
- private ngAppModule;
8
- private appBootstrappedState;
9
- private storage;
10
- private context;
11
- private options;
12
- constructor(ngAppModule: T, appBootstrappedState: ɵNgxsAppBootstrappedState, storage: HmrStorage<S>, context: HmrStateContextFactory<T, S>, options: HmrOptionBuilder);
13
- hmrNgxsStoreOnInit(hmrAfterOnInit: HmrCallback<S>): void;
14
- private getModuleHmrInitCallback;
15
- hmrNgxsStoreBeforeOnDestroy(): Partial<S>;
16
- private stateEventLoop;
17
- private detectIvyWithJIT;
18
- }
@@ -1,7 +0,0 @@
1
- import { NgxsHmrOptions } from '../symbols';
2
- export declare class HmrOptionBuilder {
3
- readonly deferTime: number;
4
- readonly autoClearLogs: boolean;
5
- constructor({ deferTime, autoClearLogs }: NgxsHmrOptions);
6
- clearLogs(): void;
7
- }
@@ -1,11 +0,0 @@
1
- import { StateContext, Store } from '@ngxs/store';
2
- import { NgModuleRef } from '@angular/core';
3
- export declare class HmrStateContextFactory<T, S> {
4
- store: Store;
5
- constructor(module: NgModuleRef<T>);
6
- /**
7
- * @description
8
- * must be taken out into @ngxs/store/internals
9
- */
10
- createStateContext(): StateContext<S>;
11
- }
@@ -1,6 +0,0 @@
1
- export declare class HmrStorage<S> {
2
- private _snapshot;
3
- constructor(_snapshot?: Partial<S>);
4
- hasData(): boolean;
5
- get snapshot(): Partial<S>;
6
- }
@@ -1,5 +0,0 @@
1
- export { HmrInitAction } from './actions/hmr-init.action';
2
- export { NgxsHmrLifeCycle, NgxsHmrOptions, WebpackModule, BootstrapModuleFn, NgxsHmrSnapshot } from './symbols';
3
- export { HmrBeforeDestroyAction } from './actions/hmr-before-destroy.action';
4
- export { hmr } from './hmr-bootstrap';
5
- export { hmrIsReloaded } from './utils/externals';
package/src/symbols.d.ts DELETED
@@ -1,54 +0,0 @@
1
- import { StateContext } from '@ngxs/store';
2
- import { NgModuleRef } from '@angular/core';
3
- export declare const enum HmrRuntime {
4
- Status = "NGXS_HMR_LIFECYCLE_STATUS"
5
- }
6
- export interface NgxsHmrSnapshot {
7
- [key: string]: any;
8
- }
9
- export interface NgxsHmrLifeCycle<T = NgxsHmrSnapshot> {
10
- /**
11
- * hmrNgxsStoreOnInit is called when the AppModule on init
12
- * @param ctx - StateContext for the current app state from Store
13
- * @param snapshot - previous state from Store after last hmr on destroy
14
- */
15
- hmrNgxsStoreOnInit(ctx: StateContext<T>, snapshot: Partial<T>): void;
16
- /**
17
- * hmrNgxsStoreOnInit is called when the AppModule on destroy
18
- * @param ctx - StateContext for the current app state from Store
19
- */
20
- hmrNgxsStoreBeforeOnDestroy(ctx: StateContext<T>): Partial<T>;
21
- }
22
- export type HmrCallback<T> = (ctx: StateContext<T>, state: Partial<T>) => void;
23
- export type BootstrapModuleFn<T = any> = () => Promise<NgModuleRef<T>>;
24
- export interface NgxsHmrOptions {
25
- /**
26
- * @description
27
- * Clear logs after each refresh
28
- * (default: true)
29
- */
30
- autoClearLogs?: boolean;
31
- /**
32
- * @description
33
- * Deferred time before loading the old state
34
- * (default: 100ms)
35
- */
36
- deferTime?: number;
37
- }
38
- type ModuleId = string | number;
39
- interface WebpackHotModule {
40
- hot?: {
41
- data: any;
42
- accept(dependencies: string[], callback?: (updatedDependencies: ModuleId[]) => void): void;
43
- accept(dependency: string, callback?: () => void): void;
44
- accept(errHandler?: (err: Error) => void): void;
45
- dispose(callback: (data: any) => void): void;
46
- };
47
- }
48
- /**
49
- * @description
50
- * any - because need setup
51
- * npm i @types/webpack-env
52
- */
53
- export type WebpackModule = WebpackHotModule | any;
54
- export {};
@@ -1 +0,0 @@
1
- export declare function hmrIsReloaded(): boolean;
@@ -1,2 +0,0 @@
1
- export declare function setHmrReloadedTo(value: boolean): void;
2
- export declare function markApplicationAsHmrReloaded(): void;