import { VuexModuleConstructor , VuexModuleAddons , Map } from "./interfaces" ; import { createModule , extractVuexModule } from "./module" ; import { createProxy , clearProxyCache } from './proxy' ; import { createSubModule } from './submodule' ; import { getClassPath , toCamelCase } from "./utils" ; const defaultModuleOptions = { namespacedPath : "" , target : "core" , } ; class VuexModule { } export function Module ( { namespacedPath = "" , target = "core" as VuexModuleTarget } = defaultModuleOptions ) { return function ( module ) : void { const VuexClass = module as VuexModuleConstructor ; VuexClass . prototype . __options__ = { namespaced : namespacedPath , target : target === "nuxt" ? target : undefined , } ; const mod = createModule ( { target : VuexClass . prototype . __options__ && VuexClass . prototype . __options__ . target , namespaced : VuexClass . prototype . __options__ && VuexClass . prototype . __options__ . namespaced , strict : true , } ) ; for ( let field in mod . prototype ) { if ( VuexClass . prototype [ field ] ) continue ; VuexClass . prototype [ field ] = mod . prototype [ field ] ; } } ; } export interface LegacyVuexModule extends VuexModuleAddons { } export class LegacyVuexModule { static ExtractVuexModule ( cls ) { const VuexClass = cls as VuexModule & VuexModuleConstructor ; const vxmodule = extractVuexModule ( VuexClass ) ; const path = getClassPath ( VuexClass . prototype . __namespacedPath__ ) || toCamelCase ( VuexClass . name ) ; return vxmodule [ path ] ; } static CreateProxy < T extends typeof VuexModule > ( $store , cls ) { return createProxy ( $store , cls as any ) ; } static CreateSubModule < T extends typeof VuexModule > ( cls ) { return createSubModule ( cls as any ) ; } static ClearProxyCache ( cls ) { return clearProxyCache ( cls as any ) ; } } export type VuexModuleTarget = "core" | "nuxt" ; interface ModuleOptions { namespacedPath ? : string ; target ? : VuexModuleTarget ; }