import type * as Vuex from 'vuex'; /** * @ignore */ export type Mutation = (state: State, P: P) => void; /** * @ignore */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export type GetterHandler = (getter: any) => R; /** * @ignore */ export type ActionHandler = ( store: Vuex.ActionContext, payload: Payload, ) => void; /** * @ignore */ export type ActionType

= (payload: P) => { type: string; payload: P }; /** * @ignore */ export interface Module extends Vuex.Module { name: string; } /** * Return of {@see createModule}. * Interface that helps to create Vuex Module's actions, mutations and getters. * * ```ts * interface RootState { * module_one: { * list: string[] * } * } * const module = createModule({ list: [] }); * ``` * * @typeParam State - Type of module state, usually an key in RootState. * @typeParam RootState - Type of root store state */ export interface ModuleBuilder { /** * Auto Define a mutation for a property and return the action create function. * Internally `Vue#set` is called to set the value into store. * * ```ts * const setItems = module.mutation('setItems'); * store.commit(setItems([1, 2])) * ``` * * @param name - mutation type * @typeParam Payload - Mutation argument type */ mutation( name: Prop, ): ActionType; /** * Define Mutation with an custom implementation, and return a typed create commit function; * * ```ts * const setItems = module.mutation('setItems', (store, items) => store.items = items); * store.commit(setItems([1, 2])) * ``` * * @param name - mutation type * @param mutationFn - mutation handler function * @typeParam Payload - Mutation argument type */ mutation( name: string, mutationFn?: Mutation, ): ActionType; /** * define an Action and return a typed create dispatch function * * ```ts * const fetchItems = module.action<{ page: number }>('setItems', ({ commit }, { page }) => * API.fetchItems(page) * .then(items => * commit(setItems(items)) * ) * ); * * store.commit(setItems([1, 2])); * ``` * * @param name - action type * @param actionFn - action handler function * @typeParam Payload - Action argument type * */ action( name: string, actionFn: ActionHandler, ): ActionType; /** * Define an getter function and create an accessor function to getter value. * * ```ts * const getSortedItems = module.getter('sortedItems', (state) => * [...state.items].sort(a, b) => a - b * ); * * // vue component * { * computed: { * getSortedItems() { * getSortedItems(this.$store.getters) * } * } * } * * ``` * @param name - getter name * @param getterFn - Vuex getter function * @typeParam Return - Getter return type */ getter( name: string, getterFn: Vuex.Getter, ): GetterHandler; /** * Create the VuexModule object. * * @param name - Module name/prefix */ getModule(name?: string): Module; }