-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ddda9d
commit d9e7211
Showing
20 changed files
with
142 additions
and
15 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
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,58 @@ | ||
import Container from '@material-ui/core/Container'; | ||
import React from 'react'; | ||
import { collect } from 'react-recollect'; | ||
import StorePropType from '../../propTypes/StorePropType'; | ||
import Parent from './Parent'; | ||
|
||
class BatchedUpdates extends React.Component { | ||
renderCount = 1; | ||
|
||
update = () => { | ||
this.props.store.batchUpdatePage.text += '×'; | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Container> | ||
<h2>Render count: {this.renderCount++}</h2> | ||
|
||
<p> | ||
When functioning correctly, clicking either button below triggers only | ||
a single render for each component | ||
</p> | ||
|
||
<hr /> | ||
<p> | ||
This changes the store within an onClick handler. In this case, React | ||
will batch updates and trigger a single render by default | ||
</p> | ||
<button onClick={this.update}>Increment</button> | ||
|
||
<hr /> | ||
|
||
<p> | ||
This changes the store outside of a onClick handler (in a setTimeout | ||
callback). In this case, React can’t batch updates, but the batching | ||
is handled internally by Recollect. | ||
</p> | ||
<button | ||
onClick={() => { | ||
setTimeout(this.update); | ||
}} | ||
> | ||
Increment async | ||
</button> | ||
|
||
<hr /> | ||
|
||
<Parent /> | ||
</Container> | ||
); | ||
} | ||
} | ||
|
||
BatchedUpdates.propTypes = { | ||
store: StorePropType.isRequired, | ||
}; | ||
|
||
export default collect(BatchedUpdates); |
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,26 @@ | ||
import React from 'react'; | ||
import { collect, PropTypes } from 'react-recollect'; | ||
import StorePropType from '../../propTypes/StorePropType'; | ||
|
||
class Child extends React.Component { | ||
renderCount = 1; | ||
|
||
render() { | ||
const { text } = this.props.store.batchUpdatePage; | ||
|
||
return ( | ||
<div> | ||
<h1>{`Child renders: ${this.renderCount++}`}</h1> | ||
<h2>{`Child value: ${text}`}</h2> | ||
<h2>{`Child value fromParent: ${this.props.fromParent}`}</h2> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Child.propTypes = { | ||
fromParent: PropTypes.string.isRequired, | ||
store: StorePropType.isRequired, | ||
}; | ||
|
||
export default collect(Child); |
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,26 @@ | ||
import React from 'react'; | ||
import { collect } from 'react-recollect'; | ||
import StorePropType from '../../propTypes/StorePropType'; | ||
import Child from './Child'; | ||
|
||
class Parent extends React.Component { | ||
renderCount = 1; | ||
|
||
render() { | ||
const { text } = this.props.store.batchUpdatePage; | ||
|
||
return ( | ||
<div> | ||
<h1>{`Parent renders: ${this.renderCount++}`}</h1> | ||
<h2>{`Parent value: ${text}`}</h2> | ||
<Child fromParent={`${text}!`} /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Parent.propTypes = { | ||
store: StorePropType.isRequired, | ||
}; | ||
|
||
export default collect(Parent); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { TYPES } from '../todomvc/constants'; | ||
import { TYPES } from '../../shared/constants'; | ||
|
||
let id = 99; | ||
|
||
|
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
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
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