miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Storage

Contents

Description

Overview

Miso.Storage wraps the browser's Web Storage API, providing access to both localStorage and sessionStorage through symmetric IO functions.

Both stores map MisoString keys to MisoString values (the Web Storage API only persists strings). Reads return Maybe MisoStringNothing when the key is absent.

  • localStorage — persists across browser sessions until explicitly cleared.
  • sessionStorage — persists only for the lifetime of the current browser tab/session; cleared automatically when the tab is closed.

Quick start

import Miso.Storage
import Miso.String (ms)

-- Persist a preference
saveTheme :: MisoString -> IO ()
saveTheme theme = setLocalStorage "theme" theme

-- Restore it on startup
loadTheme :: IO (Maybe MisoString)
loadTheme = getLocalStorage "theme"

-- Session-scoped token (cleared when tab closes)
saveToken :: MisoString -> IO ()
saveToken tok = setSessionStorage "auth_token" tok

API groups

See also

Synopsis

Local

getLocalStorage Source #

Arguments

:: MisoString

Storage key to look up

-> IO (Maybe MisoString) 

Retrieves a value stored under the given key in local storage.

setLocalStorage Source #

Arguments

:: MisoString

Storage key to set

-> MisoString

Value to store

-> IO () 

Sets the value of a key in local storage.

setLocalStorage key value sets the value of key to value.

removeLocalStorage Source #

Arguments

:: MisoString

Storage key to remove

-> IO () 

Removes an item from local storage.

removeLocalStorage key removes the value of key.

clearLocalStorage :: IO () Source #

Clears local storage.

clearLocalStorage removes all values from local storage.

localStorageLength :: IO Int Source #

Returns the number of items in local storage.

localStorageLength returns the count of items in local storage

Session

getSessionStorage Source #

Arguments

:: MisoString

Storage key to look up

-> IO (Maybe MisoString) 

Retrieves a value stored under the given key in session storage.

setSessionStorage Source #

Arguments

:: MisoString

Storage key to set

-> MisoString

Value to store

-> IO () 

Sets the value of a key in session storage.

setSessionStorage key value sets the value of key to value.

removeSessionStorage Source #

Arguments

:: MisoString

Storage key to remove

-> IO () 

Removes an item from session storage.

removeSessionStorage key removes the value of key.

clearSessionStorage :: IO () Source #

Clears session storage.

clearSessionStorage removes all values from session storage.

sessionStorageLength :: IO Int Source #

Returns the number of items in session storage.

sessionStorageLength returns the count of items in session storage