mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-08-12 20:00:17 +00:00
refactoring shouldComponentUpdate for aggreate and simple row for cell editing
This commit is contained in:
@@ -22,7 +22,7 @@ class SelectionProvider extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
state = { selected: (this.props.selectRow && this.props.selectRow.selected) || [] };
|
||||
state = { selected: this.props.selectRow.selected || [] };
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.selectRow) {
|
||||
|
||||
@@ -31,13 +31,12 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
|
||||
this.props.selected !== nextProps.selected ||
|
||||
this.props.expanded !== nextProps.expanded ||
|
||||
this.props.selectable !== nextProps.selectable ||
|
||||
this.shouldUpdateByWhenEditing(nextProps) ||
|
||||
this.shouldUpdatedBySelfProps(nextProps)
|
||||
) {
|
||||
this.shouldUpdateRowContent = this.shouldUpdatedByNormalProps(nextProps);
|
||||
this.shouldUpdateRowContent = this.shouldUpdateChild(nextProps);
|
||||
return true;
|
||||
}
|
||||
this.shouldUpdateRowContent = this.shouldUpdatedByNormalProps(nextProps);
|
||||
this.shouldUpdateRowContent = this.shouldUpdateChild(nextProps);
|
||||
|
||||
return this.shouldUpdateRowContent;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ export default ExtendBase =>
|
||||
}
|
||||
};
|
||||
|
||||
if (DELAY_FOR_DBCLICK) {
|
||||
if (DELAY_FOR_DBCLICK && selectRow.clickToEdit) {
|
||||
this.clickNum += 1;
|
||||
_.debounce(() => {
|
||||
if (this.clickNum === 1) {
|
||||
|
||||
@@ -3,7 +3,8 @@ import _ from '../utils';
|
||||
|
||||
export default ExtendBase =>
|
||||
class RowShouldUpdater extends ExtendBase {
|
||||
shouldUpdateByWhenEditing(nextProps) {
|
||||
shouldUpdateByCellEditing(nextProps) {
|
||||
if (!(this.props.clickToEdit || this.props.dbclickToEdit)) return false;
|
||||
return (
|
||||
nextProps.editingRowIdx === nextProps.rowIndex ||
|
||||
(this.props.editingRowIdx === nextProps.rowIndex &&
|
||||
@@ -28,4 +29,9 @@ export default ExtendBase =>
|
||||
|
||||
return shouldUpdate;
|
||||
}
|
||||
|
||||
shouldUpdateChild(nextProps) {
|
||||
return this.shouldUpdateByCellEditing(nextProps) ||
|
||||
this.shouldUpdatedByNormalProps(nextProps);
|
||||
}
|
||||
};
|
||||
|
||||
+1
-2
@@ -15,8 +15,7 @@ class Row extends shouldUpdater(eventDelegater(Component)) {
|
||||
|
||||
shouldComponentUpdate(nextProps) {
|
||||
this.shouldUpdateRowContent = false;
|
||||
this.shouldUpdateRowContent =
|
||||
this.shouldUpdateByWhenEditing(nextProps) || this.shouldUpdatedByNormalProps(nextProps);
|
||||
this.shouldUpdateRowContent = this.shouldUpdateChild(nextProps);
|
||||
if (this.shouldUpdateRowContent) return true;
|
||||
|
||||
return this.shouldUpdatedBySelfProps(nextProps);
|
||||
|
||||
@@ -12,8 +12,8 @@ describe('Row shouldUpdater', () => {
|
||||
render() { return null; }
|
||||
}
|
||||
|
||||
describe('shouldUpdateByWhenEditing', () => {
|
||||
describe('when nextProps.editingRowIdx eq props.rowIndex and it\' not null', () => {
|
||||
describe('shouldUpdateByCellEditing', () => {
|
||||
describe('when nextProps.clickToEdit and nexrProps.dbclickToEdit both are negative', () => {
|
||||
beforeEach(() => {
|
||||
props = {
|
||||
editingRowIdx: null,
|
||||
@@ -22,15 +22,31 @@ describe('Row shouldUpdater', () => {
|
||||
wrapper = shallow(<DummyComponent { ...props } />);
|
||||
});
|
||||
|
||||
it('should always return false', () => {
|
||||
nextProps = { ...props, editingRowIdx: 0 };
|
||||
expect(wrapper.instance().shouldUpdateByCellEditing(nextProps)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
describe('when nextProps.editingRowIdx eq props.rowIndex and it\' not null', () => {
|
||||
beforeEach(() => {
|
||||
props = {
|
||||
clickToEdit: true,
|
||||
editingRowIdx: null,
|
||||
rowIndex: 0
|
||||
};
|
||||
wrapper = shallow(<DummyComponent { ...props } />);
|
||||
});
|
||||
|
||||
it('should return true', () => {
|
||||
nextProps = { ...props, editingRowIdx: 0 };
|
||||
expect(wrapper.instance().shouldUpdateByWhenEditing(nextProps)).toBeTruthy();
|
||||
expect(wrapper.instance().shouldUpdateByCellEditing(nextProps)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when props.editingRowIdx eq props.rowIndex but nextProps.editingRowIdx is null', () => {
|
||||
beforeEach(() => {
|
||||
props = {
|
||||
clickToEdit: true,
|
||||
editingRowIdx: 0,
|
||||
rowIndex: 0
|
||||
};
|
||||
@@ -39,7 +55,7 @@ describe('Row shouldUpdater', () => {
|
||||
|
||||
it('should return true', () => {
|
||||
nextProps = { ...props, editingRowIdx: null };
|
||||
expect(wrapper.instance().shouldUpdateByWhenEditing(nextProps)).toBeTruthy();
|
||||
expect(wrapper.instance().shouldUpdateByCellEditing(nextProps)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user