Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private restoreActive(): void {
let expectedActiveIndex = getActiveHistoryEntryIndex(this.snapshot);
let trackedActiveIndex = getActiveHistoryEntryIndex(this.tracked);
if (trackedActiveIndex < expectedActiveIndex) {
history.forward();
} else if (trackedActiveIndex > expectedActiveIndex) {
history.back();
} else {
this.completeRestoration();
}
}
private restoreEntries(): void {
let expected = this.snapshot;
let tracked = this.tracked;
let {entries: expectedEntries} = expected;
let {entries: trackedEntries} = tracked;
let lastExpectedIndex = expectedEntries.length - 1;
let lastTrackedIndex = trackedEntries.length - 1;
let trackedActiveIndex = getActiveHistoryEntryIndex(tracked);
let minLength = Math.min(expectedEntries.length, trackedEntries.length);
let firstMismatchedIndex = 0;
for (
firstMismatchedIndex;
firstMismatchedIndex < minLength;
firstMismatchedIndex++
) {
let expectedEntry = expectedEntries[firstMismatchedIndex];
let trackedEntry = trackedEntries[firstMismatchedIndex];
if (!isHistoryEntryEqual(expectedEntry, trackedEntry)) {
break;
}
private pushEntry({
id,
ref,
data,
}: BrowserHistoryEntry): BrowserHistorySnapshot {
let tracked = this.tracked;
let {entries} = tracked;
let activeIndex = getActiveHistoryEntryIndex(tracked);
let snapshot: BrowserHistorySnapshot = {
entries: [...entries.slice(0, activeIndex + 1), {id, ref, data}],
active: id,
};
this.tracked = snapshot;
let href = this.getHRefByRef(ref);
try {
history.pushState({id, data}, '', href);
} catch (error) {
history.pushState({id}, '', href);
}