Просмотр исходного кода

create method for removing old user cache

yusuketk 5 лет назад
Родитель
Сommit
2865ce3c26
1 измененных файлов с 8 добавлено и 19 удалено
  1. 8 19
      src/client/js/services/AppContainer.js

+ 8 - 19
src/client/js/services/AppContainer.js

@@ -72,10 +72,10 @@ export default class AppContainer extends Container {
     const userlang = body.dataset.userlang;
     this.i18n = i18nFactory(userlang);
 
-    this.users = [];
-    this.userByName = {};
-    this.userById = {};
-    this.recoverData();
+    if (this.isLoggedin) {
+      // remove old user cache
+      this.removeOldUserCache();
+    }
 
     this.containerInstances = {};
     this.componentInstances = {};
@@ -94,6 +94,7 @@ export default class AppContainer extends Container {
       delete: this.apiv3Delete.bind(this),
     };
 
+    this.removeOldUserCache = this.removeOldUserCache.bind(this);
     this.openPageCreateModal = this.openPageCreateModal.bind(this);
     this.closePageCreateModal = this.closePageCreateModal.bind(this);
   }
@@ -278,23 +279,11 @@ export default class AppContainer extends Container {
     return emojiStrategy;
   }
 
-  recoverData() {
-    const keys = [
-      'userByName',
-      'userById',
-      'users',
-    ];
+  removeOldUserCache() {
+    const keys = ['userByName', 'userById', 'users', 'lastFetched'];
 
     keys.forEach((key) => {
-      const keyContent = window.localStorage[key];
-      if (keyContent) {
-        try {
-          this[key] = JSON.parse(keyContent);
-        }
-        catch (e) {
-          window.localStorage.removeItem(key);
-        }
-      }
+      window.localStorage.removeItem(key);
     });
   }