state.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. changePaginationPage: page => {
  10. return {
  11. type: 'TABLE_CHANGE_PAGINATION_PAGE',
  12. page
  13. }
  14. },
  15. changePaginationItems: items => {
  16. return {
  17. type: 'TABLE_CHANGE_PAGINATION_ITEMS',
  18. items
  19. }
  20. }
  21. }
  22. console.log('State actions', actions)
  23. /** state definition */
  24. export const state = {
  25. filters: {},
  26. sorting: {},
  27. pagination: {
  28. activePage: 0,
  29. items: 50
  30. }
  31. }
  32. console.log('State state', state)
  33. /** reducer is called by the redux dispatcher and handles all component actions */
  34. export function reducer (state = [], action) {
  35. let pagination
  36. switch (action.type) {
  37. case 'TABLE_CHANGE_PAGINATION_PAGE':
  38. pagination = { ...state.pagination }
  39. pagination.activePage = action.page
  40. return { ...state, pagination }
  41. case 'TABLE_CHANGE_PAGINATION_ITEMS':
  42. pagination = { ...state.pagination }
  43. pagination.items = action.items
  44. return { ...state, pagination }
  45. default:
  46. return state
  47. }
  48. }
  49. /** sagas are asynchronous workers (JS generators) to handle the state. */
  50. export function * saga () {}