Skip to content

Commit

Permalink
Prefix mock Scheduler APIs with _unstable
Browse files Browse the repository at this point in the history
For now this is only meant to be consumed via `act`.
  • Loading branch information
acdlite committed Jun 26, 2019
1 parent 9b55bcf commit a0161d9
Show file tree
Hide file tree
Showing 61 changed files with 1,136 additions and 1,021 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('createSubscription', () => {
ReactNoop.render(
<Subscription source={observable}>
{(value = 'default') => {
Scheduler.yieldValue(value);
Scheduler.unstable_yieldValue(value);
return null;
}}
</Subscription>,
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('createSubscription', () => {
});

function render(value = 'default') {
Scheduler.yieldValue(value);
Scheduler.unstable_yieldValue(value);
return null;
}

Expand Down Expand Up @@ -126,9 +126,9 @@ describe('createSubscription', () => {

function render(hasLoaded) {
if (hasLoaded === undefined) {
Scheduler.yieldValue('loading');
Scheduler.unstable_yieldValue('loading');
} else {
Scheduler.yieldValue(hasLoaded ? 'finished' : 'failed');
Scheduler.unstable_yieldValue(hasLoaded ? 'finished' : 'failed');
}
return null;
}
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('createSubscription', () => {
});

function render(value = 'default') {
Scheduler.yieldValue(value);
Scheduler.unstable_yieldValue(value);
return null;
}

Expand Down Expand Up @@ -203,7 +203,7 @@ describe('createSubscription', () => {
});

function render(hasLoaded) {
Scheduler.yieldValue('rendered');
Scheduler.unstable_yieldValue('rendered');
return null;
}

Expand Down Expand Up @@ -235,7 +235,7 @@ describe('createSubscription', () => {
});

function render(value = 'default') {
Scheduler.yieldValue(value);
Scheduler.unstable_yieldValue(value);
return null;
}

Expand Down Expand Up @@ -268,7 +268,7 @@ describe('createSubscription', () => {
const log = [];

function Child({value}) {
Scheduler.yieldValue('Child: ' + value);
Scheduler.unstable_yieldValue('Child: ' + value);
return null;
}

Expand Down Expand Up @@ -305,7 +305,7 @@ describe('createSubscription', () => {
return (
<Subscription source={this.state.observed}>
{(value = 'default') => {
Scheduler.yieldValue('Subscriber: ' + value);
Scheduler.unstable_yieldValue('Subscriber: ' + value);
return <Child value={value} />;
}}
</Subscription>
Expand Down Expand Up @@ -355,7 +355,7 @@ describe('createSubscription', () => {
const log = [];

function Child({value}) {
Scheduler.yieldValue('Child: ' + value);
Scheduler.unstable_yieldValue('Child: ' + value);
return null;
}

Expand Down Expand Up @@ -392,7 +392,7 @@ describe('createSubscription', () => {
return (
<Subscription source={this.state.observed}>
{(value = 'default') => {
Scheduler.yieldValue('Subscriber: ' + value);
Scheduler.unstable_yieldValue('Subscriber: ' + value);
return <Child value={value} />;
}}
</Subscription>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-art/src/__tests__/ReactART-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ describe('ReactART', () => {
const CurrentRendererContext = React.createContext(null);

function Yield(props) {
Scheduler.yieldValue(props.value);
Scheduler.unstable_yieldValue(props.value);
return null;
}

Expand Down
20 changes: 10 additions & 10 deletions packages/react-cache/src/__tests__/ReactCache-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ describe('ReactCache', () => {
listeners = [{resolve, reject}];
setTimeout(() => {
if (textResourceShouldFail) {
Scheduler.yieldValue(`Promise rejected [${text}]`);
Scheduler.unstable_yieldValue(`Promise rejected [${text}]`);
status = 'rejected';
value = new Error('Failed to load: ' + text);
listeners.forEach(listener => listener.reject(value));
} else {
Scheduler.yieldValue(`Promise resolved [${text}]`);
Scheduler.unstable_yieldValue(`Promise resolved [${text}]`);
status = 'resolved';
value = text;
listeners.forEach(listener => listener.resolve(value));
Expand Down Expand Up @@ -78,21 +78,21 @@ describe('ReactCache', () => {
});

function Text(props) {
Scheduler.yieldValue(props.text);
Scheduler.unstable_yieldValue(props.text);
return props.text;
}

function AsyncText(props) {
const text = props.text;
try {
TextResource.read([props.text, props.ms]);
Scheduler.yieldValue(text);
Scheduler.unstable_yieldValue(text);
return text;
} catch (promise) {
if (typeof promise.then === 'function') {
Scheduler.yieldValue(`Suspend! [${text}]`);
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
} else {
Scheduler.yieldValue(`Error! [${text}]`);
Scheduler.unstable_yieldValue(`Error! [${text}]`);
}
throw promise;
}
Expand Down Expand Up @@ -156,7 +156,7 @@ describe('ReactCache', () => {
});

function App() {
Scheduler.yieldValue('App');
Scheduler.unstable_yieldValue('App');
return BadTextResource.read(['Hi', 100]);
}

Expand Down Expand Up @@ -321,13 +321,13 @@ describe('ReactCache', () => {
const text = props.text;
try {
const actualText = BadTextResource.read([props.text, props.ms]);
Scheduler.yieldValue(actualText);
Scheduler.unstable_yieldValue(actualText);
return actualText;
} catch (promise) {
if (typeof promise.then === 'function') {
Scheduler.yieldValue(`Suspend! [${text}]`);
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
} else {
Scheduler.yieldValue(`Error! [${text}]`);
Scheduler.unstable_yieldValue(`Error! [${text}]`);
}
throw promise;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ describe('ReactHooksInspectionIntegration', () => {

await LazyFoo;

Scheduler.flushAll();
Scheduler.unstable_flushAll();

let childFiber = renderer.root._currentFiber();
let tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('ReactDOMFiberAsync', () => {
}
const root = ReactDOM.unstable_createRoot(container);
root.render(<Counter />);
Scheduler.flushAll();
Scheduler.unstable_flushAll();
expect(asyncValueRef.current.textContent).toBe('');
expect(syncValueRef.current.textContent).toBe('');

Expand All @@ -97,7 +97,7 @@ describe('ReactDOMFiberAsync', () => {

// Should flush both updates now.
jest.runAllTimers();
Scheduler.flushAll();
Scheduler.unstable_flushAll();
expect(asyncValueRef.current.textContent).toBe('hello');
expect(syncValueRef.current.textContent).toBe('hello');
});
Expand All @@ -115,12 +115,12 @@ describe('ReactDOMFiberAsync', () => {
const root = ReactDOM.unstable_createRoot(container);
root.render(<div>Hi</div>);
expect(container.textContent).toEqual('');
Scheduler.flushAll();
Scheduler.unstable_flushAll();
expect(container.textContent).toEqual('Hi');

root.render(<div>Bye</div>);
expect(container.textContent).toEqual('Hi');
Scheduler.flushAll();
Scheduler.unstable_flushAll();
expect(container.textContent).toEqual('Bye');
});

Expand All @@ -137,12 +137,12 @@ describe('ReactDOMFiberAsync', () => {
const root = ReactDOM.unstable_createRoot(container);
root.render(<Component />);
expect(container.textContent).toEqual('');
Scheduler.flushAll();
Scheduler.unstable_flushAll();
expect(container.textContent).toEqual('0');

instance.setState({step: 1});
expect(container.textContent).toEqual('0');
Scheduler.flushAll();
Scheduler.unstable_flushAll();
expect(container.textContent).toEqual('1');
});

Expand Down Expand Up @@ -264,7 +264,7 @@ describe('ReactDOMFiberAsync', () => {

const root = ReactDOM.unstable_createRoot(container);
root.render(<Component />);
Scheduler.flushAll();
Scheduler.unstable_flushAll();

// Updates are async by default
instance.push('A');
Expand All @@ -287,7 +287,7 @@ describe('ReactDOMFiberAsync', () => {
expect(ops).toEqual(['BC']);

// Flush the async updates
Scheduler.flushAll();
Scheduler.unstable_flushAll();
expect(container.textContent).toEqual('ABCD');
expect(ops).toEqual(['BC', 'ABCD']);
});
Expand All @@ -305,13 +305,13 @@ describe('ReactDOMFiberAsync', () => {
}
const root = ReactDOM.unstable_createRoot(container);
root.render(<Counter />);
Scheduler.flushAll();
Scheduler.unstable_flushAll();
expect(container.textContent).toEqual('0');

// Test that a normal update is async
inst.increment();
expect(container.textContent).toEqual('0');
Scheduler.flushAll();
Scheduler.unstable_flushAll();
expect(container.textContent).toEqual('1');

let ops = [];
Expand Down Expand Up @@ -417,7 +417,7 @@ describe('ReactDOMFiberAsync', () => {
const root = ReactDOM.unstable_createRoot(container);
root.render(<Form />);
// Flush
Scheduler.flushAll();
Scheduler.unstable_flushAll();

let disableButton = disableButtonRef.current;
expect(disableButton.tagName).toBe('BUTTON');
Expand Down Expand Up @@ -484,7 +484,7 @@ describe('ReactDOMFiberAsync', () => {
const root = ReactDOM.unstable_createRoot(container);
root.render(<Form />);
// Flush
Scheduler.flushAll();
Scheduler.unstable_flushAll();

let disableButton = disableButtonRef.current;
expect(disableButton.tagName).toBe('BUTTON');
Expand Down Expand Up @@ -544,7 +544,7 @@ describe('ReactDOMFiberAsync', () => {
const root = ReactDOM.unstable_createRoot(container);
root.render(<Form />);
// Flush
Scheduler.flushAll();
Scheduler.unstable_flushAll();

let enableButton = enableButtonRef.current;
expect(enableButton.tagName).toBe('BUTTON');
Expand Down Expand Up @@ -576,7 +576,7 @@ describe('ReactDOMFiberAsync', () => {
const root = ReactDOM.unstable_createSyncRoot(container);

function Text(props) {
Scheduler.yieldValue(props.text);
Scheduler.unstable_yieldValue(props.text);
return props.text;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/react-dom/src/__tests__/ReactDOMHooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('ReactDOMHooks', () => {
expect(container.textContent).toBe('1');
expect(container2.textContent).toBe('');
expect(container3.textContent).toBe('');
Scheduler.flushAll();
Scheduler.unstable_flushAll();
expect(container.textContent).toBe('1');
expect(container2.textContent).toBe('2');
expect(container3.textContent).toBe('3');
Expand All @@ -69,7 +69,7 @@ describe('ReactDOMHooks', () => {
expect(container.textContent).toBe('2');
expect(container2.textContent).toBe('2'); // Not flushed yet
expect(container3.textContent).toBe('3'); // Not flushed yet
Scheduler.flushAll();
Scheduler.unstable_flushAll();
expect(container.textContent).toBe('2');
expect(container2.textContent).toBe('4');
expect(container3.textContent).toBe('6');
Expand Down Expand Up @@ -137,14 +137,14 @@ describe('ReactDOMHooks', () => {
const root = ReactDOM.unstable_createRoot(container);
root.render(<Example inputRef={inputRef} labelRef={labelRef} />);

Scheduler.flushAll();
Scheduler.unstable_flushAll();

inputRef.current.value = 'abc';
inputRef.current.dispatchEvent(
new Event('input', {bubbles: true, cancelable: true}),
);

Scheduler.flushAll();
Scheduler.unstable_flushAll();

expect(labelRef.current.innerHTML).toBe('abc');
});
Expand Down
Loading

0 comments on commit a0161d9

Please sign in to comment.