mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
use handleEvent in History so we don't have to bind
This commit is contained in:
parent
3e34ccb7e1
commit
fb273782bf
@ -17,14 +17,11 @@ limitations under the License.
|
|||||||
import {BaseObservableValue} from "../../../observable/ObservableValue.js";
|
import {BaseObservableValue} from "../../../observable/ObservableValue.js";
|
||||||
|
|
||||||
export class History extends BaseObservableValue {
|
export class History extends BaseObservableValue {
|
||||||
constructor() {
|
handleEvent(event) {
|
||||||
super();
|
if (event.type === "hashchange") {
|
||||||
this._boundOnHashChange = null;
|
this.emit(this.get());
|
||||||
}
|
this._storeHash(this.get());
|
||||||
|
}
|
||||||
_onHashChange() {
|
|
||||||
this.emit(this.get());
|
|
||||||
this._storeHash(this.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get() {
|
get() {
|
||||||
@ -60,13 +57,11 @@ export class History extends BaseObservableValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSubscribeFirst() {
|
onSubscribeFirst() {
|
||||||
this._boundOnHashChange = this._onHashChange.bind(this);
|
window.addEventListener('hashchange', this);
|
||||||
window.addEventListener('hashchange', this._boundOnHashChange);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onUnsubscribeLast() {
|
onUnsubscribeLast() {
|
||||||
window.removeEventListener('hashchange', this._boundOnHashChange);
|
window.removeEventListener('hashchange', this);
|
||||||
this._boundOnHashChange = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_storeHash(hash) {
|
_storeHash(hash) {
|
||||||
|
Loading…
Reference in New Issue
Block a user