|
8 | 8 | */
|
9 | 9 |
|
10 | 10 | import EventEmitter from '../events';
|
11 |
| -import throttle from 'lodash.throttle'; |
12 | 11 | import {
|
13 | 12 | SESSION_STORAGE_LAST_SELECTION_KEY,
|
14 | 13 | SESSION_STORAGE_RELOAD_AND_PROFILE_KEY,
|
@@ -483,7 +482,13 @@ export default class Agent extends EventEmitter<{
|
483 | 482 | this._persistedSelection = null;
|
484 | 483 | this._persistedSelectionMatch = null;
|
485 | 484 | renderer.setTrackedPath(null);
|
486 |
| - this._throttledPersistSelection(rendererID, id); |
| 485 | + // Throttle persisting the selection. |
| 486 | + this._lastSelectedElementID = id; |
| 487 | + this._lastSelectedRendererID = rendererID; |
| 488 | + if (!this._persistSelectionTimerScheduled) { |
| 489 | + this._persistSelectionTimerScheduled = true; |
| 490 | + setTimeout(this._persistSelection, 1000); |
| 491 | + } |
487 | 492 | }
|
488 | 493 |
|
489 | 494 | // TODO: If there was a way to change the selected DOM element
|
@@ -893,22 +898,25 @@ export default class Agent extends EventEmitter<{
|
893 | 898 | this._bridge.send('unsupportedRendererVersion', rendererID);
|
894 | 899 | }
|
895 | 900 |
|
896 |
| - _throttledPersistSelection: any = throttle( |
897 |
| - (rendererID: number, id: number) => { |
898 |
| - // This is throttled, so both renderer and selected ID |
899 |
| - // might not be available by the time we read them. |
900 |
| - // This is why we need the defensive checks here. |
901 |
| - const renderer = this._rendererInterfaces[rendererID]; |
902 |
| - const path = renderer != null ? renderer.getPathForElement(id) : null; |
903 |
| - if (path !== null) { |
904 |
| - sessionStorageSetItem( |
905 |
| - SESSION_STORAGE_LAST_SELECTION_KEY, |
906 |
| - JSON.stringify(({rendererID, path}: PersistedSelection)), |
907 |
| - ); |
908 |
| - } else { |
909 |
| - sessionStorageRemoveItem(SESSION_STORAGE_LAST_SELECTION_KEY); |
910 |
| - } |
911 |
| - }, |
912 |
| - 1000, |
913 |
| - ); |
| 901 | + _persistSelectionTimerScheduled: boolean = false; |
| 902 | + _lastSelectedRendererID: number = -1; |
| 903 | + _lastSelectedElementID: number = -1; |
| 904 | + _persistSelection: any = () => { |
| 905 | + this._persistSelectionTimerScheduled = false; |
| 906 | + const rendererID = this._lastSelectedRendererID; |
| 907 | + const id = this._lastSelectedElementID; |
| 908 | + // This is throttled, so both renderer and selected ID |
| 909 | + // might not be available by the time we read them. |
| 910 | + // This is why we need the defensive checks here. |
| 911 | + const renderer = this._rendererInterfaces[rendererID]; |
| 912 | + const path = renderer != null ? renderer.getPathForElement(id) : null; |
| 913 | + if (path !== null) { |
| 914 | + sessionStorageSetItem( |
| 915 | + SESSION_STORAGE_LAST_SELECTION_KEY, |
| 916 | + JSON.stringify(({rendererID, path}: PersistedSelection)), |
| 917 | + ); |
| 918 | + } else { |
| 919 | + sessionStorageRemoveItem(SESSION_STORAGE_LAST_SELECTION_KEY); |
| 920 | + } |
| 921 | + }; |
914 | 922 | }
|
0 commit comments