Skip to content

Instantly share code, notes, and snippets.

@mtermoul
Created April 3, 2019 15:11
Show Gist options
  • Save mtermoul/29a324d260af515ecb7b3abc199c8672 to your computer and use it in GitHub Desktop.
Save mtermoul/29a324d260af515ecb7b3abc199c8672 to your computer and use it in GitHub Desktop.
col-admin/src/store/store.js
import Vue from 'vue'
import Vuex from 'vuex'
import _ from 'underscore'
import cosmicStore from './modules/cosmic'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
isDataReady: false,
students: [],
states: []
},
getters: {
students (state) {
return state.students
},
isDataReady (state) {
return state.isDataReady
},
states (state) {
return state.states
}
},
mutations: {
SET_STUDENTS (state, value) {
state.students = value
},
SET_IS_DATA_READY (state, value) {
state.isDataReady = value
},
ADD_STUDENTS (state, value) {
state.students.push(...value)
},
SET_STATES (state, value) {
state.states = value
}
},
actions: {
fetchStates ({commit, state}) {
let states = []
states = _.chain(state.students).pluck('state').uniq().sortBy((value) => value).value()
commit('SET_STATES', states)
}
},
modules: {
cosmicStore
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment