-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(react-grid): update only changes rows in table (#199)
- Loading branch information
Showing
9 changed files
with
207 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const TemplateRenderer = ({ template, children, ...restProps }) => | ||
template({ ...restProps, children }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import { TemplateRenderer } from './template-component'; | ||
|
||
describe('TemplateRenderer', () => { | ||
it('should work', () => { | ||
const tree = mount( | ||
<TemplateRenderer | ||
template={({ test, children }) => <div className={test}>{children}</div>} | ||
test={'test'} | ||
> | ||
<div className="content" /> | ||
</TemplateRenderer>, | ||
); | ||
|
||
expect(tree.find('.test > .content').exists()) | ||
.toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/dx-react-grid/src/components/table-layout/row-layout.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
TemplateRenderer, | ||
} from '@devexpress/dx-react-core'; | ||
|
||
import { | ||
tableColumnKeyGetter, | ||
getTableCellInfo, | ||
} from '@devexpress/dx-grid-core'; | ||
|
||
const getColumnStyle = ({ column, animationState = {} }) => ({ | ||
width: column.width !== undefined ? `${column.width}px` : undefined, | ||
...animationState, | ||
}); | ||
|
||
const getRowStyle = ({ row }) => ({ | ||
height: row.height !== undefined ? `${row.height}px` : undefined, | ||
}); | ||
|
||
export class RowLayout extends React.PureComponent { | ||
render() { | ||
const { | ||
row, | ||
columns, | ||
rowTemplate, | ||
cellTemplate, | ||
animationState, | ||
} = this.props; | ||
|
||
return ( | ||
<TemplateRenderer | ||
template={rowTemplate} | ||
row={row} | ||
style={getRowStyle({ row })} | ||
> | ||
{ | ||
columns | ||
.filter((column, columnIndex) => !getTableCellInfo({ row, columns, columnIndex }).skip) | ||
.map((column, columnIndex) => { | ||
const key = tableColumnKeyGetter(column, columnIndex); | ||
const colspan = getTableCellInfo({ row, columns, columnIndex }).colspan; | ||
return ( | ||
<TemplateRenderer | ||
key={key} | ||
template={cellTemplate} | ||
row={row} | ||
column={column} | ||
style={getColumnStyle({ column, animationState: animationState.get(key) })} | ||
{...colspan ? { colspan } : null} | ||
/> | ||
); | ||
}) | ||
} | ||
</TemplateRenderer> | ||
); | ||
} | ||
} | ||
|
||
RowLayout.propTypes = { | ||
row: PropTypes.object.isRequired, | ||
columns: PropTypes.array.isRequired, | ||
rowTemplate: PropTypes.func.isRequired, | ||
cellTemplate: PropTypes.func.isRequired, | ||
animationState: PropTypes.instanceOf(Map).isRequired, | ||
}; |
Oops, something went wrong.