Implement singleton design pattern with strict null check
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 21 Aug 2022 22:05:33 +0000 (00:05 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 21 Aug 2022 22:05:33 +0000 (00:05 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AuthorizedTagsCache.ts
src/charging-station/Bootstrap.ts
src/charging-station/SharedLRUCache.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/charging-station/ocpp/OCPPResponseService.ts

index 4142ee251f354ed31100c530a5732e25e1f3c013..d39fbee61e6fa6e27a13fbddbab25dbdffee2d06 100644 (file)
@@ -16,7 +16,7 @@ export default class AuthorizedTagsCache {
   }
 
   public static getInstance(): AuthorizedTagsCache {
-    if (!AuthorizedTagsCache.instance) {
+    if (AuthorizedTagsCache.instance === null) {
       AuthorizedTagsCache.instance = new AuthorizedTagsCache();
     }
     return AuthorizedTagsCache.instance;
index 23307f4c34a74b509ba352c071fb3383566134f5..0fa2c88d35c868650e76fa059a86f75d96c54b7e 100644 (file)
@@ -60,7 +60,7 @@ export default class Bootstrap {
   }
 
   public static getInstance(): Bootstrap {
-    if (!Bootstrap.instance) {
+    if (Bootstrap.instance === null) {
       Bootstrap.instance = new Bootstrap();
     }
     return Bootstrap.instance;
index 697cf943dadcbaa0b04f6db260f369b949556ada..a40de80293ad9090904be33cd5213e349bfe06fe 100644 (file)
@@ -20,7 +20,7 @@ export default class SharedLRUCache {
   }
 
   public static getInstance(): SharedLRUCache {
-    if (!SharedLRUCache.instance) {
+    if (SharedLRUCache.instance === null) {
       SharedLRUCache.instance = new SharedLRUCache();
     }
     return SharedLRUCache.instance;
index 5be2629abe54db1c83158b0d60af3e2d3ad2e2fd..23d0ffdd6d377737fb771f89f001518e6447fe09 100644 (file)
@@ -22,7 +22,7 @@ export default abstract class OCPPIncomingRequestService {
   }
 
   public static getInstance<T extends OCPPIncomingRequestService>(this: new () => T): T {
-    if (!OCPPIncomingRequestService.instance) {
+    if (OCPPIncomingRequestService.instance === null) {
       OCPPIncomingRequestService.instance = new this();
     }
     return OCPPIncomingRequestService.instance as T;
index 1ae25a65329107bc31b0ade928d3507b54375822..6f4e47be04864463f34b6b89fa65bceae9cf614c 100644 (file)
@@ -45,7 +45,7 @@ export default abstract class OCPPRequestService {
     this: new (ocppResponseService: OCPPResponseService) => T,
     ocppResponseService: OCPPResponseService
   ): T {
-    if (!OCPPRequestService.instance) {
+    if (OCPPRequestService.instance === null) {
       OCPPRequestService.instance = new this(ocppResponseService);
     }
     return OCPPRequestService.instance as T;
index eb49b752def235ce4ddbd8a3be65f2c5fd6822aa..624659aeec5e18cb78a6c5dd31d498ce2648489d 100644 (file)
@@ -21,7 +21,7 @@ export default abstract class OCPPResponseService {
   }
 
   public static getInstance<T extends OCPPResponseService>(this: new () => T): T {
-    if (!OCPPResponseService.instance) {
+    if (OCPPResponseService.instance === null) {
       OCPPResponseService.instance = new this();
     }
     return OCPPResponseService.instance as T;