Skip to content

Commit

Permalink
fix(directive): Check if inputs really changed when angular triggers …
Browse files Browse the repository at this point in the history
…change detection on them

Because object structure might not change while the reference will

closes #111
  • Loading branch information
Alex Malkevich committed Apr 19, 2018
1 parent 68b6e32 commit 14c953c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/dynamic/dynamic.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ describe('Directive: Dynamic', () => {
fixture.componentInstance['inputs'] = null;
expect(() => fixture.detectChanges()).not.toThrow();
});

it('should NOT throw exception when same inputs are reassigned with new object', () => {
fixture.detectChanges();
fixture.componentInstance['inputs'] = { ...fixture.componentInstance['inputs'] };
expect(() => fixture.detectChanges()).not.toThrow();
});
});

describe('inputs with `NgComponentOutlet`', () => {
Expand Down
8 changes: 6 additions & 2 deletions src/dynamic/dynamic.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ export class DynamicDirective implements OnChanges, DoCheck, OnDestroy {
this.bindOutputs();
} else {
if (this._inputsChanged(changes)) {
this._updateInputChanges(this._getInputsChanges(this._inputs));
this.updateInputs(!this._lastInputChanges);
const inputsChanges = this._getInputsChanges(this._inputs);

if (inputsChanges) {
this._updateInputChanges(inputsChanges);
this.updateInputs(!this._lastInputChanges);
}
}

if (this._outputsChanged(changes)) {
Expand Down

0 comments on commit 14c953c

Please sign in to comment.