# HmrModuleHandler

`class` in `seedcord` · v0.13.0

<https://docs.seedcord.org/packages/seedcord/0.13.0/classes/hmr-module-handler>

Reloads THandler and optional TMiddleware modules on HMR updates.

You can either implement a custom `onHmr()` method in your class by extending `HmrAware`, or if it's a plugin, override the existing `onHmr()` with fully custom logic. Or, use this class's `handle()` method inside your `onHmr()` to get standard HMR handling for your modules based on the provided options you give to the constructor.

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>
```

Handles an HMR update event by reloading affected modules based on the event details and config. It receives an HmrUpdateEvent, then checks the type of update.

- If it's a deletion, it unloads the module. - If it's an update/creation, it checks if the file is tracked, unloads it if so, then reloads the file if it is in the handlers or middlewares directory and is a valid handler/middleware.

### trackHandler

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

Tracks a handler module as being loaded from a specific file.

### trackMiddleware

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

Tracks a middleware module as being loaded from a specific file.
