We’ve all done it — copy from tutorial, stick it in production code and never look back! So this is what we end up:
Okay, let’s apply some good old Unix programming philosophy — Fold intelligence into data structure so your program can be simple and stupid.
Here is how:
We use a data literal called ‘which’, its keys are action type, properties are a lambda function returns a new state.
By doing this, we fold the correlation (knowledge)between action type and its handler into a data structure so our program can be as stupid as which[action.type].
Thanks for reading if you have any suggestions please PR to my Github, and stay tuned for next article about Dictionary Pattern.