Skip to content

Commit

Permalink
fix(module:form): fix repeated trigger change detection (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored Oct 18, 2018
1 parent a40bc13 commit a9f2db6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
1 change: 0 additions & 1 deletion packages/form/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export abstract class Widget<T extends FormProperty> implements AfterViewInit {
}

detectChanges() {
this.cd.detectChanges();
this.formProperty.root.widget.cd.markForCheck();
}

Expand Down
20 changes: 7 additions & 13 deletions packages/form/src/widgets/custom/custom.widget.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { DebugElement } from '@angular/core';
import { ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { deepCopy } from '@delon/util';
import {
builder,
TestFormComponent,
SFPage,
SCHEMA,
} from '../../../spec/base.spec';
import { ComponentFixture } from '@angular/core/testing';
import { builder, TestFormComponent, SFPage } from '../../../spec/base.spec';
import { SFSchema } from '../../../src/schema/index';
import { SFUISchemaItem, SFUISchema } from '../../../src/schema/ui';

describe('form: widget: custom', () => {
let fixture: ComponentFixture<TestFormComponent>;
Expand All @@ -21,13 +14,14 @@ describe('form: widget: custom', () => {

function detectChanges(path = '/a') {
context.comp.rootProperty.searchProperty(path).widget.detectChanges();
fixture.detectChanges();
return page;
}

it('should be custom widget', () => {
({ fixture, dl, context, page } = builder({
detectChanges: false,
template: `<sf [schema]="schema" #comp><ng-template sf-template="/a">custom:<div class="custom-el">{{ id }}</div></ng-template></sf>`
template: `<sf [schema]="schema" #comp><ng-template sf-template="/a">custom:<div class="custom-el">{{ id }}</div></ng-template></sf>`,
}));
page.newSchema(schema);
detectChanges().checkCount('.custom-el', 1);
Expand All @@ -36,7 +30,7 @@ describe('form: widget: custom', () => {
it('should be auto fix path when not start with /', () => {
({ fixture, dl, context, page } = builder({
detectChanges: false,
template: `<sf [schema]="schema" #comp><ng-template sf-template="a">custom:<div class="custom-el">{{ id }}</div></ng-template></sf>`
template: `<sf [schema]="schema" #comp><ng-template sf-template="a">custom:<div class="custom-el">{{ id }}</div></ng-template></sf>`,
}));
page.newSchema(schema);
detectChanges().checkCount('.custom-el', 1);
Expand All @@ -46,7 +40,7 @@ describe('form: widget: custom', () => {
spyOn(console, 'warn');
({ fixture, dl, context, page } = builder({
detectChanges: false,
template: `<sf [schema]="schema" #comp><ng-template sf-template="invalud_a">custom:<div class="custom-el">{{ id }}</div></ng-template></sf>`
template: `<sf [schema]="schema" #comp><ng-template sf-template="invalud_a">custom:<div class="custom-el">{{ id }}</div></ng-template></sf>`,
}));
page.newSchema(schema);
expect(console.warn).toHaveBeenCalled();
Expand All @@ -55,7 +49,7 @@ describe('form: widget: custom', () => {
it('#ng-alain-issues-492: should changed default data', () => {
({ fixture, dl, context, page } = builder({
detectChanges: false,
template: `<sf [schema]="schema" [formData]="formData" #comp><ng-template sf-template="/a">custom:<div class="custom-el">{{ id }}</div></ng-template></sf>`
template: `<sf [schema]="schema" [formData]="formData" #comp><ng-template sf-template="/a">custom:<div class="custom-el">{{ id }}</div></ng-template></sf>`,
}));
page.newSchema(schema);
detectChanges().checkCount('.custom-el', 1);
Expand Down

0 comments on commit a9f2db6

Please sign in to comment.