MCPcopy Create free account
hub / github.com/anomalyco/opencode / localStorageDirect

Function localStorageDirect

packages/app/src/utils/persist.ts:425–464  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

423}
424
425function localStorageDirect(): SyncStorage {
426 const scope = "direct"
427 return {
428 getItem: (key) => {
429 const cached = cacheGet(key)
430 if (fallbackDisabled(scope)) return cached ?? null
431
432 const stored = (() => {
433 try {
434 return localStorage.getItem(key)
435 } catch {
436 fallbackSet(scope)
437 return null
438 }
439 })()
440 if (stored === null) return cached ?? null
441 cacheSet(key, stored)
442 return stored
443 },
444 setItem: (key, value) => {
445 if (fallbackDisabled(scope)) return
446 try {
447 if (write(localStorage, key, value)) return
448 } catch {
449 fallbackSet(scope)
450 return
451 }
452 fallbackSet(scope)
453 },
454 removeItem: (key) => {
455 cacheDelete(key)
456 if (fallbackDisabled(scope)) return
457 try {
458 localStorage.removeItem(key)
459 } catch {
460 fallbackSet(scope)
461 }
462 },
463 }
464}
465
466const DRAFT_PERSISTED_KEYS = ["prompt", "comments", "model-selection", "file-view", "layout"]
467

Callers 2

removePersistedFunction · 0.85
persistedFunction · 0.85

Calls 8

cacheGetFunction · 0.85
fallbackDisabledFunction · 0.85
fallbackSetFunction · 0.85
cacheSetFunction · 0.85
cacheDeleteFunction · 0.85
getItemMethod · 0.80
removeItemMethod · 0.80
writeFunction · 0.70

Tested by

no test coverage detected