The PortFunnelLocalStorage uses the JavaScript localStorage facility to persistently store key/value pairs.
It is a billstclair/elm-port-funnel PortFunnel funnel.
A MessageResponse is used to return values for Get and ListKeys.
Our internal state.
A convenience type for keys in the store. Same as 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 put a value into local storage.
Nothing for the value means to remove the key.
Return a message to remove all keys beginning with a prefix.
A prefix of "" means to remove all keys.
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.
Messages that can be sent/received to/from the JavaScript code.
Startupis received after the JS code loads. It sets theisLoadedflag in our state, and reportsNoResponse.Getis sent to request a read.Putis sent to request a write or received in response toGet. A value ofNothingmeans remove that key/value pair when sent or no value in the store when received.ListKeysis sent to request a list of keys.Keysis received in response toListKeys.Clearis sent to clear keys starting with the prefix. No response is sent.The
Simulate<Foo>messages are returned by the simulator and simulated by theprocessfunction (not exposed, except inside ofmoduleDesc).