state.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /** @module setting/state */
  2. /**
  3. * state.js
  4. *
  5. * Collection of everything which has to do with state changes.
  6. **/
  7. /** actionTypes define what actions are handeled by the reducer. */
  8. export const actions = {
  9. changePriceAdult: priceAdult => {
  10. return {
  11. type: 'SETTING_CHANGE_PRICE_ADULT',
  12. priceAdult
  13. }
  14. },
  15. changePriceJunior: priceJunior => {
  16. return {
  17. type: 'SETTING_CHANGE_PRICE_JUNIOR',
  18. priceJunior
  19. }
  20. }
  21. }
  22. console.log('State actions', actions)
  23. /** state definition */
  24. export const state = {
  25. priceAdult: 50,
  26. priceJunior: 30
  27. }
  28. console.log('State state', state)
  29. /** reducer is called by the redux dispatcher and handles all component actions */
  30. export function reducer (state = [], action) {
  31. switch (action.type) {
  32. case 'SETTING_CHANGE_PRICE_ADULT':
  33. return { ...state, priceAdult: action.priceAdult }
  34. case 'SETTING_CHANGE_PRICE_JUNIOR':
  35. return { ...state, priceJunior: action.priceJunior }
  36. default:
  37. return state
  38. }
  39. }
  40. /** sagas are asynchronous workers (JS generators) to handle the state. */
  41. export function * saga () {}