@samitouri / QOS-React-2 / commits / 8e3cd8ab1e

Debounce inspect-element polling

Brian Vaughn committed Jun 18, 2019 at 07:41 UTC 8e3cd8ab1e857ccc513c0516f4cceb0ad6847be3
2 files changed +15 -4
src/__tests__/inspectedElementContext-test.js
+1 -1
@@ -613,7 +613,7 @@ describe('InspectedElementContext', () => {
613
614 TestUtils.act(() => {
615 inspectedElement = null;
616 - jest.runOnlyPendingTimers();
616 + jest.advanceTimersByTime(1000);
617 expect(inspectedElement).not.toBeNull();
618 expect(inspectedElement).toMatchSnapshot('4: update inspected element');
619 });
src/devtools/views/Components/InspectedElementContext.js
+14 -3
@@ -236,10 +236,21 @@ function InspectedElementContextController({ children }: Props) {
236 // Update the $r variable.
237 bridge.send('selectElement', { id: selectedElementID, rendererID });
238
239 - const onInspectedElement = ({ id }: InspectedElementPayload) => {
239 + const onInspectedElement = (data: InspectedElementPayload) => {
240 // If this is the element we requested, wait a little bit and then ask for another update.
241 - if (id === selectedElementID) {
242 - timeoutID = setTimeout(sendRequest, 1000);
241 + if (data.id === selectedElementID) {
242 + switch (data.type) {
243 + case 'no-change':
244 + case 'full-data':
245 + case 'hydrated-path':
246 + if (timeoutID !== null) {
247 + clearTimeout(timeoutID);
248 + }
249 + timeoutID = setTimeout(sendRequest, 1000);
250 + break;
251 + default:
252 + break;
253 + }
254 }
255 };
256