instance.unstable_asyncUpdates = true creates an async subtree

Same behavior as unstable_asyncRender. Can be used to wrap a specific
subtree, rather than an entire root.
This commit is contained in:
Andrew Clark
2017-04-17 14:56:10 -07:00
parent 3bf398bcbc
commit 609e97ebe7
2 changed files with 50 additions and 0 deletions
@@ -70,6 +70,52 @@ describe('ReactDOMFiberAsync', () => {
jest.runAllTimers();
expect(container.textContent).toEqual('1');
});
it('unstable_asyncUpdates creates an async subtree', () => {
let instance;
class Component extends React.Component {
state = {step: 0};
unstable_asyncUpdates = true;
render() {
instance = this;
return <div>{this.state.step}</div>;
}
}
ReactDOM.render(<Component />, container);
jest.runAllTimers();
instance.setState({step: 1});
expect(container.textContent).toEqual('0');
jest.runAllTimers();
expect(container.textContent).toEqual('1');
});
it('updates inside an async subtree are async by default', () => {
class Component extends React.Component {
unstable_asyncUpdates = true;
render() {
return <Child />;
}
}
let instance;
class Child extends React.Component {
state = {step: 0};
render() {
instance = this;
return <div>{this.state.step}</div>;
}
}
ReactDOM.render(<Component />, container);
jest.runAllTimers();
instance.setState({step: 1});
expect(container.textContent).toEqual('0');
jest.runAllTimers();
expect(container.textContent).toEqual('1');
})
});
}
});
@@ -305,6 +305,10 @@ module.exports = function(
instance.refs = emptyObject;
instance.context = getMaskedContext(workInProgress, unmaskedContext);
if (instance.unstable_asyncUpdates === true) {
workInProgress.contextTag |= AsyncUpdates;
}
if (typeof instance.componentWillMount === 'function') {
if (__DEV__) {
startPhaseTimer(workInProgress, 'componentWillMount');