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
35 lines
| 1 | const selectors = { |
| 2 | getRule( state, type ) { |
| 3 | const index = state.ruleTypes.findIndex( |
| 4 | ( { value } ) => value === type, |
| 5 | ); |
| 6 | |
| 7 | if ( -1 === index ) { |
| 8 | return false; |
| 9 | } |
| 10 | |
| 11 | return state.ruleTypes[ index ]; |
| 12 | }, |
| 13 | readRule( state, rule ) { |
| 14 | const { type = '' } = rule; |
| 15 | |
| 16 | if ( !type ) { |
| 17 | return ''; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * @type {Function} |
| 22 | */ |
| 23 | const callback = state.ruleReaders[ type ] ?? false; |
| 24 | |
| 25 | if ( 'function' === typeof callback ) { |
| 26 | return callback( rule ); |
| 27 | } |
| 28 | |
| 29 | return state.ruleReaders.default( rule ); |
| 30 | }, |
| 31 | }; |
| 32 | |
| 33 | export default { |
| 34 | ...selectors, |
| 35 | }; |