|
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,12 @@ 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._persistSelectionTimer === null) { |
| 489 | + setTimeout(this._persistSelection, 1000); |
| 490 | + } |
487 | 491 | } |
488 | 492 |
|
489 | 493 | // TODO: If there was a way to change the selected DOM element |
@@ -893,22 +897,25 @@ export default class Agent extends EventEmitter<{ |
893 | 897 | this._bridge.send('unsupportedRendererVersion', rendererID); |
894 | 898 | } |
895 | 899 |
|
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 | | - ); |
| 900 | + _persistSelectionTimer: null = null; |
| 901 | + _lastSelectedRendererID: number = -1; |
| 902 | + _lastSelectedElementID: number = -1; |
| 903 | + _persistSelection: any = () => { |
| 904 | + this._persistSelectionTimer = null; |
| 905 | + const rendererID = this._lastSelectedRendererID; |
| 906 | + const id = this._lastSelectedElementID; |
| 907 | + // This is throttled, so both renderer and selected ID |
| 908 | + // might not be available by the time we read them. |
| 909 | + // This is why we need the defensive checks here. |
| 910 | + const renderer = this._rendererInterfaces[rendererID]; |
| 911 | + const path = renderer != null ? renderer.getPathForElement(id) : null; |
| 912 | + if (path !== null) { |
| 913 | + sessionStorageSetItem( |
| 914 | + SESSION_STORAGE_LAST_SELECTION_KEY, |
| 915 | + JSON.stringify(({rendererID, path}: PersistedSelection)), |
| 916 | + ); |
| 917 | + } else { |
| 918 | + sessionStorageRemoveItem(SESSION_STORAGE_LAST_SELECTION_KEY); |
| 919 | + } |
| 920 | + }; |
914 | 921 | } |
0 commit comments