billstclair/elm-localstorage/4.0.2

NOTE: this package is not compatible with Elm 0.19.1

Published as the billstclair/elm-localstorage package at elm-lang.org

I've built many projects that use JavaScript's localStorage mechanism for persistent storage. Enough to know the features I need. This package makes that experience available to the community.

Some ideas here are cribbed from Paul Statezny's knledg/elm-local-storage-ports, but his package is not in the Elm repository. This one also provides an API-compatible pure Elm version that you can use from elm reactor during development (with only session persistence, but that suffices for development).

See the example directory for use of both simulated ports, which work in elm reactor, and real ports.

The example is live at lisplog.org/localstorage.

To use the real ports with your own application, create the five ports, getItem, setItem, clear, listKeys, and receiveItem, as is done in example/PortExample.elm. Copy the site directory, inluding its js subdirectory. In index.html, change the <title>, and change PortExample to the name of your top-level application module. If you want to use different names for the ports, you can change those here as well.

Finally, compile your application Elm file into site/index.js:

cd ...
elm make MyApplication.elm --output site/index.js

Happy hacking!

Bill St. Clair
24 March, 2018