import { makeAutoObservable } from 'mobx'; import { Col } from './DocCreatorMenu'; import { FieldSettings } from './TemplateFieldTypes/TemplateField'; import { Template } from './Template'; export class TemplateManager { templates: Template[] = []; constructor(templateSettings: FieldSettings[]) { makeAutoObservable(this); this.templates = this.initializeTemplates(templateSettings); } initializeTemplates = (templateSettings: FieldSettings[]): Template[] => { const initializedTemplates: Template[] = []; templateSettings.forEach(settings => initializedTemplates.push(new Template(settings))); return initializedTemplates; }; getValidTemplates = (cols: Col[]): Template[] => { console.log('called in manager with templates: ', this.templates); return this.templates.filter(template => template.isValidTemplate(cols)); }; addTemplate = (newTemplate: Template) => { this.templates.push(newTemplate); }; removeTemplate = (template: Template) => { this.templates.splice(this.templates.indexOf(template), 1); template.cleanup(); }; }