vuex-module-decorators icon indicating copy to clipboard operation
vuex-module-decorators copied to clipboard

Can vite hot update be supported?

Open CaoMeiYouRen opened this issue 3 years ago • 0 comments

For example

// 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
  })
}

CaoMeiYouRen avatar Dec 05 '21 16:12 CaoMeiYouRen