billstclair/elm-localstorage/1.1.0

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 prexix ++ ".".

(Key -> Cmd msg)
-> (( Key, Value ) -> Cmd msg)
-> (String -> Cmd 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.

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.