You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // @flow
  2. import {
  3. PARTICIPANT_JOINED,
  4. PARTICIPANT_KICKED,
  5. PARTICIPANT_LEFT,
  6. PARTICIPANT_UPDATED
  7. } from '../base/participants/actionTypes';
  8. import { MiddlewareRegistry } from '../base/redux';
  9. import {
  10. INIT_SEARCH,
  11. INIT_UPDATE_STATS
  12. } from './actionTypes';
  13. import { initReorderStats, updateStats } from './actions';
  14. import { filterBySearchCriteria, getSortedSpeakerStats, getPendingReorder } from './functions';
  15. MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
  16. const result = next(action);
  17. switch (action.type) {
  18. case INIT_SEARCH: {
  19. const state = getState();
  20. const stats = filterBySearchCriteria(state);
  21. dispatch(updateStats(stats));
  22. break;
  23. }
  24. case INIT_UPDATE_STATS:
  25. if (action.getSpeakerStats) {
  26. const state = getState();
  27. const speakerStats = { ...action.getSpeakerStats() };
  28. const stats = filterBySearchCriteria(state, speakerStats);
  29. const pendingReorder = getPendingReorder(state);
  30. dispatch(updateStats(pendingReorder ? getSortedSpeakerStats(state, stats) : stats));
  31. }
  32. break;
  33. case PARTICIPANT_JOINED:
  34. case PARTICIPANT_LEFT:
  35. case PARTICIPANT_KICKED:
  36. case PARTICIPANT_UPDATED: {
  37. dispatch(initReorderStats());
  38. break;
  39. }
  40. }
  41. return result;
  42. });