Skip to content

Commit 4a0bca9

Browse files
committed
perf: remove localstorage function
1 parent 26ff506 commit 4a0bca9

1 file changed

Lines changed: 4 additions & 25 deletions

File tree

‎src/browser.ts‎

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ function formatArgs(
139139
*/
140140
const log = console.debug || console.log || (() => {})
141141

142-
// Use non-null assertion operator because
143-
// we handle the case where storage is undefined in load/save.
144-
const storage = localstorage()!
145-
146142
const defaultOptions: Omit<Required<DebugOptions>, 'color'> = {
147143
useColors: true,
148144

@@ -176,28 +172,11 @@ export function createDebug(
176172
)
177173
}
178174

179-
/**
180-
* Localstorage attempts to return the localstorage.
181-
*
182-
* This is necessary because safari throws
183-
* when a user disables cookies/localstorage
184-
* and you attempt to access it.
185-
*/
186-
function localstorage(): Storage | undefined {
187-
try {
188-
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
189-
// The Browser also has localStorage in the global context.
190-
return localStorage
191-
} catch {
192-
// Swallow
193-
// XXX (@Qix-) should we be logging these?
194-
}
195-
}
196-
197175
function load(): string {
198176
let r: string | null | undefined
199177
try {
200-
r = storage.getItem('debug') || storage.getItem('DEBUG')
178+
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context.
179+
r = localStorage.getItem('debug') || localStorage.getItem('DEBUG')
201180
} catch {
202181
// Swallow
203182
// XXX (@Qix-) should we be logging these?
@@ -214,9 +193,9 @@ function load(): string {
214193
function save(namespaces: string) {
215194
try {
216195
if (namespaces) {
217-
storage.setItem('debug', namespaces)
196+
localStorage.setItem('debug', namespaces)
218197
} else {
219-
storage.removeItem('debug')
198+
localStorage.removeItem('debug')
220199
}
221200
} catch {
222201
// Swallow

0 commit comments

Comments
 (0)