|
1 | 1 | import switchFunctional from 'switch-functional' |
2 | 2 |
|
3 | | -import { normalizeCondition } from './condition.js' |
| 3 | +import { mapCondition } from './condition.js' |
4 | 4 | import { mapEffects } from './effect.js' |
5 | 5 |
|
6 | 6 | // `ErrorClass.switch(value)` |
7 | 7 | // Wrap `switch-functional` to add Error-specific conditions and effects |
8 | 8 | const switchMethod = ({ ErrorClass }, value) => |
9 | | - customize(normalizeCondition, mapEffects.bind(undefined, ErrorClass))(value) |
10 | | - |
11 | | -const customize = (mapConditions, mapReturnValues) => (value) => |
12 | | - customizeSwitch(switchFunctional(value), mapConditions, mapReturnValues) |
13 | | - |
14 | | -const customizeSwitch = (originalSwitch, mapConditions, mapReturnValues) => ({ |
15 | | - case: (conditions, ...returnValues) => |
16 | | - customizeSwitch( |
17 | | - originalSwitch.case( |
18 | | - Array.isArray(conditions) |
19 | | - ? conditions.map(mapConditions) |
20 | | - : mapConditions(conditions), |
21 | | - mapReturnValues(returnValues), |
22 | | - ), |
23 | | - mapConditions, |
24 | | - mapReturnValues, |
25 | | - ), |
26 | | - default: (...returnValues) => |
27 | | - originalSwitch.default(mapReturnValues(returnValues)), |
28 | | -}) |
| 9 | + switchFunctional(value, { |
| 10 | + mapCondition, |
| 11 | + mapReturnValues: mapEffects.bind(undefined, ErrorClass), |
| 12 | + }) |
29 | 13 |
|
30 | 14 | export default { |
31 | 15 | name: 'switch', |
|
0 commit comments