miso-1.8.5.0: A tasty Haskell front-end web 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

This module defines Effect and Sub types, which are used to define update function and subs field of the App.

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 # 
Instance details

Defined in Miso.Effect

Methods

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

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

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

Monad (Effect action) Source # 
Instance details

Defined in Miso.Effect

Methods

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

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

return :: a -> Effect action a Source #

fail :: String -> Effect action a Source #

Functor (Effect action) Source # 
Instance details

Defined in Miso.Effect

Methods

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

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

Applicative (Effect action) Source # 
Instance details

Defined in Miso.Effect

Methods

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 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.