autoformat

feat/vaults
Tomáš Mládek 2021-12-12 14:38:34 +01:00
parent aaa511fc3f
commit bdbf46549d
1 changed files with 36 additions and 36 deletions

View File

@ -1,41 +1,41 @@
import { createHashHistory } from "history";
import type { HistorySource } from "svelte-navigator";
export default function(): HistorySource {
const history = createHashHistory({window});
let listeners = [];
export default function (): HistorySource {
const history = createHashHistory({ window });
let listeners = [];
history.listen(location => {
if (history.action === "POP") {
listeners.forEach(listener => listener(location));
}
});
history.listen((location) => {
if (history.action === "POP") {
listeners.forEach((listener) => listener(location));
}
});
return {
get location() {
return history.location as any;
},
addEventListener(name, handler) {
if (name !== "popstate") return;
listeners.push(handler);
},
removeEventListener(name, handler) {
if (name !== "popstate") return;
listeners = listeners.filter(fn => fn !== handler);
},
history: {
get state() {
return history.location.state;
},
pushState(state, title, uri) {
history.push(uri, state);
},
replaceState(state, title, uri) {
history.replace(uri, state);
},
go(to) {
history.go(to);
},
},
};
}
return {
get location() {
return history.location as any;
},
addEventListener(name, handler) {
if (name !== "popstate") return;
listeners.push(handler);
},
removeEventListener(name, handler) {
if (name !== "popstate") return;
listeners = listeners.filter((fn) => fn !== handler);
},
history: {
get state() {
return history.location.state;
},
pushState(state, title, uri) {
history.push(uri, state);
},
replaceState(state, title, uri) {
history.replace(uri, state);
},
go(to) {
history.go(to);
},
},
};
}