Skip to content

Commit a6cf21e

Browse files
authored
Merge pull request #8 from Rembane/add-usage-example
Add usage example to Web.Storage.Storage. Closes #5.
2 parents 0e44768 + b836a0b commit a6cf21e

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/Web/Storage/Storage.purs

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
-- | This module defines a data type and various functions for interacting
22
-- | with the `Storage` interface of the Web Storage API.
3+
-- | For example:
4+
-- |
5+
-- | ```purescript
6+
-- | import Prelude
7+
-- | import Effect (Effect)
8+
-- | import Effect.Console (log, logShow)
9+
-- | import Web.HTML (window)
10+
-- | import Web.HTML.Window (localStorage)
11+
-- | import Web.Storage.Storage (clear, getItem, removeItem, setItem)
12+
-- |
13+
-- | main :: Effect Unit
14+
-- | main = do
15+
-- | w <- window
16+
-- | s <- localStorage w
17+
-- | setItem "this-is-my-key" "Here is my value." s
18+
-- | v <- getItem "this-is-my-key" s
19+
-- | logShow v
20+
-- |
21+
-- | removeItem "this-is-my-key" s
22+
-- | v' <- getItem "this-is-my-key" s
23+
-- | log "It is gone!"
24+
-- | logShow v'
25+
-- |
26+
-- | clear s
27+
-- | ```
28+
329
module Web.Storage.Storage
430
( Storage
531
, length
@@ -33,7 +59,8 @@ foreign import _getItem :: String -> Storage -> Effect (Nullable String)
3359
getItem :: String -> Storage -> Effect (Maybe String)
3460
getItem s = map toMaybe <<< _getItem s
3561

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

3966
-- | Removes the given key from the storage.

0 commit comments

Comments
 (0)