Framework
HMR
Interface: HMR
HMR API interface.
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
enabled | readonly | boolean | Whether HMR is currently enabled. Returns true only when running robo dev --hmr. |
Methods
module()
module(metaUrl): HotModuleGet the HMR instance for a module.
Call this at the top level of your module with import.meta.url.
When a module is reloaded, any previously registered dispose callbacks are executed before the new module instance registers its own.
Parameters
| Parameter | Type | Description |
|---|---|---|
metaUrl | string | The module URL from import.meta.url |
Returns
A HotModule instance for registering cleanup callbacks
subscribe()
subscribe(callback, options?): HmrSubscriptionSubscribe to HMR events. Callbacks are invoked after handlers are reloaded in the portal.
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | HmrCallback | Function to call when HMR events occur |
options? | HmrSubscribeOptions | Optional filters for events |
Returns
Subscription handle with unsubscribe method
Example
import { hmr } from 'robo.js/hmr'
const sub = hmr.subscribe((ctx) => {
console.log('Routes reloaded:', ctx.routes)
}, {
namespaces: ['server'],
routes: ['api']
})
// Later: sub.unsubscribe()