isBatchingUpdates

    1. class List extends React.PureComponent {
    2. constructor (props) {}
    3. render () {}
    4. onChange = () => {
    5. // 开始,处于 batchUpdate
    6. // isBatchingUpdates = true
    7. // 其他操作
    8. setTimeout(() => {
    9. // 此时的 isBatchUpdates = false
    10. this.setState({
    11. number: this.state.number + 1
    12. })
    13. })
    14. // 结束 isBatchingUpdates = false
    15. }
    16. }
    17. // transaction 面向切片编程
    18. transaction.initialize = function () { console.log('init') }
    19. transaction.close = function () { console.log('close') }
    20. function fn() { console.log('todo anything') }
    21. transcation.perform(fn)