UNPKG

@eolme/vma-engine

Version:
18 lines (17 loc) 522 B
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 };