Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

reducer.ts 961B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import { CLOSE_HID_DEVICE, INIT_DEVICE, UPDATE_DEVICE } from './actionTypes';
  3. import { IDeviceInfo } from './types';
  4. /**
  5. * The initial state of the web-hid feature.
  6. */
  7. const DEFAULT_STATE = {
  8. deviceInfo: {} as IDeviceInfo
  9. };
  10. export interface IWebHid {
  11. deviceInfo: IDeviceInfo;
  12. }
  13. ReducerRegistry.register<IWebHid>(
  14. 'features/web-hid',
  15. (state: IWebHid = DEFAULT_STATE, action): IWebHid => {
  16. switch (action.type) {
  17. case INIT_DEVICE:
  18. return {
  19. ...state,
  20. deviceInfo: action.deviceInfo
  21. };
  22. case UPDATE_DEVICE:
  23. return {
  24. ...state,
  25. deviceInfo: {
  26. ...state.deviceInfo,
  27. ...action.updates
  28. }
  29. };
  30. case CLOSE_HID_DEVICE:
  31. return {
  32. ...state,
  33. deviceInfo: DEFAULT_STATE.deviceInfo
  34. };
  35. default:
  36. return state;
  37. }
  38. });