Skip to content

Commit

Permalink
fix(component): Add missing runOutsideAngular wrappers
Browse files Browse the repository at this point in the history
Every call of Handsontable functions should be wrapped to prevent
triggers of Angular change detection.
  • Loading branch information
rene-leanix committed Apr 9, 2018
1 parent 526d3e3 commit b1fb869
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/handsontable.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,14 @@ export class HotTableComponent implements OnInit, OnDestroy, OnChanges {
const contains = (testProperties: TriggerableInputProperty[]) =>
_.intersection(properties, testProperties).length > 0;
if (this.inst) {
if (contains(optionsInputProperties)) {
this.inst.updateSettings(this.getCurrentOptions(), false);
}
if (contains(['data'])) {
this.inst.loadData(this.data);
}
this.ngZone.runOutsideAngular(() => {
if (contains(optionsInputProperties)) {
this.inst.updateSettings(this.getCurrentOptions(), false);
}
if (contains(['data'])) {
this.inst.loadData(this.data);
}
});
}
}

Expand All @@ -206,9 +208,11 @@ export class HotTableComponent implements OnInit, OnDestroy, OnChanges {
this.data = [];
this.pagedDataSubscription = this.pagedData.subscribe((newPagedData: any) => {
Array.prototype.push.apply(this.data, newPagedData);
this.inst.loadData(this.data);
this.ngZone.runOutsideAngular(() => {
this.inst.loadData(this.data);
this.inst.updateSettings(options, false);
});
this.parseAutoComplete(options);
this.inst.updateSettings(options, false);
});
}
}
Expand All @@ -221,7 +225,9 @@ export class HotTableComponent implements OnInit, OnDestroy, OnChanges {
this.pagedDataSubscription.unsubscribe();
}
if (this.inst) {
this.inst.destroy();
this.ngZone.runOutsideAngular(() => {
this.inst.destroy();
});
}
}

Expand All @@ -240,7 +246,6 @@ export class HotTableComponent implements OnInit, OnDestroy, OnChanges {
}

private parseAutoComplete(options: any) {
const inst = this.inst;
const columns = this.columns || options.columns;
const dataSet = options.data;

Expand All @@ -249,7 +254,9 @@ export class HotTableComponent implements OnInit, OnDestroy, OnChanges {
if (typeof column.source === 'string') {
const relatedField: string = column.source;
column.source = (_query: any, process: any) => {
const row: number = inst.getSelected()[0][0];
const row: number = this.ngZone.runOutsideAngular(() =>
this.inst.getSelected()[0][0]
);
const data: any = dataSet[row];

if (!data) {
Expand Down

0 comments on commit b1fb869

Please sign in to comment.