Ver código fonte

Adding vuex store base setup

Herton 7 anos atrás
pai
commit
c8476ec281

+ 7 - 0
src/store/modules/actions.js

@@ -0,0 +1,7 @@
+import * as types from './types';
+
+export default {
+    [types.DO_SOMETHING]: ({commit}, payload) => {
+        commit(types.MUTATE_SOMETHING, payload)
+    }
+};

+ 7 - 0
src/store/modules/getters.js

@@ -0,0 +1,7 @@
+import * as types from './types';
+
+export default {
+    [types.VALUE]: state => {
+        return state.value;
+    }
+};

+ 15 - 0
src/store/modules/index.js

@@ -0,0 +1,15 @@
+import * as types from '../types';
+import actions from './actions';
+import getters from './getters';
+import mutations from './mutations';
+
+const state = {
+    value: 0
+};
+
+export default {
+    state,
+    mutations,
+    actions,
+    getters
+}

+ 7 - 0
src/store/modules/mutations.js

@@ -0,0 +1,7 @@
+import * as types from './types';
+
+export default {
+    [types.MUTATE_SOMETHING]: (state, payload) => {
+        state.value = payload;
+    }
+};

+ 14 - 0
src/store/store.js

@@ -0,0 +1,14 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import distributor from './modules/distributor';
+
+Vue.use(Vuex);
+
+export const store = new Vuex.Store({
+    state: {
+        value: 0
+    },
+    modules: {
+        distributor
+    }
+});

+ 8 - 0
src/store/types.js

@@ -0,0 +1,8 @@
+// Getters
+export const VALUE = 'shared/VALUE';
+
+// Mutations
+export const MUTATE_SOMETHING = 'distributor/MUTATE_SOMETHING';
+
+// Actions
+export const DO_SOMETHING = 'distributor/DO_SOMETHING';