actions.js
2 years ago
constants.js
2 years ago
dispatchers.js
2 years ago
index.js
2 years ago
reducer.js
2 years ago
selectors.js
2 years ago
dispatchers.js
119 lines
| 1 | import constants from './constants'; |
| 2 | import selectors from './selectors'; |
| 3 | |
| 4 | export default { |
| 5 | [ constants.clearGateway ]: ( state, action ) => ( |
| 6 | { |
| 7 | ...state, |
| 8 | currentGateway: {}, |
| 9 | } |
| 10 | ), |
| 11 | [ constants.clearScenario ]: ( state, action ) => ( |
| 12 | { |
| 13 | ...state, |
| 14 | currentScenario: {}, |
| 15 | } |
| 16 | ), |
| 17 | [ constants.setScenario ]: ( state, action ) => ( |
| 18 | { |
| 19 | ...state, |
| 20 | currentScenario: { |
| 21 | ...state.currentScenario, |
| 22 | ...( |
| 23 | action.item || {} |
| 24 | ), |
| 25 | }, |
| 26 | } |
| 27 | ), |
| 28 | [ constants.setGateway ]: ( state, action ) => ( |
| 29 | { |
| 30 | ...state, |
| 31 | currentGateway: { |
| 32 | ...state.currentGateway, |
| 33 | ...action.item, |
| 34 | }, |
| 35 | } |
| 36 | ), |
| 37 | [ constants.setGatewaySpecific ]: ( state, action ) => ( |
| 38 | { |
| 39 | ...state, |
| 40 | currentGateway: { |
| 41 | ...state.currentGateway, |
| 42 | [ state.currentGateway.gateway ]: { |
| 43 | ...selectors.getGatewaySpecific( state ), |
| 44 | ...action.item, |
| 45 | }, |
| 46 | }, |
| 47 | } |
| 48 | ), |
| 49 | [ constants.setGatewayInner ]: ( state, action ) => { |
| 50 | const { key, value } = action.item; |
| 51 | return { |
| 52 | ...state, |
| 53 | currentGateway: { |
| 54 | ...state.currentGateway, |
| 55 | [ key ]: { |
| 56 | ...( |
| 57 | state.currentGateway[ key ] || {} |
| 58 | ), |
| 59 | ...value, |
| 60 | }, |
| 61 | }, |
| 62 | }; |
| 63 | }, |
| 64 | [ constants.setRequest ]: ( state, action ) => { |
| 65 | const items = [ selectors.getGatewayId( state ), action.item?.id ].filter( value => value ); |
| 66 | action.item.id = items.join( '/' ); |
| 67 | |
| 68 | return { |
| 69 | ...state, |
| 70 | currentRequest: action.item, |
| 71 | }; |
| 72 | }, |
| 73 | [ constants.setCurrentScenario ]: ( state, action ) => ( |
| 74 | { |
| 75 | ...state, |
| 76 | currentScenario: { |
| 77 | ...state.currentScenario, |
| 78 | [ state.currentScenario?.id ]: { |
| 79 | ...( |
| 80 | state.currentScenario[ state.currentScenario?.id ] || {} |
| 81 | ), |
| 82 | ...( |
| 83 | action.item || {} |
| 84 | ), |
| 85 | }, |
| 86 | }, |
| 87 | } |
| 88 | ), |
| 89 | [ constants.hardSetGateway ]: ( state, action ) => { |
| 90 | if ( action.item ) { |
| 91 | state.currentGateway[ action.item ] = action.value; |
| 92 | } |
| 93 | |
| 94 | return { |
| 95 | ...state, |
| 96 | }; |
| 97 | }, |
| 98 | [ constants.hardSetGatewaySpecific ]: ( state, action ) => { |
| 99 | if ( action.item && state.currentGateway?.gateway ) { |
| 100 | state.currentGateway[ state.currentGateway?.gateway ] = {}; |
| 101 | state.currentGateway[ state.currentGateway?.gateway ][ action.item ] = action.value; |
| 102 | } |
| 103 | |
| 104 | return { |
| 105 | ...state, |
| 106 | }; |
| 107 | }, |
| 108 | [ constants.registerEventType ]: ( state, action ) => { |
| 109 | const event = { |
| 110 | ...action.item, |
| 111 | gateway: action.item?.gateway ?? state.currentGateway?.gateway, |
| 112 | scenario: action.item?.scenario ?? state.currentScenario?.id, |
| 113 | }; |
| 114 | |
| 115 | state.eventTypes.push( event ); |
| 116 | |
| 117 | return state; |
| 118 | }, |
| 119 | }; |