This chapter is dedicated to managing dependencies, namely libraries, that your mobile applications rely on. Most current applications abuse the singleton pattern. However, I strongly believe that, one day, JavaScript developers will adopt well-known dependency injection (DI) patterns. Even if they decide to use the singleton pattern, it will be way easier to refactor. In this chapter, we will focus on the React context and how libraries such as Redux leverage the DI mechanism. This is the safest alternative to use if you really want to step up your code and make it easily testable. We will dive into the code in the React Redux library, which uses the React context extensively. You will also understand why the JavaScript world is so slow to abandon the singleton pattern.
In this chapter, you will learn about the following topics:
- The singleton pattern
- The...