Skip to content

Add usage example to Web.Storage.Storage. Closes #5. #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/Web/Storage/Storage.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
-- | This module defines a data type and various functions for interacting
-- | with the `Storage` interface of the Web Storage API.
-- | For example:
-- |
-- | ```purescript
-- | import Prelude
-- | import Effect (Effect)
-- | import Effect.Console (log, logShow)
-- | import Web.HTML (window)
-- | import Web.HTML.Window (localStorage)
-- | import Web.Storage.Storage (clear, getItem, removeItem, setItem)
-- |
-- | main :: Effect Unit
-- | main = do
-- | w <- window
-- | s <- localStorage w
-- | setItem "this-is-my-key" "Here is my value." s
-- | v <- getItem "this-is-my-key" s
-- | logShow v
-- |
-- | removeItem "this-is-my-key" s
-- | v' <- getItem "this-is-my-key" s
-- | log "It is gone!"
-- | logShow v'
-- |
-- | clear s
-- | ```

module Web.Storage.Storage
( Storage
, length
Expand Down Expand Up @@ -33,7 +59,8 @@ foreign import _getItem :: String -> Storage -> Effect (Nullable String)
getItem :: String -> Storage -> Effect (Maybe String)
getItem s = map toMaybe <<< _getItem s

-- | Given a key name and a value (in that order), adds that key to the storage or updates its value if it already exists.
-- | Given a key name and a value (in that order), adds that key to the
-- | storage or updates its value if it already exists.
foreign import setItem :: String -> String -> Storage -> Effect Unit

-- | Removes the given key from the storage.
Expand Down