Browse Source

Very minor performance improvement to improve debugging. Only fetch the model once.

pull/978/head
Sebastian 4 years ago
parent
commit
6edfee4cf8
  1. 50
      frontend/src/app/shared/state/contents.forms.ts

50
frontend/src/app/shared/state/contents.forms.ts

@ -403,41 +403,47 @@ class ArrayTemplate implements FormArrayTemplate {
} }
public createControl() { public createControl() {
const model = this.model;
const child = this.model.isComponents ? const child = this.model.isComponents ?
this.createComponent() : this.createComponent(model) :
this.createItem(); this.createItem(model);
this.model.internalItems = [...this.model.items, child]; model.internalItems = [...this.model.items, child];
return child.form; return child.form;
} }
public removeControl(index: number) { public removeControl(index: number) {
this.model.internalItems = this.model.items.filter((_, i) => i !== index); const model = this.model;
model.internalItems = model.items.filter((_, i) => i !== index);
} }
public clearControls() { public clearControls() {
this.model.internalItems = []; const model = this.model;
model.internalItems = [];
} }
private createItem() { private createItem(model: FieldArrayForm) {
return new ArrayItemForm( return new ArrayItemForm(
this.model.globals, model.globals,
this.model.field as RootFieldDto, model.field as RootFieldDto,
this.model.fieldPath, model.fieldPath,
this.model.isOptional, model.isOptional,
this.model.rules, model.rules,
this.model.partition); model.partition);
} }
private createComponent() { private createComponent(model: FieldArrayForm) {
return new ComponentForm( return new ComponentForm(
this.model.globals, model.globals,
this.model.field as RootFieldDto, model.field as RootFieldDto,
this.model.fieldPath, model.fieldPath,
this.model.isOptional, model.isOptional,
this.model.rules, model.rules,
this.model.partition); model.partition);
} }
} }
@ -518,10 +524,12 @@ abstract class ObjectTemplate<T extends ObjectFormBase = ObjectFormBase> impleme
const schema = this.getSchema(value, this.model); const schema = this.getSchema(value, this.model);
if (this.currentSchema !== schema) { if (this.currentSchema !== schema) {
this.clearControlsCore(this.model); const model = this.model;
this.clearControlsCore(model);
if (schema) { if (schema) {
this.setControlsCore(schema, value, this.model, form); this.setControlsCore(schema, value, model, form);
} }
this.currentSchema = schema; this.currentSchema = schema;

Loading…
Cancel
Save