From ec8843fe908814f8b28b4b5d0315905f1268e098 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Mon, 22 Jan 2018 13:24:41 -0800 Subject: [PATCH] Compute benchmark props before each iteration Fix a bug in the logic that was meant to perform component prop computation in-between cycles. --- .../benchmarks/src/app/Benchmark/index.js | 28 ++++----- .../src/cases/SierpinskiTriangle.js | 57 +++++++++---------- yarn.lock | 2 +- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/packages/benchmarks/src/app/Benchmark/index.js b/packages/benchmarks/src/app/Benchmark/index.js index dfad1d8f..dc64af2e 100644 --- a/packages/benchmarks/src/app/Benchmark/index.js +++ b/packages/benchmarks/src/app/Benchmark/index.js @@ -74,7 +74,7 @@ type BenchmarkPropsType = { }; type BenchmarkStateType = { - getComponentProps: Function, + componentProps: Object, cycle: number, running: boolean }; @@ -100,9 +100,10 @@ export default class Benchmark extends Component ({ getComponentProps: nextProps.getComponentProps })); + this.setState(state => ({ componentProps: nextProps.getComponentProps(state.cycle) })); } componentWillUpdate(nextProps: BenchmarkPropsType, nextState: BenchmarkStateType) { @@ -145,13 +146,11 @@ export default class Benchmark extends Component - ) : null; + return running && shouldRender(cycle, type) ? : null; } start() { @@ -165,15 +164,16 @@ export default class Benchmark extends Component ({ ...getComponentProps(obj), 'data-test': cycle }) - : getComponentProps; + const componentProps = getComponentProps({ cycle }); + // make sure props always change for update tests + if (type === BenchmarkType.UPDATE) { + componentProps['data-test'] = cycle; + } this.raf = window.requestAnimationFrame(() => { this.setState((state: BenchmarkStateType) => ({ - getComponentProps: getNextProps, - cycle: state.cycle + 1 + cycle: state.cycle + 1, + componentProps })); }); } diff --git a/packages/benchmarks/src/cases/SierpinskiTriangle.js b/packages/benchmarks/src/cases/SierpinskiTriangle.js index 65a082d0..cc926d9e 100644 --- a/packages/benchmarks/src/cases/SierpinskiTriangle.js +++ b/packages/benchmarks/src/cases/SierpinskiTriangle.js @@ -53,35 +53,34 @@ class SierpinskiTriangle extends React.Component { s /= 2; - return [ - , - , - - ]; + return ( + + + + + + ); } else { return No implementation available; } diff --git a/yarn.lock b/yarn.lock index 922280a7..50a66315 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7950,7 +7950,7 @@ styled-components@2.4.0: stylis "^3.4.0" supports-color "^3.2.3" -styled-jsx@2.2.1, styled-jsx@^2.2.1: +styled-jsx@2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-2.2.1.tgz#8b38b9e53e5d9767e392595ab1afdc8426b3ba5d" dependencies: