Guest User

Untitled

a guest
Nov 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import { createAction, handleActions } from 'redux-actions';
  2. import { fromJS } from 'immutable';
  3.  
  4. // Constants
  5. export const CHARS_SET = 'barcode/CHARS_SET';
  6. export const BARCODE_SET = 'bardcode/BARCODE_SET';
  7. export const BARCODE_UNSET = 'bardcode/BARCODE_UNSET';
  8. export const PRESSED = 'bardcode/PRESSED';
  9.  
  10. // Actions
  11. export const pressed = createAction('PRESSED');
  12. export const setPress = createAction('PRESS_SET');
  13. export const unsetPress = createAction('PRESS_UNSET');
  14. export const setBarcode = createAction('BARCODE_SET');
  15. export const unsetBarcode = createAction('BARCODE_UNSET');
  16.  
  17. export const actions = {
  18. setPress,
  19. unsetPress,
  20. setBarcode,
  21. pressed,
  22. };
  23.  
  24. // State
  25. const initialState = fromJS({
  26. chars: [],
  27. barcodeValue: '',
  28. pressed: false,
  29. lastScanTime: new Date(),
  30. });
  31.  
  32. // Reducer
  33. export default handleActions(
  34. {
  35. PRESS_SET: (state, action) =>
  36. state.set(
  37. 'chars',
  38. fromJS(action.payload.chars).set(
  39. 'lastScanTime',
  40. action.payload.lastScanTime,
  41. ),
  42. ),
  43. PRESS_UNSET: state => state.set('chars', fromJS([])).set('pressed', false),
  44. BARCODE_SET: (state, action) =>
  45. state.set('barcodeValue', action.payload.barcodeValue),
  46. BARCODE_UNSET: state => state.set('barcodeValue', ''),
  47. PRESSED: state => state.set('pressed', true),
  48. },
  49. initialState,
  50. );
Add Comment
Please, Sign In to add comment