Skip to content

Commit 7b8d39e

Browse files
committed
Add usage example to Web.Storage.Storage. Closes #5.
1 parent 0e44768 commit 7b8d39e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Web/Storage/Storage.purs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
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+
-- | main :: Effect Unit
7+
-- | main = do
8+
-- | w <- window
9+
-- | s <- localStorage w
10+
-- | setItem "this-is-my-key" "Here is my value." s
11+
-- | v <- getItem "this-is-my-key" s
12+
-- | logShow v
13+
-- |
14+
-- | removeItem "this-is-my-key" s
15+
-- | v' <- getItem "this-is-my-key" s
16+
-- | log "It is gone!"
17+
-- | logShow v'
18+
-- |
19+
-- | clear s
20+
-- | ```
21+
322
module Web.Storage.Storage
423
( Storage
524
, length
@@ -33,7 +52,8 @@ foreign import _getItem :: String -> Storage -> Effect (Nullable String)
3352
getItem :: String -> Storage -> Effect (Maybe String)
3453
getItem s = map toMaybe <<< _getItem s
3554

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.
55+
-- | Given a key name and a value (in that order), adds that key to the
56+
-- | storage or updates its value if it already exists.
3757
foreign import setItem :: String -> String -> Storage -> Effect Unit
3858

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

0 commit comments

Comments
 (0)