Skip to content

Commit

Permalink
use document focus
Browse files Browse the repository at this point in the history
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

thejavierCO committed Aug 7, 2024
1 parent 3d38a76 commit f2d16e2
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/js/store.js
Original file line number Diff line number Diff line change
@@ -75,12 +75,7 @@ export class dbStore extends EventTarget {

export class localStorageDb {
constructor() {
this.id = "";
this.keys = [];
if (this.id == "") {
this.id = uuidv4();
sessionStorage.setItem("userId", this.id)
}
this.storageChange(({ key, newValue }) => {
if (key != null) this.keys.forEach(({ key: item, start }) => {
if (key == item) start(newValue)
@@ -112,7 +107,7 @@ export class dbStoreUseLocalStorage extends dbStore {
this.keysStore.use("store", (data) => {
if (typeof data == "string") this.store.update(_ => JSON.parse(data))
else if (typeof data == "undefined") this.store.update(_ => ([]));
else if (Array.isArray(data)) localStorage.setItem("store", JSON.stringify(data));
else if (Array.isArray(data) && document.hasFocus()) localStorage.setItem("store", JSON.stringify(data));
else if (data == null) localStorage.setItem("store", "[]")
})
this.Destroy = this.store.subscribe((data) => this.keysStore.get("store").start(data))

0 comments on commit f2d16e2

Please sign in to comment.