purescript - Monad Transformer for Halogen Components -


i'm trying figure out in way can use transformer on monad halogen component contains.

i'd extend intro example readert carries config record in case used make strings configurable, i'm lost when comes putting together.

let's define our config this:

-- | global configuration newtype config = config { toggletext :: string                         , ontext :: string                         , offtext :: string                         } 

our ui function turn from

forall m eff. (monad m) => component m input input

to

forall m (monad m) => component (readert config m) input input.

to evaluate our main function, we'd use hoistcomponent turn previous form:

main =   let config = config { toggletext: "toggle button"                       , ontext: "on"                       , offtext: "off"                       }   tuple node _ <- runui $ hoistcomponent (runreadert config) ui   appendtobody node 

i'm not sure if makes sense far, pretending does, next step i'm struggling. in ideal world, ui function allow me this:

ui :: forall m eff. (monad m) => component (readert config m) input input ui = render <$> stateful (state { on: false }) update     render :: state -> h.html (readert config m input)   render (state s) =     (config conf) <- ask     return $ h.div_ [ h.h1_ [ h.text conf.toggletext ]                     , h.button [ a.onclick (a.input_ togglestate) ]                                [ h.text (if s.on conf.ontext else conf.offtext) ]                     ]    update :: state -> input -> state   update (state s) togglestate = state { on: not s.on } 

but end long chain of unification errors , don't know start. obviously, inner use of ask cannot work this, because i'd need lift html context, i'm not sure if that's possible.

it great if guide through types here , tell me if general approach sensible. full (non-compiling) example on github. i18n should serve simple example use of reader here.

the monad m monad event handlers. html document not have access configuration in reader monad.

you use reader if wanted event handlers have access configuration object, , have replace use of a.input_ action in reader monad.

to want do, want more monadreader config m => m (component _ _ _), component depends on configuration.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -