27 lines
558 B
TypeScript
27 lines
558 B
TypeScript
/**
|
|
* 基类、单例
|
|
*/
|
|
export default class Provider {
|
|
private static instance;
|
|
|
|
private static readonly pool = {};
|
|
|
|
constructor() {
|
|
}
|
|
|
|
public static getInstance<T extends typeof Provider>(this: T): InstanceType<T> {
|
|
// return this.instance ||= new this();
|
|
if (!this.instance) {
|
|
this.instance = new this();
|
|
Provider.pool[this.name] = this.instance;
|
|
}
|
|
return this.instance;
|
|
}
|
|
|
|
public static getPool() {
|
|
return {
|
|
pool: Provider.pool,
|
|
}
|
|
}
|
|
}
|