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
selectors.js
64 lines
| 1 | const selectors = { |
| 2 | getFunctions( state ) { |
| 3 | return state.functions; |
| 4 | }, |
| 5 | getOperators( state ) { |
| 6 | return state.operators; |
| 7 | }, |
| 8 | getRenderStates( state ) { |
| 9 | return state.renderStates; |
| 10 | }, |
| 11 | getSwitchableRenderStates( state ) { |
| 12 | return state.renderStates.filter( |
| 13 | ( { is_custom = false, can_be_switched = false } ) => ( |
| 14 | is_custom || can_be_switched |
| 15 | ), |
| 16 | ); |
| 17 | }, |
| 18 | getCustomRenderStates( state ) { |
| 19 | return state.renderStates.filter( |
| 20 | ( { is_custom = false } ) => is_custom, |
| 21 | ); |
| 22 | }, |
| 23 | getOperator( state, operator ) { |
| 24 | const index = state.operators.findIndex( |
| 25 | ( { value } ) => value === operator, |
| 26 | ); |
| 27 | |
| 28 | if ( -1 === index ) { |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | return state.operators[ index ]; |
| 33 | }, |
| 34 | readCondition( state, condition ) { |
| 35 | const { operator = '' } = condition; |
| 36 | |
| 37 | if ( !operator ) { |
| 38 | return ''; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @type {Function} |
| 43 | */ |
| 44 | const callback = state.conditionReaders[ operator ] ?? false; |
| 45 | |
| 46 | if ( 'function' === typeof callback ) { |
| 47 | return callback( condition ); |
| 48 | } |
| 49 | |
| 50 | return state.conditionReaders.default( condition ); |
| 51 | }, |
| 52 | getFunction( state, funcType ) { |
| 53 | return state.functions.find( |
| 54 | ( { value } ) => value === funcType, |
| 55 | ); |
| 56 | }, |
| 57 | getFunctionDisplay( state, funcType ) { |
| 58 | return selectors.getFunction( state, funcType )?.display; |
| 59 | }, |
| 60 | }; |
| 61 | |
| 62 | export default { |
| 63 | ...selectors, |
| 64 | }; |