varasto
Typed access to the Web Storage API.
Types
An error that occurs when reading.
pub type ReadError {
NotFound
DecodeError(err: json.DecodeError)
}
Constructors
-
NotFoundA value was not found with the given key.
-
DecodeError(err: json.DecodeError)The found value could not be decoded.
pub opaque type TypedStorage(a)
pub type WebStorage
Values
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 local() -> Result(WebStorage, Nil)
Get the LocalStorage handle.
Returns an error if the environment does not have LocalStorage available.
pub fn new(
raw_storage: WebStorage,
reader: decode.Decoder(a),
writer: fn(a) -> json.Json,
) -> TypedStorage(a)
Create a new TypedStorage.
pub fn remove(storage: TypedStorage(a), key: String) -> Nil
Remove a value from the storage.
pub fn session() -> Result(WebStorage, Nil)
Get the SessionStorage handle.
Returns an error if the environment does not have SessionStorage available.
pub fn set(
storage: TypedStorage(a),
key: String,
value: a,
) -> Result(Nil, Nil)
Set a value in the storage.
Returns an error if the writing quota was exceeded.