1
1
mirror of https://github.com/leon-ai/leon.git synced 2025-01-04 15:55:58 +03:00

refactor(server): simplify helpers singleton

This commit is contained in:
louistiti 2022-09-25 23:37:30 +08:00
parent 4a59ba1d9c
commit 1a4e09f908
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
7 changed files with 21 additions and 63 deletions

View File

@ -11,16 +11,10 @@ dayjs.extend(timezone)
class DateHelper {
private static instance: DateHelper
private constructor() {
// Singleton
}
public static getInstance() {
constructor() {
if (DateHelper.instance == null) {
DateHelper.instance = new DateHelper()
DateHelper.instance = this
}
return DateHelper.instance
}
/**
@ -54,4 +48,4 @@ class DateHelper {
}
}
export const DATE = DateHelper.getInstance()
export const DATE = new DateHelper()

View File

@ -14,16 +14,10 @@ export type ShortLanguageCode = Language['short']
class LangHelper {
private static instance: LangHelper
private constructor() {
// Singleton
}
public static getInstance() {
constructor() {
if (LangHelper.instance == null) {
LangHelper.instance = new LangHelper()
LangHelper.instance = this
}
return LangHelper.instance
}
/**
@ -64,4 +58,4 @@ class LangHelper {
}
}
export const LANG = LangHelper.getInstance()
export const LANG = new LangHelper()

View File

@ -21,16 +21,10 @@ class LoaderHelper {
private interval: NodeJS.Timer | undefined
private constructor() {
// Singleton
}
public static getInstance() {
constructor() {
if (LoaderHelper.instance == null) {
LoaderHelper.instance = new LoaderHelper()
LoaderHelper.instance = this
}
return LoaderHelper.instance
}
/**
@ -62,4 +56,4 @@ class LoaderHelper {
}
}
export const LOADER = LoaderHelper.getInstance()
export const LOADER = new LoaderHelper()

View File

@ -16,16 +16,10 @@ class LogHelper {
private static instance: LogHelper
private constructor() {
// Singleton
}
public static getInstance() {
constructor() {
if (LogHelper.instance == null) {
LogHelper.instance = new LogHelper()
LogHelper.instance = this
}
return LogHelper.instance
}
/**
@ -88,4 +82,4 @@ class LogHelper {
}
}
export const LOG = LogHelper.getInstance()
export const LOG = new LogHelper()

View File

@ -11,16 +11,10 @@ interface GetInformation {
class OSHelper {
private static instance: OSHelper
private constructor() {
// Singleton
}
public static getInstance() {
constructor() {
if (OSHelper.instance == null) {
OSHelper.instance = new OSHelper()
OSHelper.instance = this
}
return OSHelper.instance
}
/**
@ -54,4 +48,4 @@ class OSHelper {
}
}
export const OS = OSHelper.getInstance()
export const OS = new OSHelper()

View File

@ -26,16 +26,10 @@ const DOMAINS_DIR = path.join(process.cwd(), 'skills')
class SkillDomainHelper {
private static instance: SkillDomainHelper
private constructor() {
// Singleton
}
public static getInstance() {
constructor() {
if (SkillDomainHelper.instance == null) {
SkillDomainHelper.instance = new SkillDomainHelper()
SkillDomainHelper.instance = this
}
return SkillDomainHelper.instance
}
/**
@ -140,4 +134,4 @@ class SkillDomainHelper {
}
}
export const SKILL_DOMAIN = SkillDomainHelper.getInstance()
export const SKILL_DOMAIN = new SkillDomainHelper()

View File

@ -1,16 +1,10 @@
class StringHelper {
private static instance: StringHelper
private constructor() {
// Singleton
}
public static getInstance() {
constructor() {
if (StringHelper.instance == null) {
StringHelper.instance = new StringHelper()
StringHelper.instance = this
}
return StringHelper.instance
}
/**
@ -82,4 +76,4 @@ class StringHelper {
}
}
export const STRING = StringHelper.getInstance()
export const STRING = new StringHelper()