This blog post is explaining how I applied Singleton pattern from the Go4 to solve simeple state management problem.
At QUOINE, we use Redux for all the thing with regard to state management. It comes with several costs:
The code snippet is as the screenshot below:
The module export two methods for setting and getting a list of fiat currency. After bootstrapping the application, the dynamic list will be fetched over the wire and set value back to fiat currency list. Anywhere inside the application code that needs access to this list, it can just simply use getFiatList method for that purpose.
With that simple approach, I could replace the static list of data located on the client side by dynamic one returned by the server. The transition is painless thank to the simplicity brought by singleton pattern. This process would have never been easy this way if I had chosen the path to go with Redux. I could be able to avoid create one more reducer, action and countless of connected components just for that piece of dynamic data. One last thing, I would like to point out to the old and valuable from our beloved Dan Abramov - You might not need Redux.
Until next time - cheer 🎉 😊 🎉