miso-0.21.1.0: A tasty Haskell front-end framework

Copyright(C) 2016-2018 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <djohnson.m@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Effect

Description

 

Synopsis

Documentation

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.

Constructors

Effect model [Sub action] 

Instances

Bifunctor Effect Source # 

Methods

bimap :: (a -> b) -> (c -> d) -> Effect a c -> Effect b d #

first :: (a -> b) -> Effect a c -> Effect b c #

second :: (b -> c) -> Effect a b -> Effect a c #

Monad (Effect action) Source # 

Methods

(>>=) :: Effect action a -> (a -> Effect action b) -> Effect action b #

(>>) :: Effect action a -> Effect action b -> Effect action b #

return :: a -> Effect action a #

fail :: String -> Effect action a #

Functor (Effect action) Source # 

Methods

fmap :: (a -> b) -> Effect action a -> Effect action b #

(<$) :: a -> Effect action b -> Effect action a #

Applicative (Effect action) Source # 

Methods

pure :: a -> Effect action a #

(<*>) :: Effect action (a -> b) -> Effect action a -> Effect action b #

(*>) :: Effect action a -> Effect action b -> Effect action b #

(<*) :: Effect action a -> Effect action b -> Effect action a #

type Sub action = Sink action -> JSM () Source #

Type synonym for constructing event subscriptions.

The Sink callback is used to dispatch actions which are then fed back to the update function.

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.

noEff :: model -> Effect action model Source #

Smart constructor for an Effect with no actions.

(<#) :: model -> JSM action -> Effect action model Source #

Smart constructor for an Effect with exactly one action.

(#>) :: JSM action -> model -> Effect action model Source #

Effect smart constructor, flipped

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 Subscription which introduces a leaky-abstraction.