currency.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { INIT_PAYMENTS_CURRENCIES, RESET_CURRENCY } from '@/constants/actionTypes'
  2. import { SET_CURRENCIES, SET_LOADING_CURRENCIES } from '@/constants/mutationTypes'
  3. const initialState = {
  4. currency: [],
  5. loadingCurrency: false
  6. }
  7. const state = {
  8. currency: initialState.currency,
  9. loadingCurrency: initialState.loadingCurrency
  10. }
  11. const getters = {
  12. /**
  13. * [currency]
  14. * @param {[type]} state [description]
  15. * @return {[type]} [description]
  16. */
  17. currency(state) {
  18. return state.currency
  19. },
  20. /**
  21. * [loadingCurrency]
  22. * @param {[type]} state [description]
  23. * @return {[type]} [description]
  24. */
  25. loadingCurrency(state) {
  26. return state.loadingCurrency
  27. }
  28. }
  29. const mutations = {
  30. /**
  31. * [currency]
  32. * @param {[type]} state [description]
  33. * @param {[type]} payload [description]
  34. */
  35. [SET_CURRENCIES] (state, payload) {
  36. state.currency = payload
  37. },
  38. /**
  39. * [loadingCurrency]
  40. * @param {[type]} state [description]
  41. * @param {[type]} payload [description]
  42. */
  43. [SET_LOADING_CURRENCIES] (state, payload) {
  44. state.loadingCurrency = !!payload
  45. }
  46. }
  47. const actions = {
  48. /**
  49. * [INIT_CURRENCIES]
  50. * @param {*} param0
  51. * @param {*} payload
  52. */
  53. [INIT_PAYMENTS_CURRENCIES] ({commit}, payload) {
  54. commit(SET_CURRENCIES, payload)
  55. commit(SET_LOADING_CURRENCIES, payload)
  56. },
  57. [RESET_CURRENCY] ({ commit }) {
  58. commit(SET_CURRENCIES, [] )
  59. }
  60. }
  61. export default {
  62. state,
  63. getters,
  64. mutations,
  65. actions
  66. }