feat: implement lazy singleton pattern for repository instances and update related imports
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
import { Result } from "@/utils";
|
||||
import type { IChatRepository } from "@/data/repositories/interfaces";
|
||||
import { LocalChatStorage, LocalMessage } from "@/data/storage/chat";
|
||||
import { createLazySingleton } from "./lazy_singleton";
|
||||
|
||||
export class ChatRepository implements IChatRepository {
|
||||
constructor(
|
||||
@@ -186,8 +187,11 @@ export class ChatRepository implements IChatRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/** 全局单例。 */
|
||||
export const chatRepository = new ChatRepository(
|
||||
chatApi,
|
||||
LocalChatStorage.getInstance(),
|
||||
/** 全局懒单例。 */
|
||||
export const getChatRepository = createLazySingleton<IChatRepository>(
|
||||
() =>
|
||||
new ChatRepository(
|
||||
chatApi,
|
||||
LocalChatStorage.getInstance(),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user