From f61b65aa28b37570b149806308430a9863f4077a Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Tue, 28 Nov 2023 12:47:57 -0300 Subject: [PATCH] Polishing --- package.json | 2 +- src/storages/inLocalStorage/SplitsCacheInLocal.ts | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 8d5952ce..65b3d060 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "build": "npm run build:cjs && npm run build:esm", "build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types", "build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs", - "test": "jest --runInBand", + "test": "jest", "test:coverage": "jest --coverage", "all": "npm run check && npm run build && npm run test", "publish:rc": "npm run check && npm run test && npm run build && npm publish --tag rc", diff --git a/src/storages/inLocalStorage/SplitsCacheInLocal.ts b/src/storages/inLocalStorage/SplitsCacheInLocal.ts index 7511897a..acca8f3c 100644 --- a/src/storages/inLocalStorage/SplitsCacheInLocal.ts +++ b/src/storages/inLocalStorage/SplitsCacheInLocal.ts @@ -260,7 +260,7 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync { getNamesByFlagSets(flagSets: string[]): ISet[] { return flagSets.map(flagSet => { const flagSetKey = this.keys.buildFlagSetKey(flagSet); - let flagSetFromLocalStorage = localStorage.getItem(flagSetKey); + const flagSetFromLocalStorage = localStorage.getItem(flagSetKey); return new _Set(flagSetFromLocalStorage ? JSON.parse(flagSetFromLocalStorage) : []); }); @@ -275,10 +275,9 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync { const flagSetKey = this.keys.buildFlagSetKey(featureFlagSet); - let flagSetFromLocalStorage = localStorage.getItem(flagSetKey); - if (!flagSetFromLocalStorage) flagSetFromLocalStorage = '[]'; + const flagSetFromLocalStorage = localStorage.getItem(flagSetKey); - const flagSetCache = new _Set(JSON.parse(flagSetFromLocalStorage)); + const flagSetCache = new _Set(flagSetFromLocalStorage ? JSON.parse(flagSetFromLocalStorage) : []); flagSetCache.add(featureFlag.name); localStorage.setItem(flagSetKey, JSON.stringify(setToArray(flagSetCache))); @@ -296,7 +295,7 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync { private removeNames(flagSetName: string, featureFlagName: string) { const flagSetKey = this.keys.buildFlagSetKey(flagSetName); - let flagSetFromLocalStorage = localStorage.getItem(flagSetKey); + const flagSetFromLocalStorage = localStorage.getItem(flagSetKey); if (!flagSetFromLocalStorage) return;