fay-base-0.21.2.0: The base package for Fay.
Safe HaskellNone
LanguageHaskell2010

Data.Var

Synopsis

Different types of variables

data Sig a Source #

A subscribable signal. Can have handlers subscribed to them, but doesn't store a value.

Instances

Instances details
Subscribable (Sig a) Source # 
Instance details

Defined in Data.Var

Settable (Sig a) Source # 
Instance details

Defined in Data.Var

newSig :: Fay (Ptr (Sig a)) Source #

Make a new signal.

data Ref a Source #

A mutable reference, with no subscribers.

Instances

Instances details
Gettable (Ref a) Source # 
Instance details

Defined in Data.Var

Settable (Ref a) Source # 
Instance details

Defined in Data.Var

newRef :: Ptr a -> Fay (Ptr (Ref a)) Source #

Make a new mutable reference.

data Var a Source #

A reactive variable. Stores a value, and can have handlers subscribed to changes.

Instances

Instances details
Subscribable (Var a) Source # 
Instance details

Defined in Data.Var

Gettable (Var a) Source # 
Instance details

Defined in Data.Var

Settable (Var a) Source # 
Instance details

Defined in Data.Var

newVar :: Ptr a -> Fay (Ptr (Var a)) Source #

Make a new reactive variable.

Generic operations

class Settable v Source #

All of the variable types can be set to a value.

Instances

Instances details
Settable (Var a) Source # 
Instance details

Defined in Data.Var

Settable (Ref a) Source # 
Instance details

Defined in Data.Var

Settable (Sig a) Source # 
Instance details

Defined in Data.Var

set :: Settable (v a) => Ptr (v a) -> Ptr a -> Fay () Source #

Write to the value (if any), and call subscribers (if any).

class Gettable v Source #

Ref and Var store their last set value.

Instances

Instances details
Gettable (Var a) Source # 
Instance details

Defined in Data.Var

Gettable (Ref a) Source # 
Instance details

Defined in Data.Var

get :: Gettable (v a) => Ptr (v a) -> Fay (Ptr a) Source #

Get the value of a Ref or Var.

modify :: (Settable (v a), Gettable (v a)) => v a -> (a -> a) -> Fay () Source #

Modifies the current value with a pure function.

modifyWith :: (Settable (v a), Gettable (v a)) => v a -> (a -> Fay a) -> Fay () Source #

Runs a Fay action on the current value, and updates with the result.

class Settable v => Subscribable v Source #

Sig and Var have lists of subscribers that are notified when set is used.

Instances

Instances details
Subscribable (Var a) Source # 
Instance details

Defined in Data.Var

Subscribable (Sig a) Source # 
Instance details

Defined in Data.Var

subscribe :: Subscribable (v a) => Ptr (v a) -> Ptr (a -> Fay void) -> Fay (() -> Fay ()) Source #

Subscribe to the value of a Sig or Var.

The result is an unsubscribe function.

withUnsubscriber :: ((a -> Fay ()) -> Fay (() -> Fay ())) -> ((() -> Fay ()) -> a -> Fay ()) -> Fay (() -> Fay ()) Source #

Run the same subscribing action but provide an additional unsubscribe parameter to the handler.

Specific operations

subscribeWithOld :: Var a -> (a -> a -> Fay ()) -> Fay (() -> Fay ()) Source #

Subscribe to a Var, along with the previous value.

The result is an unsubscribe function.

subscribeChange :: Eq a => Var a -> (a -> Fay ()) -> Fay (() -> Fay ()) Source #

Subscribe to a Var, but only call handler when it actually changes.

The result is an unsubscribe function.

subscribeAndRead :: Var a -> (a -> Fay void) -> Fay (() -> Fay ()) Source #

Subscribe to a Var, and call the function on the current value.

The result is an unsubscribe function.

subscribeChangeAndRead :: Eq a => Var a -> (a -> Fay ()) -> Fay (() -> Fay ()) Source #

Subscribe to a Var, but only call handler when it actually changes, and also initially on registration.

The result is an unsubscribe function.

subscribeExclusive :: Subscribable (v a) => v a -> (a -> Fay ()) -> Fay (a -> Fay (), () -> Fay ()) Source #

Given a change handler, returns a function that can be used to set a subscribable without invoking the handler. This can be useful in situations where the handler for a Var causes an event which otherwise ought to set the value of the Var. An example of this is interfacing with HTML input field change events.

The snd part of the result is an unsubscribe function.

subscribeAndReadExclusive :: Var a -> (a -> Fay ()) -> Fay (a -> Fay (), () -> Fay ()) Source #

Given a change handler, returns a function that can be used to set a var without invoking the handler. The handler is called with the initial value. This can be useful in situations where the handler for a Var causes an event which otherwise ought to set the value of the Var. An example of this is interfacing with HTML input field change events.

The snd part of the result is an unsubscribe function.

mapVar :: (a -> b) -> Var a -> Fay (Var b) Source #

Creates a Var that updates whenever the source var is changed, applying the provided function to compute the new value.

mergeVars :: (a -> b -> c) -> Maybe (c -> (a, b)) -> Var a -> Var b -> Fay (Var c, Fay ()) Source #

Creates a Var that updates whenever one of its source vars are changed. If the 2nd argument is a Just value, then its used to set the source vars when the variable is changed. Setting using a merged var is sometimes preferred because both values are set before the subscribers are called.

The snd part of the result is an unsubscribe function.

mergeVars' :: (a -> b -> c) -> Maybe (c -> (a, b)) -> Var a -> Var b -> Fay (Var c) Source #

Like mergeVars, but discards the unsubscribe function.

tupleVars :: Var a -> Var b -> Fay (Var (a, b), Fay ()) Source #

Creates a Var that updates whenever one of its source vars are changed. It can also be used to set both source vars at once.

See mergeVars for more information. Note that when using nested tuples, if you want all of the values to be set before broadcast, then they should nest to the left.

tupleVars' :: Var a -> Var b -> Fay (Var (a, b)) Source #

Like tupleVars, but discards the unsubscribe function.

waitForN :: Int -> Fay (Fay void -> Fay (), Sig ()) Source #

Wait for n signals on the given signaller.

waitFor :: Var a -> (a -> Bool) -> (a -> Fay ()) -> Fay () Source #

Wait for the given predicate to be satisfied on the var and then unsubscribe.

oneShot :: Subscribable (v a) => v a -> (a -> Fay ()) -> Fay () Source #

Make a one-shot variable subscription that immediately unsubscribes after the event has triggered.

holdSig :: a -> Sig a -> Fay (Var a) Source #

Turn a sig into a var, by storing the last reported value.