Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data RepF r a = Rep {}
- type Rep a = RepF (Html ()) a
- oneRep :: Monad m => Rep a -> (Rep a -> HashMap Text Text -> m ()) -> StateT (HashMap Text Text) m (HashMap Text Text, Either Text a)
- newtype SharedRepF m r a = SharedRep {}
- type SharedRep m a = SharedRepF m (Html ()) a
- runOnce :: Monad m => SharedRep m a -> (Html () -> HashMap Text Text -> m ()) -> m (HashMap Text Text, Either Text a)
- zeroState :: Monad m => SharedRep m a -> m (Html (), (HashMap Text Text, Either Text a))
- register :: Monad m => (Text -> Either Text a) -> (a -> Text) -> (Text -> a -> r) -> a -> SharedRepF m r a
- message :: Monad m => (Text -> Either Text a) -> (Text -> a -> r) -> a -> a -> SharedRepF m r a
- genName :: MonadState Int m => m Text
- genNamePre :: MonadState Int m => Text -> m Text
Documentation
Information contained in a web page can usually be considered to be isomorphic to a map of named values - a HashMap
. This is especially true when considering a differential of information contained in a web page. Looking at a page from the outside, it often looks like a streaming differential of a hashmap.
RepF consists of an underlying value being represented, and, given a hashmap state, a way to produce a representation of the underlying value (or error), in another domain, together with the potential to alter the hashmap state.
oneRep :: Monad m => Rep a -> (Rep a -> HashMap Text Text -> m ()) -> StateT (HashMap Text Text) m (HashMap Text Text, Either Text a) Source #
stateful result of one step, given a RepF
, and a monadic action.
Useful for testing and for initialising a page.
newtype SharedRepF m r a Source #
Driven by the architecture of the DOM, web page components are compositional, and tree-like, where components are often composed of other components, and values are thus shared across components.
This is sometimes referred to as "observable sharing". See data-reify as another library that reifies this (pun intended), and provided the initial inspiration for this implementation.
unshare should only be run once, which is a terrible flaw that might be fixed by linear types.
Instances
runOnce :: Monad m => SharedRep m a -> (Html () -> HashMap Text Text -> m ()) -> m (HashMap Text Text, Either Text a) Source #
Compute the initial state of a SharedRep and then run an action once (see tests).
zeroState :: Monad m => SharedRep m a -> m (Html (), (HashMap Text Text, Either Text a)) Source #
compute the initial state of a SharedRep (testing)
:: Monad m | |
=> (Text -> Either Text a) | Parser |
-> (a -> Text) | Printer |
-> (Text -> a -> r) | create initial object from name and initial value |
-> a | initial value |
-> SharedRepF m r a |
Create a sharedRep
:: Monad m | |
=> (Text -> Either Text a) | Parser |
-> (Text -> a -> r) | create initial object from name and initial value |
-> a | initial value |
-> a | default value |
-> SharedRepF m r a |
Like register
, but does not put a value into the HashMap on instantiation, consumes the value when found in the HashMap, and substitutes a default on lookup failure
genName :: MonadState Int m => m Text Source #
name supply for elements of a SharedRepF
genNamePre :: MonadState Int m => Text -> m Text Source #
sometimes a number doesn't work properly in html (or js???), and an alpha prefix seems to help