currency.js 1.4 KB

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