Skip to content

Commit 9837146

Browse files
authored
Fix storage
Signed-off-by: Faisal N <contact@faisaln.com>
1 parent 16d2b81 commit 9837146

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/modules/storage.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Storage {
88
let temp = this.object;
99
temp[key] = value;
1010
localStorage.setItem(this.id, JSON.stringify(temp));
11-
setCookie(this.id, JSON.stringify(temp), 7);
11+
this.syncWithCookie();
1212
return this;
1313
}
1414

@@ -24,7 +24,7 @@ class Storage {
2424
let temp = this.object;
2525
delete temp[key];
2626
localStorage.setItem(this.id, JSON.stringify(temp));
27-
setCookie(this.id, JSON.stringify(temp), 7);
27+
this.syncWithCookie();
2828
return this;
2929
}
3030

@@ -38,8 +38,11 @@ class Storage {
3838
}
3939

4040
syncWithCookie() {
41+
const localData = localStorage.getItem(this.id);
4142
const cookieData = getCookie(this.id);
42-
if (cookieData) {
43+
if (localData && cookieData && localData !== cookieData) {
44+
setCookie(this.id, localData, 7);
45+
} else if (!localData && cookieData) {
4346
localStorage.setItem(this.id, cookieData);
4447
}
4548
}
@@ -68,4 +71,4 @@ function getCookie(name) {
6871

6972
const storageInstance = new Storage("virtual-falcons");
7073

71-
export default storageInstance;
74+
export default storageInstance;

0 commit comments

Comments
 (0)