Copyright | (C) 2016-2018 David M. Johnson |
---|---|
License | BSD3-style (see the file LICENSE) |
Maintainer | David M. Johnson <djohnson.m@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- module Miso.Effect.Storage
- module Miso.Effect.DOM
- data Effect action model = Effect model [Sub action]
- type Sub action = Sink action -> JSM ()
- type Sink action = action -> IO ()
- mapSub :: (actionA -> actionB) -> Sub actionA -> Sub actionB
- noEff :: model -> Effect action model
- (<#) :: model -> JSM action -> Effect action model
- (#>) :: JSM action -> model -> Effect action model
- batchEff :: model -> [JSM action] -> Effect action model
- effectSub :: model -> Sub action -> Effect action model
Documentation
module Miso.Effect.Storage
module Miso.Effect.DOM
data Effect action model Source #
An effect represents the results of an update action.
It consists of the updated model and a list of subscriptions. Each Sub
is
run in a new thread so there is no risk of accidentally blocking the
application.
Instances
Bifunctor Effect Source # | |
Monad (Effect action) Source # | |
Functor (Effect action) Source # | |
Applicative (Effect action) Source # | |
Defined in Miso.Effect pure :: a -> Effect action a Source # (<*>) :: Effect action (a -> b) -> Effect action a -> Effect action b Source # liftA2 :: (a -> b -> c) -> Effect action a -> Effect action b -> Effect action c Source # (*>) :: Effect action a -> Effect action b -> Effect action b Source # (<*) :: Effect action a -> Effect action b -> Effect action a Source # |
type Sink action = action -> IO () Source #
Function to asynchronously dispatch actions to the update
function.
mapSub :: (actionA -> actionB) -> Sub actionA -> Sub actionB Source #
Turn a subscription that consumes actions of type a
into a subscription
that consumes actions of type b
using the supplied function of type a -> b
.
(<#) :: model -> JSM action -> Effect action model Source #
Smart constructor for an Effect
with exactly one action.
batchEff :: model -> [JSM action] -> Effect action model Source #
Smart constructor for an Effect
with multiple actions.
effectSub :: model -> Sub action -> Effect action model Source #
Like <#
but schedules a subscription which is an IO computation which has
access to a Sink
which can be used to asynchronously dispatch actions to
the update
function.
A use-case is scheduling an IO computation which creates a 3rd-party JS
widget which has an associated callback. The callback can then call the sink
to turn events into actions. To do this without accessing a sink requires
going via a
which introduces a leaky-abstraction.Sub
scription