The PortFunnelLocalStorage uses the JavaScript localStorage facility to persistently store key/value pairs.
It is a billstclair/elm-port-funnel PortFunnel funnel.
A Response is used to return values for Get and ListKeys.
Our internal state.
A convenience type for keys in the store. Same as String.
A convenience type for prefixes. Same as String.
A convenience type for values in the store. Same as Json.Encode.Value.
A convenience type for labels in the store. Same as Maybe String.
PortFunnel.FunnelSpecThe name of this funnel: "LocalStorage".
Our module descriptor.
Responsible for sending a CmdResponse back through the port.
This funnel doesn't initiate any sends, so this function always returns Cmd.none.
StateThe initial state.
The Prefix arg (plus a period, if non-blank) is prepended to all
keys sent to the backend, and removed from keys returned. It basically
give you a namespace in local storage, and usually matches your
application name. It allows multiple different Elm applications to be
served by the same domain without stepping on each other's state.
The state also stores a Dict, which acts as the backing store for simulation,
and a flag saying whether the JavaScript code has sent its "I'm loaded" message
(see isLoaded).
Message out the Cmd PortSend a Message through a Cmd port.
Note that this send function requires that you pass state,
but it is read-only, so you don't need to update your Model state
on return.
The Message type is opaque, so there are functions to create the four messages
you may pass to send.
Return a Message to get a value from local storage.
Return a Message to get a labeled value from local storage.
Sometimes the Key alone isn't enough to mark your intention with
the return value. In this case you can label the return with a string
you can recognize. It will be returned in the label property of the
GetResponse.
Return a Message to put a value into local storage.
Nothing for the value means to remove the key.
Return a Message to list all keys beginning with a prefix.
Return a Message to list all keys beginning with a prefix.
Sometimes the Prefix alone isn't enough to mark your intention with
the return value. In this case you can label the return with a string
you can recognize. It will be returned in the label property of the
ListKeysResponse.
Return a message to remove all keys beginning with a prefix.
A prefix of "" means to remove all keys.
Convert a Message to a nice-looking human-readable string.
Convert a Message to the same JSON string that gets sent
over the wire to the JS code.
Make a simulated Cmd port.
Returns true if a Startup message has been processed.
This is sent by the port code after it has initialized. Your code can use this to decide whether to use your real outgoing port or the one created by makeSimulatedCmdPort.
Turn a Message into a GenericMessage.
Turn a GenericMessage into a Message.
An opaque type that represents a message to send to or receive from the JS code.
There are a number of internal messages, but the ones you can use are created by
get,put,listkeys, andclear.