Debounce inspect-element polling
This commit is contained in:
parent
6c03f6abbd
commit
8e3cd8ab1e
|
@ -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');
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue