smartdata/ts/smartdata.classes.collectionfactory.ts
2020-09-10 10:12:17 +00:00

22 lines
807 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import * as plugins from './smartdata.plugins';
import { SmartdataCollection } from './smartdata.classes.collection';
import { SmartdataDb } from './smartdata.classes.db';
export class CollectionFactory {
public collections: {[key: string]: SmartdataCollection<any>} = {};
public getCollection = (nameArg: string, dbArg: SmartdataDb | (() => SmartdataDb)): SmartdataCollection<any> => {
if (!this.collections[nameArg]) {
this.collections[nameArg] = (() => {
if (dbArg instanceof SmartdataDb) {
// tslint:disable-next-line: no-string-literal
return new SmartdataCollection(nameArg, dbArg);
} else {
dbArg = dbArg();
return new SmartdataCollection(nameArg, dbArg);
}
})();
}
return this.collections[nameArg];
}
}