Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 3d80e12

Browse files
Update documentation.
1 parent 0276323 commit 3d80e12

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/State.purs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
-- | Renderless components use `Control.Comonad.Store` wrapped around
2+
-- | their state type. This allows true renderless components, as the
3+
-- | `extract` function from `Store` serves as the render function.
4+
-- | However, this means that state update functions in the component's
5+
-- | eval function are not actually operating on the component's state
6+
-- | type; they're operating on the `Store` instead. This module contains
7+
-- | helper functions to make this work easy to do.
18
module Renderless.State where
29

310
import Prelude
@@ -14,25 +21,33 @@ import Data.Tuple (fst, snd)
1421
-- | use it as you ordinarily would.
1522
-- |
1623
-- | ```purescript
24+
-- | -- Old
25+
-- | st <- H.get
26+
-- | -- New
1727
-- | st <- getState
1828
-- | ```
1929
getState :: m s a. MonadState (Store s a) m => m s
2030
getState = map snd <<< pure <<< runStore =<< get
2131

22-
-- | You can also retrieve the render function, if you need to.
32+
-- | You can also retrieve the render function, if you need to,
33+
-- | from within the `Store` comonad.
2334
-- |
2435
-- | ```purescript
25-
-- | render <- getRender
36+
-- | renderFunction <- getRender
2637
-- | ```
2738
getRender :: m s a. MonadState (Store s a) m => m (s -> a)
2839
getRender = map fst <<< pure <<< runStore =<< get
2940

30-
-- | When you are modifying the state type, you need to again get into
31-
-- | `Store` and apply the function there. We can do this with `seeks`
32-
-- | from the module. You could use this directly, or write helpers to
41+
-- | When you are modifying the state type, you need to apply a function
42+
-- | (`state -> state`) within the `Store`. We can do this with the `seeks`
43+
-- | function from `Control.Comonad.Store`. You could use this directly, or
44+
-- | write helpers like the ones provided here.
3345
-- | make it feel more natural.
3446
-- |
3547
-- | ```purescript
48+
-- | -- without helpers
49+
-- | H.modify_ $ seeks $ \st -> st { field = newValue }
50+
-- | -- with helpers
3651
-- | modifyState_ \st -> st { field = newValue }
3752
-- | ```
3853
modifyState :: m s a. MonadState (Store s a) m => (s -> s) -> m (Store s a)
@@ -64,7 +79,8 @@ updateStore :: ∀ state html
6479
updateStore r f
6580
= store r <<< snd <<< runStore <<< seeks f
6681

67-
-- | You could also use these helper functions directly
82+
-- | You can also use these helper functions directly, rather than
83+
-- | pass `updateStore` to `modify`.
6884
-- |
6985
-- | ```purescript
7086
-- | newStore <- modifyStore render stateTransform

0 commit comments

Comments
 (0)