state.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /** @module player/state */
  2. // import { call, put, takeEvery, takeLatest } from 'redux-saga/effects'
  3. /**
  4. * state.js
  5. *
  6. * Collection of everything which has to do with state changes.
  7. **/
  8. /** actionTypes define what actions are handeled by the reducer. */
  9. export const actions = {
  10. alertAdd: data => {
  11. console.log('adding alert', data)
  12. return {
  13. type: 'ALERT_ADD',
  14. data
  15. }
  16. },
  17. alertDismiss: alertId => {
  18. console.log('dismissing alert', alertId)
  19. return {
  20. type: 'ALERT_DISMISS',
  21. alertId
  22. }
  23. }
  24. }
  25. console.log('State actions', actions)
  26. /** state definition */
  27. export const state = {
  28. alerts: []
  29. }
  30. console.log('State state', state)
  31. /** reducer is called by the redux dispatcher and handles all component actions */
  32. export function reducer (state = [], action) {
  33. switch (action.type) {
  34. case 'ALERT_ADD':
  35. return { ...state, alerts: [ ...state.alerts, action.data ] }
  36. case 'ALERT_DISMISS':
  37. return { ...state, alerts: [ ...state.alerts.slice(0, action.alertId), ...state.alerts.slice(action.alertId + 1) ] }
  38. default:
  39. return state
  40. }
  41. }
  42. /** sagas are asynchronous workers (JS generators) to handle the state. */
  43. export function * saga () {}