Created
September 23, 2014 08:23
-
-
Save daveliepmann/cf923140702c8b1de301 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns localstorage) | |
(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
I think if I were doing this again today I would probably make the API either more like Clojure's (
assoc!
,get
,dissoc
) or use interop directly