import { ActionDescriptor , ActionOption , VuexModule , VuexModuleInternalsPrototype } from "./interfaces" ; import { ActionContext } from 'vuex' ; import { LegacyVuexModule } from './module.legacy' ; export const internalAction = ( state , context ) => undefined ; export function action ( options ? ) ; export function action ( target , key , descriptor ) ; export function action ( ... params ) { const firstParam = params [ 0 ] as VuexModule | ActionOption | undefined ; if ( firstParam === undefined ) return handleMutateActionMode ; if ( firstParam instanceof VuexModule || firstParam instanceof LegacyVuexModule ) { return handleMutateActionMode ( firstParam , params [ 1 ] , params [ 2 ] ) ; } switch ( firstParam . mode ) { case "raw" : return handleRawActionMode ; case "mutate" : return handleMutateActionMode ; default : return handleMutateActionMode ( firstParam , params [ 1 ] , params [ 2 ] ) ; } } export function getRawActionContext < T extends VuexModule , R > ( thisArg ) { return thisArg as ActionContext < T , R > ; } function handleMutateActionMode ( target , key , descriptor ) { initializeActionsCache ( target ) ; ( target as VuexModule & VuexModuleInternalsPrototype ) . __actions__ ! . push ( { __name__ : key , __type__ : "mutate" , } ) ; } function handleRawActionMode ( target , key , descriptor ) { initializeActionsCache ( target ) ; ( target as VuexModule & VuexModuleInternalsPrototype ) . __actions__ ! . push ( { __name__ : key , __type__ : "raw" , } ) ; } function initializeActionsCache ( target ) { if ( ( target as VuexModuleInternalsPrototype ) . __actions__ === undefined ) { ( target as VuexModuleInternalsPrototype ) . __actions__ = [ ] ; } }