varasto

Typed access to the Web Storage API.

Types

An error that occurs when reading.

pub type ReadError {
  NotFound
  DecodeError(err: json.DecodeError)
}

Constructors

  • NotFound

    A value was not found with the given key.

  • DecodeError(err: json.DecodeError)

    The found value could not be decoded.

pub opaque type TypedStorage(a)

Functions

pub fn clear(storage: TypedStorage(a)) -> Nil

Clear the whole storage.

NOTE! This will clear the whole storage, not just values you have set.

pub fn get(
  storage: TypedStorage(a),
  key: String,
) -> Result(a, ReadError)

Get a value from the storage.

pub fn new(
  raw_storage: Storage,
  reader: fn(Dynamic) -> Result(a, List(DecodeError)),
  writer: fn(a) -> Json,
) -> TypedStorage(a)

Create a new TypedStorage.

pub fn remove(storage: TypedStorage(a), key: String) -> Nil

Remove a value from the storage.

pub fn set(
  storage: TypedStorage(a),
  key: String,
  value: a,
) -> Result(Nil, Nil)

Set a value in the storage.

Search Document