billstclair/elm-localstorage/1.1.0

NOTE: this package is not compatible with Elm 0.19.1

LocalStorage.SharedTypes

Types for the LocalStorage module.

Types

type alias Key =
String

A convenience type for keys in the store. Same as String.

type alias Value =
Value

A convenience type for values in the store. Same as Json.Encode.Value.

= GetItemOperation
| SetItemOperation
| ClearOperation

The operation that caused your wrapper Msg to be sent.

For real ports, you'll only ever see GetItemOperation.

For simluated ports, you'll see the others as well, because you have to save the updated state.

type Ports msg
= Ports
{ getItem : Ports msg -> GetItemPort msg
, setItem : Ports msg -> SetItemPort msg
, clear : Ports msg -> ClearPort msg
, state : DictState
}

Wrap up your ports.

You'll usually create one of these with LocalStorage.realRealPorts or DictPorts.make.

Your update Msg will receive one, if you're using simulated ports.

type alias DictState =
Dict Key Value

A Dict that stores key/value pairs for the simulated ports.

Port Signatures

type alias GetItemPort msg =
Key -> Cmd msg

The required signature of your localStorage.getItem port.

type alias SetItemPort msg =
( Key, Value ) -> Cmd msg

The required signature of your localStorage.setItem port.

type alias ClearPort msg =
String -> Cmd msg

The required signature of your localStorage.clear port.

type alias ReceiveItemPort msg =
(( Key, Value ) -> msg) -> Sub msg

The required signature of your subscription to receive getItem values.

Constants

emptyDictState : DictState

Dict.empty