8
*/
9
10
import EventEmitter from '../events';
11
-import throttle from 'lodash.throttle';
11
import {
12
SESSION_STORAGE_LAST_SELECTION_KEY,
13
SESSION_STORAGE_RELOAD_AND_PROFILE_KEY,
482
this._persistedSelection = null;
483
this._persistedSelectionMatch = null;
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
+ }
492
}
493
494
// TODO: If there was a way to change the selected DOM element
898
this._bridge.send('unsupportedRendererVersion', rendererID);
899
}
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
+ };
922
}