In imperative code, you have things, such as if
statements, that determine what happens next. Taken in moderation, there's nothing wrong with this type of construct. But when your main avenue of logic is imperative statements, things tend to grow unmaintainable quickly.
The alternative to this imperative style is to compose your logic declaratively. Maps are the first tool that will help you get there.
When you use maps as the means to declare your application logic, it's helpful to think of the map keys as the possible paths. For example, an if
statement checks whether a condition is true, and if so, it allows for a block of code to be executed. With maps, keys are the condition. The values with which they're paired represent the functionality to execute when the condition is true.
Let's illustrate this idea at it's most basic level using an Immutable.js map:
const actions = Map.of( 'first', () => console.log('first'), 'second...