Created
July 14, 2016 10:57
-
-
Save ktsn/be9b4e5166e953cc77e2e65426a2c4c5 to your computer and use it in GitHub Desktop.
[Vuex] Suppress prefix or suffix in the module definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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