Skip to content

Instantly share code, notes, and snippets.

@mhuebert
Forked from daveliepmann/localstorage.cljs
Last active July 11, 2017 14:24
Show Gist options
  • Save mhuebert/1e13d47afa4ae599dd9615d53b8bbd27 to your computer and use it in GitHub Desktop.
Save mhuebert/1e13d47afa4ae599dd9615d53b8bbd27 to your computer and use it in GitHub Desktop.
HTML5 localStorage utility functions for ClojureScript. I find it makes for cleaner code when I wrap the native JS.
(ns localstorage)
#_[]
[1
2
3
4]
(defn set-item!
"Set `key' in browser's localStorage to `val`."
[key val]
(.setItem (.-localStorage js/window) key val))
(defn get-item
"Returns value of `key' from browser's localStorage."
[key]
(.getItem (.-localStorage js/window) key))
(defn remove-item!
"Remove the browser's localStorage value for the given `key`"
[key]
(.removeItem (.-localStorage js/window) key))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment