github.com/covergates/covergates@v0.2.2-0.20201009050117-42ef8a19fb95/web/src/store/modules/report/index.ts (about)

     1  import { Module } from 'vuex';
     2  import {
     3    fetchCurrentReport,
     4    fetchSource,
     5    fetchHistory
     6  } from './actions';
     7  import {
     8    setCurrent,
     9    startLoading,
    10    stopLoading,
    11    setSource,
    12    setError,
    13    setHistory
    14  } from './mutations';
    15  import { RootState } from '@/store';
    16  
    17  export enum Mutations {
    18    SET_REPORT_CURRENT = 'SET_REPORT_CURRENT',
    19    SET_REPORT_HISTORY = 'SET_REPORT_HISTORY',
    20    START_REPORT_LOADING = 'START_REPORT_LOADING',
    21    STOP_REPORT_LOADING = 'STOP_REPORT_LOADING',
    22    SET_REPORT_SOURCE = 'SET_REPORT_SOURCE',
    23    SET_REPORT_ERROR = 'SET_REPORT_ERROR'
    24  }
    25  
    26  export enum Actions {
    27    FETCH_REPORT_CURRENT = 'FETCH_REPORT_CURRENT',
    28    FETCH_REPORT_HISTORY = 'FETCH_REPORT_HISTORY',
    29    FETCH_REPORT_SOURCE = 'FETCH_REPORT_SOURCE'
    30  }
    31  
    32  export type ReportState = {
    33    current?: Report;
    34    history: Report[];
    35    loading: boolean;
    36    source?: string;
    37    error?: Error;
    38  };
    39  
    40  const module: Module<ReportState, RootState> = {
    41    state: {
    42      loading: false,
    43      current: undefined,
    44      history: [],
    45      source: undefined,
    46      error: undefined
    47    },
    48    actions: {
    49      [Actions.FETCH_REPORT_CURRENT]: fetchCurrentReport,
    50      [Actions.FETCH_REPORT_HISTORY]: fetchHistory,
    51      [Actions.FETCH_REPORT_SOURCE]: fetchSource
    52    },
    53    mutations: {
    54      [Mutations.START_REPORT_LOADING]: startLoading,
    55      [Mutations.STOP_REPORT_LOADING]: stopLoading,
    56      [Mutations.SET_REPORT_CURRENT]: setCurrent,
    57      [Mutations.SET_REPORT_SOURCE]: setSource,
    58      [Mutations.SET_REPORT_ERROR]: setError,
    59      [Mutations.SET_REPORT_HISTORY]: setHistory
    60    }
    61  };
    62  
    63  declare module '@/store' {
    64    interface State {
    65      report: ReportState;
    66    }
    67  }
    68  
    69  export default module;