better-state
Advanced tools
Comparing version 1.1.7 to 1.1.9
22
app.js
@@ -10,2 +10,3 @@ class App { | ||
#id = 0; | ||
#scrollerDelay = null; | ||
#lastPop = null; | ||
@@ -15,3 +16,3 @@ verbose = false; | ||
constructor() { | ||
console.log("better-state 1.1.7"); | ||
console.log("better-state 1.1.9"); | ||
this.#index = isNaN(history.state?.index) ? 0 : history.state.index; | ||
@@ -29,7 +30,11 @@ this.#history[this.#index] = history.state || { | ||
try { | ||
this.#history[this.#index].state.scrollX = window.scrollX; | ||
this.#history[this.#index].state.scrollY = window.scrollY; | ||
history.replaceState(this.#history[this.#index], "", location.pathname); | ||
if (this.#scrollerDelay) window.clearTimeout(this.#scrollerDelay); | ||
this.#scrollerDelay = window.setTimeout(() => { | ||
this.#history[this.#index].state.scrollX = window.scrollX; | ||
this.#history[this.#index].state.scrollY = window.scrollY; | ||
history.replaceState(this.#history[this.#index], "", location.pathname); | ||
//console.log(window.scrollY); | ||
}, 333); | ||
} catch (err) { | ||
console.error(err); | ||
if (this.verbose) console.error(err); | ||
} | ||
@@ -103,3 +108,8 @@ }); | ||
get state() { | ||
return this.#history[this.#index]?.state ?? null; | ||
try { | ||
return this.#history[this.#index]?.state ?? null; | ||
} catch (err) { | ||
if (this.verbose) console.error(err); | ||
return null; | ||
} | ||
} | ||
@@ -106,0 +116,0 @@ |
{ | ||
"name": "better-state", | ||
"version": "1.1.7", | ||
"version": "1.1.9", | ||
"description": "A small wrapper that encapsulates history.pushState and window.onpopstate and offers extra features - including 'No Going Back'", | ||
@@ -5,0 +5,0 @@ "main": "app.js", |
15280
144