-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed and added test for memoization bug
- Loading branch information
1 parent
9e49751
commit 42c0704
Showing
5 changed files
with
131 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import { Row, Col } from '../../../dist'; | ||
|
||
export default class Grid extends Component { | ||
|
||
static propTypes = { | ||
value: PropTypes.string | ||
}; | ||
|
||
render () { | ||
const { value } = this.props; | ||
|
||
return ( | ||
<Row> | ||
<Col size={3}> | ||
<button>{value}</button> | ||
</Col> | ||
<Col size={3}> | ||
<button>{value}</button> | ||
</Col> | ||
<Col size={6}> | ||
<Row> | ||
<Col size={6}>YAR!</Col> | ||
<Col size={6}>{value}</Col> | ||
</Row> | ||
</Col> | ||
</Row> | ||
); | ||
} | ||
} |
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,69 @@ | ||
import React, {Component, PropTypes} from 'react'; | ||
import Perf from 'react-addons-perf'; | ||
|
||
window.Perf = Perf; | ||
|
||
export default class PerfTest extends Component { | ||
|
||
static propTypes = { | ||
children: PropTypes.any, | ||
loops: PropTypes.number, | ||
onComplete: PropTypes.func, | ||
testFn: PropTypes.func, | ||
testProp: PropTypes.string | ||
}; | ||
|
||
static defaultProps = { | ||
loops: 100 | ||
}; | ||
|
||
componentWillMount () { | ||
this.setTestProp(); | ||
} | ||
|
||
componentDidMount () { | ||
this.runTest().then(() => this.endTest()); | ||
} | ||
|
||
setTestProp (cb = () => {}) { | ||
const {testProp, testFn} = this.props; | ||
this.setState({ | ||
[testProp]: testFn() | ||
}, cb); | ||
} | ||
|
||
runTest () { | ||
let i = 0; | ||
Perf.start(); | ||
return new Promise(resolve => { | ||
const execTest = () => { | ||
i++; | ||
setTimeout(() => { | ||
if (i < this.props.loops) { | ||
this.setTestProp(execTest); | ||
} else { | ||
Perf.stop(); | ||
resolve(Perf); | ||
} | ||
}, 10); | ||
}; | ||
execTest(); | ||
}); | ||
} | ||
|
||
endTest () { | ||
const measurements = Perf.getLastMeasurements(); | ||
const summary = Perf.getMeasurementsSummaryMap(measurements); | ||
|
||
return this.props.onComplete(summary); | ||
} | ||
|
||
render () { | ||
const { children, testProp } = this.props; | ||
const testValue = this.state[testProp]; | ||
|
||
return React.cloneElement(children, { | ||
[testProp]: testValue | ||
}); | ||
} | ||
} |
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