hashchange: Extract function to update spectator_old_hash.

This commit is contained in:
Aman Agrawal 2021-11-17 12:24:17 +00:00 committed by Tim Abbott
parent a7badd726f
commit 6da34fd283
2 changed files with 10 additions and 6 deletions

View File

@ -30,6 +30,15 @@ export function set_hash_before_overlay(hash) {
state.hash_before_overlay = hash;
}
export function update_web_public_hash(hash) {
// Returns true if hash is web public compatible.
if (hash_util.is_spectator_compatible(hash)) {
state.spectator_old_hash = hash;
return true;
}
return false;
}
export function save_old_hash() {
state.old_hash = window.location.hash;

View File

@ -315,14 +315,9 @@ function do_hashchange_overlay(old_hash) {
function hashchanged(from_reload, e) {
const current_hash = window.location.hash;
const old_hash = e && (e.oldURL ? new URL(e.oldURL).hash : browser_history.old_hash());
const is_hash_web_public_compatible = browser_history.update_web_public_hash(current_hash);
const was_internal_change = browser_history.save_old_hash();
const is_hash_web_public_compatible = hash_util.is_spectator_compatible(current_hash);
if (is_hash_web_public_compatible) {
browser_history.state.spectator_old_hash = current_hash;
}
if (was_internal_change) {
return undefined;
}