SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Vue from 'vue';
  2. import { ActionTree, MutationTree, GetterTree } from './type_helper';
  3. import { cloneDeep } from 'lodash';
  4.  
  5. type Entity = {
  6.   value: string
  7. }
  8.  
  9. type EntityState = {
  10.   records: Entity[];
  11.   errors: { [key: string]: boolean; };
  12. };
  13.  
  14. type EntityMutations = {
  15.   set: object[];
  16. };
  17.  
  18. type EntityActions = {
  19.   getList: (payload: null) => Promise<void>;
  20. };
  21.  
  22. type EntityGetters = {
  23.   records: Entity[];
  24. };
  25.  
  26. export const state = (): EntityState => ({
  27.   records: [],
  28.   errors: {},
  29. });
  30.  
  31. export const mutations: MutationTree<EntityState, EntityMutations> = {
  32.   set: (state, payload) => {
  33.     Vue.set(state, 'records', payload);
  34.     Vue.set(state, 'errors', {});
  35.   },
  36. };
  37.  
  38. export const actions: ActionTree<EntityState, EntityMutations, EntityGetters, EntityActions> = {
  39.   getList: async ({ commit }) => {
  40.     commit('set', []);
  41.   }
  42. };
  43.  
  44. export const getters: GetterTree<EntityState, EntityGetters> = {
  45.   records: (state) => cloneDeep(state.records),
  46. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top