// src/module/index.ts
function registerDynamicModule<S>(dynamicModule: Mod<S, any>, modOpt: DynamicModuleOptions) {
if (!modOpt.name) {
throw new Error('Name of module not provided in decorator options')
}
if (!modOpt.store) {
throw new Error('Store not provided in decorator options when using dynamic option')
}
////
if (import.meta.hot) {
// Hot update of vite.
if (modOpt.store.hasModule(modOpt.name)) {
// Hot update if duplicate modules are encountered.
modOpt.store.hotUpdate({
modules: {
[modOpt.name]: dynamicModule
}
})
return
}
}
////
modOpt.store.registerModule(modOpt.name, dynamicModule, {
preserveState: modOpt.preserveState || false
})
}
For example