UNPKG

vuex-xhr-state

Version:

Use Vuex to manage the state of you're ajax calls.

48 lines (47 loc) 1.89 kB
import { GetterTree, Module, MutationTree } from 'vuex'; import { IVxsOptions, VxsActionTree, VxsExtendedState, VxsMethod } from './types'; import { VuexXhrCreator } from './VuexXhrCreator'; interface IMapResult<P> { key: string; payload: P; } export default class VuexXhr<S, RS, P, D> implements Module<VxsExtendedState<D, S>, RS> { readonly state: VxsExtendedState<D, S>; readonly namespaced: boolean; namespace: string; mutations: MutationTree<VxsExtendedState<D, S>>; actions: VxsActionTree<S, RS, P, D>; getters: GetterTree<VxsExtendedState<D, S>, RS>; options: IVxsOptions<D, P, S, RS>; private vuexXhrCreator?; constructor(options: IVxsOptions<D, P, S, RS>); setNamespace: (namespace: string) => void; mapPending: (payload: P) => IMapResult<P>; mapHasError: (payload: P) => IMapResult<P>; mapFetched: (payload: P) => IMapResult<P>; mapData: (payload: P) => IMapResult<P>; mapResponse: (payload: P) => IMapResult<P>; pending: (getters: any[], payload: P) => unknown; hasError: (getters: any[], payload?: P | undefined) => unknown; fetched: (getters: any[], payload?: P | undefined) => unknown; data: (getters: any[], payload?: P | undefined) => D; response: (getters: any[], payload?: P | undefined) => unknown; dataNamespace: () => string; fetch: () => string; send: () => string; invalidate: () => string; invalidateAll: () => string; forceFetch: () => string; reset: () => string; setState: (payload: any, mockState: any) => void; setMethod: (stub: VxsMethod<P, D>) => void; setVuexXhrCreator: (vuexXhrCreator: VuexXhrCreator) => void; /** * Invalidate the cache of the group this method belongs to */ inValidateGroup: () => void; mockCall(_: unknown, data: D): void; private mergeStore; private findGetter; } export {};