refactor(Table): make row work like a class property

This commit is contained in:
kristof0425 2019-09-02 11:10:08 +02:00 committed by 偏右
parent 2875933c99
commit 3274c55bdf

View File

@ -91,19 +91,25 @@ const emptyObject = {};
let row: BodyRowClass | undefined;
const createComponents = (components: TableComponents = {}, prevComponents?: TableComponents) => {
const createComponents = (
components: TableComponents = {},
prevComponents?: TableComponents,
isCalledFromConstructor?: boolean,
) => {
const bodyRow = components && components.body && components.body.row;
const prevBodyRow = prevComponents && prevComponents.body && prevComponents.body.row;
let Row = row;
row = undefined;
if (!Row || bodyRow !== prevBodyRow) {
Row = createBodyRow(bodyRow);
if (isCalledFromConstructor) {
// 'row' needs to act like a class property
row = undefined;
}
if (!row || bodyRow !== prevBodyRow) {
row = createBodyRow(bodyRow);
}
return {
...components,
body: {
...components.body,
row: Row,
row,
},
};
};
@ -283,7 +289,7 @@ class Table<T> extends React.Component<TableProps<T>, TableState<T>> {
pagination: this.getDefaultPagination(props),
pivot: undefined,
prevProps: props,
components: createComponents(props.components),
components: createComponents(props.components, undefined, true),
columns,
};
}