Skip to content

Instantly share code, notes, and snippets.

@ktsn
Created July 14, 2016 10:57
Show Gist options
  • Save ktsn/be9b4e5166e953cc77e2e65426a2c4c5 to your computer and use it in GitHub Desktop.
Save ktsn/be9b4e5166e953cc77e2e65426a2c4c5 to your computer and use it in GitHub Desktop.
[Vuex] Suppress prefix or suffix in the module definition
// use shorter name in local
const ADD = `ADD_TOAST_MESSAGE`
const REMOVE = `REMOVE_TOAST_MESSAGE`
// export as longer name with suffix
export {
ADD as ADD_TOAST_MESSAGE,
REMOVE as REMOVE_TOAST_MESSAGE
}
const actions = {
[ADD] ({ commit }, text) {
const id = ++maxToastId
commit(ADD, createMessage(id, text))
setTimeout(() => {
commit(REMOVE, id)
}, 5000)
},
[REMOVE] ({ commit }, id) {
commit(REMOVE, id)
}
}
const mutations = {
[ADD] (state, data) {
state.messages.push(data)
},
[REMOVE] (state, id) {
state.messages = state.messages.filter(m => m.id !== id)
}
}
export default {
state,
actions,
mutations
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment