Debounce inspect-element polling

This commit is contained in:
Brian Vaughn 2019-06-18 07:41:30 -07:00
parent 6c03f6abbd
commit 8e3cd8ab1e
2 changed files with 15 additions and 4 deletions

View File

@ -613,7 +613,7 @@ describe('InspectedElementContext', () => {
TestUtils.act(() => {
inspectedElement = null;
jest.runOnlyPendingTimers();
jest.advanceTimersByTime(1000);
expect(inspectedElement).not.toBeNull();
expect(inspectedElement).toMatchSnapshot('4: update inspected element');
});

View File

@ -236,10 +236,21 @@ function InspectedElementContextController({ children }: Props) {
// Update the $r variable.
bridge.send('selectElement', { id: selectedElementID, rendererID });
const onInspectedElement = ({ id }: InspectedElementPayload) => {
const onInspectedElement = (data: InspectedElementPayload) => {
// If this is the element we requested, wait a little bit and then ask for another update.
if (id === selectedElementID) {
timeoutID = setTimeout(sendRequest, 1000);
if (data.id === selectedElementID) {
switch (data.type) {
case 'no-change':
case 'full-data':
case 'hydrated-path':
if (timeoutID !== null) {
clearTimeout(timeoutID);
}
timeoutID = setTimeout(sendRequest, 1000);
break;
default:
break;
}
}
};