billstclair/elm-localstorage/4.0.2

NOTE: this package is not compatible with Elm 0.19.1

LocalStorage

The 'LocalStorage' module does most of the work in using the JavaScript localStorage facility to persistently store key/value pairs.

Types

type LocalStorage msg

Opaque type. Returned by make and getPorts. Passed to the other functions.

Constructors

make : Ports msg -> String -> LocalStorage msg

Make a LocalStorage instance.

If prefix is not empty (""), will prefix all keys in JS localStorage with prefix ++ ".".

GetItemPort msg
-> SetItemPort msg
-> ClearPort msg
-> ListKeysPort msg
-> Ports msg

Create a Ports value, using what are usually your real Elm ports.

Functions

getItem : LocalStorage msg -> Key -> Cmd msg

Return a Cmd to fetch the value for the Key from LocalStorage.

setItem : LocalStorage msg -> Key -> Value -> Cmd msg

Return a Cmd to set the value for the Key to Value in LocalStorage.

clear : LocalStorage msg -> Cmd msg

Return a Cmd to clear all JS localStorage keys that begin with the prefix passed to make.

listKeys : LocalStorage msg -> String -> Cmd msg

Return a Cmd to list all JS localStorage keys that begin with the prefix passed to make followed by the String you pass here.

State accessors

getPorts : LocalStorage msg -> Ports msg

Return the Ports instance you passed to make or setPorts.

setPorts : Ports msg -> LocalStorage msg -> LocalStorage msg

Set the internal Ports value. Fetch it back with getPorts.

getPrefix : LocalStorage msg -> String

Get the prefix passed to make