File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
6972const storageInstance = new Storage ( "virtual-falcons" ) ;
7073
71- export default storageInstance ;
74+ export default storageInstance ;
You can’t perform that action at this time.
0 commit comments