const map: Map<string, HMRRecord> = new Map()
export function registerHMR(instance: ComponentInternalInstance) {
- map.get(instance.type.__hmrId!)!.instances.add(instance)
+ const id = instance.type.__hmrId!
+ let record = map.get(id)
+ if (!record) {
+ createRecord(id, instance.type as ComponentOptions)
+ record = map.get(id)!
+ }
+ record.instances.add(instance)
}
export function unregisterHMR(instance: ComponentInternalInstance) {
}
function rerender(id: string, newRender?: RenderFunction) {
+ const record = map.get(id)
+ if (!record) return
// Array.from creates a snapshot which avoids the set being mutated during
// updates
- Array.from(map.get(id)!.instances).forEach(instance => {
+ Array.from(record.instances).forEach(instance => {
if (newRender) {
instance.render = newRender
}
}
function reload(id: string, newComp: ComponentOptions) {
- const record = map.get(id)!
+ const record = map.get(id)
+ if (!record) return
// 1. Update existing comp definition to match new one
const comp = record.comp
Object.assign(comp, newComp)