Skip to content

Commit ba519b8

Browse files
committed
ColumnMetrics: reset state only if new columns differ from previous
1 parent a901d78 commit ba519b8

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

lib/ColumnMetrics.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ var Mixin = {
112112
},
113113

114114
componentWillReceiveProps(nextProps) {
115-
this.setState(this.getColumnMetrics(nextProps));
115+
if (!sameColumns(this.props.columns, nextProps.columns)) {
116+
this.setState(this.getColumnMetrics(nextProps));
117+
}
116118
},
117119

118120
getColumnMetrics(props, initial) {
@@ -138,4 +140,34 @@ var Mixin = {
138140
}
139141
};
140142

143+
function sameColumns(prevColumns, nextColumns) {
144+
var i, len, column;
145+
var prevColumnsByKey = {};
146+
var nextColumnsByKey = {};
147+
148+
for (i = 0, len = prevColumns.length; i < len; i++) {
149+
column = prevColumns[i];
150+
prevColumnsByKey[column.key] = column;
151+
}
152+
153+
for (i = 0, len = nextColumns.length; i < len; i++) {
154+
column = nextColumns[i];
155+
nextColumnsByKey[column.key] = column;
156+
var prevColumn = prevColumnsByKey[column.key];
157+
if (prevColumn === undefined || prevColumn.width !== column.width) {
158+
return false;
159+
}
160+
}
161+
162+
for (i = 0, len = prevColumns.length; i < len; i++) {
163+
column = prevColumns[i];
164+
var nextColumn = nextColumnsByKey[column.key];
165+
if (nextColumn === undefined || nextColumn.width !== column.width) {
166+
return false;
167+
}
168+
}
169+
170+
return true;
171+
}
172+
141173
module.exports = {Mixin, calculate, resizeColumn};

0 commit comments

Comments
 (0)