From 1ca780f9d385bcf96a016ab5ba57ca0f19c94b74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 22 Aug 2022 00:05:33 +0200 Subject: [PATCH] Implement singleton design pattern with strict null check MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/AuthorizedTagsCache.ts | 2 +- src/charging-station/Bootstrap.ts | 2 +- src/charging-station/SharedLRUCache.ts | 2 +- src/charging-station/ocpp/OCPPIncomingRequestService.ts | 2 +- src/charging-station/ocpp/OCPPRequestService.ts | 2 +- src/charging-station/ocpp/OCPPResponseService.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/charging-station/AuthorizedTagsCache.ts b/src/charging-station/AuthorizedTagsCache.ts index 4142ee25..d39fbee6 100644 --- a/src/charging-station/AuthorizedTagsCache.ts +++ b/src/charging-station/AuthorizedTagsCache.ts @@ -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; diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 23307f4c..0fa2c88d 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -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; diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index 697cf943..a40de802 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -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; diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index 5be2629a..23d0ffdd 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -22,7 +22,7 @@ export default abstract class OCPPIncomingRequestService { } public static getInstance(this: new () => T): T { - if (!OCPPIncomingRequestService.instance) { + if (OCPPIncomingRequestService.instance === null) { OCPPIncomingRequestService.instance = new this(); } return OCPPIncomingRequestService.instance as T; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 1ae25a65..6f4e47be 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -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; diff --git a/src/charging-station/ocpp/OCPPResponseService.ts b/src/charging-station/ocpp/OCPPResponseService.ts index eb49b752..624659ae 100644 --- a/src/charging-station/ocpp/OCPPResponseService.ts +++ b/src/charging-station/ocpp/OCPPResponseService.ts @@ -21,7 +21,7 @@ export default abstract class OCPPResponseService { } public static getInstance(this: new () => T): T { - if (!OCPPResponseService.instance) { + if (OCPPResponseService.instance === null) { OCPPResponseService.instance = new this(); } return OCPPResponseService.instance as T; -- 2.34.1