選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

reducer.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // @flow
  2. import { ReducerRegistry } from '../base/redux';
  3. import {
  4. ADD_FACIAL_EXPRESSION,
  5. ADD_TO_FACIAL_EXPRESSIONS_BUFFER,
  6. CLEAR_FACIAL_EXPRESSIONS_BUFFER,
  7. START_FACIAL_RECOGNITION,
  8. STOP_FACIAL_RECOGNITION,
  9. UPDATE_FACE_COORDINATES
  10. } from './actionTypes';
  11. const defaultState = {
  12. faceBoxes: {},
  13. facialExpressions: {
  14. happy: 0,
  15. neutral: 0,
  16. surprised: 0,
  17. angry: 0,
  18. fearful: 0,
  19. disgusted: 0,
  20. sad: 0
  21. },
  22. facialExpressionsBuffer: [],
  23. recognitionActive: false
  24. };
  25. ReducerRegistry.register('features/facial-recognition', (state = defaultState, action) => {
  26. switch (action.type) {
  27. case ADD_FACIAL_EXPRESSION: {
  28. state.facialExpressions[action.facialExpression] += action.duration;
  29. return state;
  30. }
  31. case ADD_TO_FACIAL_EXPRESSIONS_BUFFER: {
  32. return {
  33. ...state,
  34. facialExpressionsBuffer: [ ...state.facialExpressionsBuffer, action.facialExpression ]
  35. };
  36. }
  37. case CLEAR_FACIAL_EXPRESSIONS_BUFFER: {
  38. return {
  39. ...state,
  40. facialExpressionsBuffer: []
  41. };
  42. }
  43. case START_FACIAL_RECOGNITION: {
  44. return {
  45. ...state,
  46. recognitionActive: true
  47. };
  48. }
  49. case STOP_FACIAL_RECOGNITION: {
  50. return {
  51. ...state,
  52. recognitionActive: false
  53. };
  54. }
  55. case UPDATE_FACE_COORDINATES: {
  56. return {
  57. ...state,
  58. faceBoxes: {
  59. ...state.faceBoxes,
  60. [action.id]: action.faceBox
  61. }
  62. };
  63. }
  64. }
  65. return state;
  66. });