# HmrModuleHandler

`class` in `core/hmr` · v0.2.1-next.0

<https://docs.seedcord.org/packages/core/0.2.1-next.0/classes/hmr-module-handler>

Reloads THandler and optional TMiddleware modules on HMR updates.

Call `handle()` from your `HmrAware.onHmr()` for standard reload behavior, or write a fully custom `onHmr()` and skip this class.

This is only useful during development.

```ts
class HmrModuleHandler<
    THandler,
    TMiddleware = void,
    TArtifacts = unknown
>
```

## Constructors

### constructor

```ts
HmrModuleHandler(
    options: HmrModuleHandlerOptions<THandler, TMiddleware, TArtifacts>
)
```

Constructs a new instance of the `HmrModuleHandler` class

## Methods

### handle

```ts
public async handle(event: HmrUpdateEvent): Promise<void>
```

Unloads or reloads the modules affected by an HmrUpdateEvent, scoped to the handler and middleware directories.

### trackHandler

```ts
public trackHandler(
    file: string,
    handler: THandler
): void
```

Links the handler to its source file so a later update can unload it.

### trackMiddleware

```ts
public trackMiddleware(
    file: string,
    middleware: TMiddleware
): void
```

Links the middleware to its source file so a later update can unload it.
