25 lines
664 B
TypeScript
25 lines
664 B
TypeScript
import { DeepPartial } from '../util/deep-partial.type';
|
|
import { mergeDeep } from '../util/merge-deep';
|
|
import { MsonModel } from './mson.type';
|
|
|
|
export class ModelStore {
|
|
public componentStore = new Map<string, MsonModel>();
|
|
|
|
getModelByName(name: string) {
|
|
return this.componentStore.get(name);
|
|
}
|
|
|
|
updateModel(name: string, upsert: DeepPartial<MsonModel>) {
|
|
const existing = this.getModelByName(name);
|
|
this.componentStore.set(name, mergeDeep(existing || {}, upsert));
|
|
}
|
|
|
|
insertModel(name: string, model: MsonModel) {
|
|
this.componentStore.set(name, model);
|
|
}
|
|
|
|
listModels() {
|
|
return Array.from(this.componentStore.keys());
|
|
}
|
|
}
|