Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { createAction, handleActions } from 'redux-actions';
- import { fromJS } from 'immutable';
- // Constants
- export const CHARS_SET = 'barcode/CHARS_SET';
- export const BARCODE_SET = 'bardcode/BARCODE_SET';
- export const BARCODE_UNSET = 'bardcode/BARCODE_UNSET';
- export const PRESSED = 'bardcode/PRESSED';
- // Actions
- export const pressed = createAction('PRESSED');
- export const setPress = createAction('PRESS_SET');
- export const unsetPress = createAction('PRESS_UNSET');
- export const setBarcode = createAction('BARCODE_SET');
- export const unsetBarcode = createAction('BARCODE_UNSET');
- export const actions = {
- setPress,
- unsetPress,
- setBarcode,
- pressed,
- };
- // State
- const initialState = fromJS({
- chars: [],
- barcodeValue: '',
- pressed: false,
- lastScanTime: new Date(),
- });
- // Reducer
- export default handleActions(
- {
- PRESS_SET: (state, action) =>
- state.set(
- 'chars',
- fromJS(action.payload.chars).set(
- 'lastScanTime',
- action.payload.lastScanTime,
- ),
- ),
- PRESS_UNSET: state => state.set('chars', fromJS([])).set('pressed', false),
- BARCODE_SET: (state, action) =>
- state.set('barcodeValue', action.payload.barcodeValue),
- BARCODE_UNSET: state => state.set('barcodeValue', ''),
- PRESSED: state => state.set('pressed', true),
- },
- initialState,
- );
Add Comment
Please, Sign In to add comment