smartdata/ts/smartdata.classes.collectionfactory.ts

23 lines
698 B
TypeScript
Raw Normal View History

2020-09-10 10:12:17 +00:00
import * as plugins from './smartdata.plugins';
import { SmartdataCollection } from './smartdata.classes.collection';
import { SmartdataDb } from './smartdata.classes.db';
export class CollectionFactory {
2020-10-19 16:44:28 +00:00
public collections: { [key: string]: SmartdataCollection<any> } = {};
2020-09-10 10:12:17 +00:00
2020-10-19 16:44:28 +00:00
public getCollection = (
nameArg: string,
2021-06-09 11:40:23 +00:00
dbArg: SmartdataDb
2020-10-19 16:44:28 +00:00
): SmartdataCollection<any> => {
2020-09-10 10:12:17 +00:00
if (!this.collections[nameArg]) {
this.collections[nameArg] = (() => {
if (dbArg instanceof SmartdataDb) {
// tslint:disable-next-line: no-string-literal
return new SmartdataCollection(nameArg, dbArg);
}
})();
}
return this.collections[nameArg];
2020-10-19 16:44:28 +00:00
};
}