actions.js
3 years ago
constants.js
3 years ago
default.state.js
3 years ago
dispatchers.js
3 years ago
functions.js
3 years ago
index.js
3 years ago
loading.state.js
3 years ago
reducer.js
3 years ago
selectors.js
3 years ago
dispatchers.js
117 lines
| 1 | import constants from './constants'; |
| 2 | import selectors from './selectors'; |
| 3 | import functions from './functions'; |
| 4 | import withActionLocalizeScript from '../helpers/withActionLocalizeScript'; |
| 5 | |
| 6 | export default { |
| 7 | [ constants.setCurrentAction ]: ( state, action ) => { |
| 8 | const update = {}; |
| 9 | |
| 10 | if ( 'function' === typeof action.item ) { |
| 11 | update.currentAction = action.item( state.currentAction ); |
| 12 | } |
| 13 | else { |
| 14 | update.currentAction = action.item; |
| 15 | } |
| 16 | |
| 17 | return { |
| 18 | ...state, |
| 19 | ...update, |
| 20 | }; |
| 21 | }, |
| 22 | [ constants.setMeta ]: ( state, action ) => ( |
| 23 | { |
| 24 | ...state, |
| 25 | meta: { |
| 26 | ...action.item, |
| 27 | }, |
| 28 | } |
| 29 | ), |
| 30 | [ constants.clearCurrent ]: ( state ) => ( |
| 31 | { |
| 32 | ...state, |
| 33 | currentAction: {}, |
| 34 | meta: {}, |
| 35 | } |
| 36 | ), |
| 37 | [ constants.setLoading ]: ( state, action ) => { |
| 38 | const actionIndex = selectors.getLoadingIndex( state, action.state.id ); |
| 39 | const loading = [ ...state.loadingState ]; |
| 40 | |
| 41 | if ( -1 !== actionIndex ) { |
| 42 | loading[ actionIndex ] = functions.getLoadingItem( action.state ); |
| 43 | } |
| 44 | else { |
| 45 | loading.push( functions.getLoadingItem( action.state ) ); |
| 46 | } |
| 47 | |
| 48 | return { |
| 49 | ...state, |
| 50 | loadingState: loading, |
| 51 | }; |
| 52 | }, |
| 53 | [ constants.updateCurrentSettings ]: ( state, action ) => { |
| 54 | const { settings, type } = state.currentAction; |
| 55 | |
| 56 | const updateSettings = { |
| 57 | ...selectors.getCurrentSettings( state ), |
| 58 | ...action.item, |
| 59 | }; |
| 60 | |
| 61 | return { |
| 62 | ...state, |
| 63 | currentAction: { |
| 64 | ...state.currentAction, |
| 65 | settings: { |
| 66 | ...settings, |
| 67 | [ type ]: updateSettings, |
| 68 | }, |
| 69 | }, |
| 70 | }; |
| 71 | }, |
| 72 | [ constants.updateCurrentConditions ]: ( state, action ) => { |
| 73 | const { conditions = [] } = state.currentAction; |
| 74 | |
| 75 | const update = 'function' === typeof action.item ? action.item( |
| 76 | conditions ) : action.item; |
| 77 | |
| 78 | return { |
| 79 | ...state, |
| 80 | currentAction: { |
| 81 | ...state.currentAction, |
| 82 | conditions: update, |
| 83 | }, |
| 84 | }; |
| 85 | }, |
| 86 | [ constants.addCallback ]: ( state, action ) => ( |
| 87 | { |
| 88 | ...state, |
| 89 | callbacks: { |
| 90 | ...state.callbacks, |
| 91 | [ action.actionType ]: withActionLocalizeScript( |
| 92 | action.actionType, |
| 93 | action.callback, |
| 94 | ), |
| 95 | }, |
| 96 | } |
| 97 | ), |
| 98 | [ constants.addDetail ]: ( state, action ) => ( |
| 99 | { |
| 100 | ...state, |
| 101 | details: { |
| 102 | ...state.details, |
| 103 | [ action.actionType ]: action.item, |
| 104 | }, |
| 105 | } |
| 106 | ), |
| 107 | [ constants.addComputedField ]: ( state, action ) => ( |
| 108 | { |
| 109 | ...state, |
| 110 | computedFields: [ |
| 111 | ...state.computedFields, |
| 112 | action.field |
| 113 | ] |
| 114 | } |
| 115 | ), |
| 116 | |
| 117 | }; |