From 15d4611e619fe343810f5ff5f67e58c8e0b3e3d0 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 9 Dec 2016 10:59:31 +0100 Subject: [PATCH] add flow annotations in RecentHistory --- .../components/nav/component/RecentHistory.js | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js b/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js index e7dc3f06f09..d5bb1b2d587 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js +++ b/server/sonar-web/src/main/js/app/components/nav/component/RecentHistory.js @@ -17,11 +17,18 @@ * 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); -- 2.39.5