Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ramsaylanier/87d81094373e3b31fe5e6094a27def64 to your computer and use it in GitHub Desktop.

Select an option

Save ramsaylanier/87d81094373e3b31fe5e6094a27def64 to your computer and use it in GitHub Desktop.
import * as types from '../mutation-types'
// initial state
// shape: [{ id, quantity }]
const state = {
sidebarOpen: false,
sidebarComponent: null
}
// getters
const getters = {
sidebarOpen: state => state.sidebarOpen,
sidebarComponent: state => state.sidebarComponent
}
// actions
const actions = {
toggleSidebar ({ commit, state }, {component}) {
commit(types.TOGGLE_SIDEBAR)
// This is new! We're using one action to trigger two mutations!
commit(types.SET_SIDEBAR_COMPONENT, component)
}
}
// mutations
const mutations = {
[types.TOGGLE_SIDEBAR] (state) {
state.sidebarOpen = !state.sidebarOpen
},
// When toggleSidebar action is called, this mutation is triggered
// storing the passed in component in our application state
[types.SET_SIDEBAR_COMPONENT] (state, component) {
state.sidebarComponent = component
}
}
export default {
state,
getters,
actions,
mutations
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment