]> source.dussan.org Git - sonarqube.git/commitdiff
add flow annotations in RecentHistory
authorStas Vilchik <vilchiks@gmail.com>
Fri, 9 Dec 2016 09:59:31 +0000 (10:59 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 9 Dec 2016 13:28:10 +0000 (14:28 +0100)
server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js

index e7dc3f06f09276e6c9304276530f690a95a5954c..d5bb1b2d5872aa88e9280273dec26292a3a7750c 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+// @flow
 const STORAGE_KEY = 'sonar_recent_history';
 const HISTORY_LIMIT = 10;
 
+type History = Array<{
+  key: string,
+  name: string,
+  icon: string
+}>;
+
 export default class RecentHistory {
-  static get () {
+  static get (): History {
     let history = localStorage.getItem(STORAGE_KEY);
     if (history == null) {
       history = [];
@@ -36,27 +43,24 @@ export default class RecentHistory {
     return history;
   }
 
-  static set (newHistory) {
+  static set (newHistory: History): void {
     localStorage.setItem(STORAGE_KEY, JSON.stringify(newHistory));
   }
 
-  static clear () {
+  static clear (): void {
     localStorage.removeItem(STORAGE_KEY);
   }
 
-  static add (componentKey, componentName, icon) {
+  static add (componentKey: string, componentName: string, icon: string): void {
     const sonarHistory = RecentHistory.get();
-
-    if (componentKey) {
-      const newEntry = { key: componentKey, name: componentName, icon };
-      let newHistory = sonarHistory.filter(entry => entry.key !== newEntry.key);
-      newHistory.unshift(newEntry);
-      newHistory = newHistory.slice(0, HISTORY_LIMIT);
-      RecentHistory.set(newHistory);
-    }
+    const newEntry = { key: componentKey, name: componentName, icon };
+    let newHistory = sonarHistory.filter(entry => entry.key !== newEntry.key);
+    newHistory.unshift(newEntry);
+    newHistory = newHistory.slice(0, HISTORY_LIMIT);
+    RecentHistory.set(newHistory);
   }
 
-  static remove (componentKey) {
+  static remove (componentKey: string): void {
     const history = RecentHistory.get();
     const newHistory = history.filter(entry => entry.key !== componentKey);
     RecentHistory.set(newHistory);