Skip to content

Commit

Permalink
perf improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
pooyaj committed Oct 24, 2022
1 parent 131e8f5 commit 3358219
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/browser/src/core/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class Store {
const ONE_YEAR = 365

export class Cookie extends Store {
static _available: boolean | undefined
static available(): boolean {
if (Cookie._available !== undefined) {
return Cookie._available
}

let cookieEnabled = window.navigator.cookieEnabled

if (!cookieEnabled) {
Expand All @@ -68,6 +73,8 @@ export class Cookie extends Store {
jar.remove('ajs:cookies')
}

Cookie._available = cookieEnabled

return cookieEnabled
}

Expand Down Expand Up @@ -137,13 +144,21 @@ export class Cookie extends Store {
}

export class LocalStorage extends Store {
static _available: boolean | undefined

static available(): boolean {
if (LocalStorage._available !== undefined) {
return LocalStorage._available
}

const test = 'test'
try {
localStorage.setItem(test, test)
localStorage.removeItem(test)
LocalStorage._available = true
return true
} catch (e) {
LocalStorage._available = false
return false
}
}
Expand Down

0 comments on commit 3358219

Please sign in to comment.