make pushUrl silent again

This commit is contained in:
Bruno Windels 2020-10-09 16:58:53 +02:00
parent 41c1c9a6c3
commit 4ae622bdd3

View File

@ -20,9 +20,14 @@ export class History extends BaseObservableValue {
constructor() { constructor() {
super(); super();
this._boundOnHashChange = null; this._boundOnHashChange = null;
this._expectSetEcho = false;
} }
_onHashChange() { _onHashChange() {
if (this._expectSetEcho) {
this._expectSetEcho = false;
return;
}
this.emit(this.get()); this.emit(this.get());
} }
@ -37,7 +42,19 @@ export class History extends BaseObservableValue {
} }
pushUrl(url) { pushUrl(url) {
document.location.hash = this.urlAsPath(url); const hash = this.urlAsPath(url);
// important to check before we expect an echo
// as setting the hash to it's current value doesn't
// trigger onhashchange
if (hash === document.location.hash) {
return;
}
// this operation is silent,
// so avoid emitting on echo hashchange event
if (this._boundOnHashChange) {
this._expectSetEcho = true;
}
document.location.hash = hash;
} }
urlAsPath(url) { urlAsPath(url) {