Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Feb 12, 2021
1 parent 7efabaa commit f18cbb9
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 21 deletions.
38 changes: 38 additions & 0 deletions benchmark/browser/scenarios/table-cell/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as React from 'react';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell';
import TableHead from '@material-ui/core/TableHead';
import TableRow from '@material-ui/core/TableRow';

const data = { name: 'Frozen yoghurt', calories: 159, fat: 6.0, carbs: 24, protein: 4.0 };
const rows = Array.from(new Array(100)).map(() => data);

export default function TableCellCase() {
return (
<Table>
<TableHead>
<TableRow>
<TableCell>Dessert (100g serving)</TableCell>
<TableCell>Calories</TableCell>
<TableCell>Fat&nbsp;(g)</TableCell>
<TableCell>Carbs&nbsp;(g)</TableCell>
<TableCell>Protein&nbsp;(g)</TableCell>
</TableRow>
</TableHead>
<TableBody>
{rows.map((row, index) => (
<TableRow key={index}>
<TableCell component="th" scope="row">
{row.name}
</TableCell>
<TableCell>{row.calories}</TableCell>
<TableCell>{row.fat}</TableCell>
<TableCell>{row.carbs}</TableCell>
<TableCell>{row.protein}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
);
}
5 changes: 5 additions & 0 deletions benchmark/browser/scripts/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ async function run() {
name: 'noop (baseline)',
path: './noop/index.js',
},
// Test that there no significant offset
{
name: 'Table',
path: './table-cell/index.js',
},
// Test the cost of React primitives
{
name: 'React primitives',
Expand Down
4 changes: 1 addition & 3 deletions docs/pages/performance/table-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const TableBody = createComponent('tbody');
const data = { name: 'Frozen yoghurt', calories: 159, fat: 6.0, carbs: 24, protein: 4.0 };
const rows = Array.from(new Array(100)).map(() => data);

function TableComponent() {
export default function TableComponent() {
return (
<NoSsr defer>
<Table>
Expand Down Expand Up @@ -55,5 +55,3 @@ function TableComponent() {
</NoSsr>
);
}

export default TableComponent;
4 changes: 1 addition & 3 deletions docs/pages/performance/table-emotion.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const TableBody = createComponent('tbody');
const data = { name: 'Frozen yoghurt', calories: 159, fat: 6.0, carbs: 24, protein: 4.0 };
const rows = Array.from(new Array(100)).map(() => data);

function TableEmotion() {
export default function TableEmotion() {
return (
<NoSsr defer>
<Table>
Expand Down Expand Up @@ -61,5 +61,3 @@ function TableEmotion() {
</NoSsr>
);
}

export default TableEmotion;
4 changes: 1 addition & 3 deletions docs/pages/performance/table-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const TableBody = createComponent('tbody');
const data = { name: 'Frozen yoghurt', calories: 159, fat: 6.0, carbs: 24, protein: 4.0 };
const rows = Array.from(new Array(100)).map(() => data);

function TableHook() {
export default function TableHook() {
return (
<NoSsr defer>
<Table>
Expand Down Expand Up @@ -63,5 +63,3 @@ function TableHook() {
</NoSsr>
);
}

export default TableHook;
4 changes: 1 addition & 3 deletions docs/pages/performance/table-mui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TableRow from '@material-ui/core/TableRow';
const data = { name: 'Frozen yoghurt', calories: 159, fat: 6.0, carbs: 24, protein: 4.0 };
const rows = Array.from(new Array(100)).map(() => data);

function TableMui() {
export default function TableMui() {
return (
<NoSsr defer>
<Table>
Expand Down Expand Up @@ -39,5 +39,3 @@ function TableMui() {
</NoSsr>
);
}

export default TableMui;
4 changes: 1 addition & 3 deletions docs/pages/performance/table-raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import NoSsr from '@material-ui/core/NoSsr';
const data = { name: 'Frozen yoghurt', calories: 159, fat: 6.0, carbs: 24, protein: 4.0 };
const rows = Array.from(new Array(100)).map(() => data);

function TableRaw() {
export default function TableRaw() {
return (
<NoSsr defer>
<table>
Expand Down Expand Up @@ -32,5 +32,3 @@ function TableRaw() {
</NoSsr>
);
}

export default TableRaw;
4 changes: 1 addition & 3 deletions docs/pages/performance/table-styled-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const TableBody = createComponent('tbody');
const data = { name: 'Frozen yoghurt', calories: 159, fat: 6.0, carbs: 24, protein: 4.0 };
const rows = Array.from(new Array(100)).map(() => data);

function TableStyledComponents() {
export default function TableStyledComponents() {
return (
<NoSsr defer>
<Table>
Expand Down Expand Up @@ -58,5 +58,3 @@ function TableStyledComponents() {
</NoSsr>
);
}

export default TableStyledComponents;
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ export default function getThemeProps(params) {
return props;
}

const output = { ...props };

// Resolve default props, code borrow from React source.
// https://github.com/facebook/react/blob/15a8f031838a553e41c0b66eb1bcf1da8448104d/packages/react/src/ReactElement.js#L221
const defaultProps = theme.components[name].defaultProps;
let propName;

for (propName in defaultProps) {
if (props[propName] === undefined) {
props[propName] = defaultProps[propName];
if (output[propName] === undefined) {
output[propName] = defaultProps[propName];
}
}

return props;
return output;
}

0 comments on commit f18cbb9

Please sign in to comment.