feat: implement lazy singleton pattern for repository instances and update related imports
This commit is contained in:
@@ -18,6 +18,7 @@ import { PaymentApi, paymentApi } from "@/data/services/api";
|
||||
import { PaymentPlansStorage } from "@/data/storage/payment";
|
||||
import type { IPaymentRepository } from "@/data/repositories/interfaces";
|
||||
import { Result } from "@/utils/result";
|
||||
import { createLazySingleton } from "./lazy_singleton";
|
||||
|
||||
export class PaymentRepository implements IPaymentRepository {
|
||||
constructor(private readonly api: PaymentApi) {}
|
||||
@@ -83,8 +84,10 @@ export class PaymentRepository implements IPaymentRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/** 全局单例。 */
|
||||
export const paymentRepository = new PaymentRepository(paymentApi);
|
||||
/** 全局懒单例。 */
|
||||
export const getPaymentRepository = createLazySingleton<IPaymentRepository>(
|
||||
() => new PaymentRepository(paymentApi),
|
||||
);
|
||||
|
||||
export function isVipPaymentPlan(plan: PaymentPlan): boolean {
|
||||
return plan.vipDays !== null;
|
||||
|
||||
Reference in New Issue
Block a user