diff options
Diffstat (limited to 'server/sonar-web/src/main/js/helpers/cookies.ts')
-rw-r--r-- | server/sonar-web/src/main/js/helpers/cookies.ts | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/server/sonar-web/src/main/js/helpers/cookies.ts b/server/sonar-web/src/main/js/helpers/cookies.ts index b3442b76703..97bec175aab 100644 --- a/server/sonar-web/src/main/js/helpers/cookies.ts +++ b/server/sonar-web/src/main/js/helpers/cookies.ts @@ -17,20 +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. */ -let cookies: { [key: string]: string }; - -export function getCookie(name: string): string | undefined { - if (cookies) { - return cookies[name]; - } - - const rawCookies = document.cookie.split('; '); - cookies = {}; +import { memoize } from 'lodash'; +const parseCookies = memoize((documentCookie: string): { [key: string]: string } => { + const rawCookies = documentCookie.split('; '); + const cookies: { [key: string]: string } = {}; rawCookies.forEach(candidate => { const [key, value] = candidate.split('='); cookies[key] = value; }); + return cookies; +}); - return cookies[name]; +export function getCookie(name: string): string | undefined { + return parseCookies(document.cookie)[name]; } |