@eolme/vma-engine
Version:
Engine for VK Mini Apps
18 lines (17 loc) • 522 B
JavaScript
const instances = new Map();
const SingletonProvider = {
getInstance(clazz, ...params) {
if (instances.has(clazz.name)) {
return instances.get(clazz.name);
}
const instance = new clazz(...params);
instances.set(clazz.name, instance);
return instance;
},
destroyInstance(clazz) {
if (instances.has(clazz.name)) {
instances.delete(clazz.name);
}
}
};
export { SingletonProvider, SingletonProvider as default };