perf(docs-infra): avoid unnecessary JSON parsing in `ScrollService` (#29658)

PR Close #29658
This commit is contained in:
George Kalpakas 2019-04-02 13:37:56 +03:00 committed by Jason Aden
parent 19081dc9a3
commit 53be333439
1 changed files with 5 additions and 2 deletions

View File

@ -171,13 +171,16 @@ export class ScrollService {
if (this.supportManualScrollRestoration) {
const currentScrollPosition = this.viewportScroller.getScrollPosition();
this.location.replaceState(this.location.path(true), undefined, {scrollPosition: currentScrollPosition});
window.sessionStorage.setItem('scrollPosition', currentScrollPosition.toString());
window.sessionStorage.setItem('scrollPosition', currentScrollPosition.join(','));
}
}
getStoredScrollPosition(): ScrollPosition | null {
const position = window.sessionStorage.getItem('scrollPosition');
return position ? JSON.parse('[' + position + ']') : null;
if (!position) { return null; }
const [x, y] = position.split(',');
return [+x, +y];
}
removeStoredScrollPosition() {