miso-0.16.0.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] 

type Sub action = Sink action -> IO () 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.

noEff :: model -> Effect action model Source

Smart constructor for an Effect with no actions.

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

Smart constructor for an Effect with exactly one action.

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

Effect smart constructor, flipped

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.