Module

Specular.FRP.Base

Package
purescript-specular
Repository
restaumatic/purescript-specular

#Event Source

newtype Event a

A source of occurences.

During a frame, an Event occurs at most once with a value of type a.

Event is a functor. It is not, however, an Applicative. There is no meaningful interpretation of pure (when would the event occur?). There is an interpretation of apply (Event that fires when the input events coincide), but it's not very useful.

Instances

#never Source

never :: forall a. Event a

An Event that never occurs.

#leftmost Source

leftmost :: forall a. Array (Event a) -> Event a

An Event that occurs when any of the events occur. If some of them occur simultaneously, the occurence value is that of the leftmost one.

#filterEvent Source

filterEvent :: forall a. (a -> Boolean) -> Event a -> Event a

#filterMapEvent Source

filterMapEvent :: forall a b. (a -> Maybe b) -> Event a -> Event b

#filterJustEvent Source

filterJustEvent :: forall a. Event (Maybe a) -> Event a

#pull Source

pull :: forall a m. MonadEffect m => Effect a -> m a

#Behavior Source

newtype Behavior a

import Partial.Unsafe (unsafeCrashWith) import Unsafe.Coerce (unsafeCoerce) Behaviors are time-changing values that can be read, but not subscribed to.

Instances

#sampleAt Source

sampleAt :: forall a b. Event (a -> b) -> Behavior a -> Event b

#readBehavior Source

readBehavior :: forall a. Behavior a -> Effect a

Read a value of a Behavior.

#Dynamic Source

newtype Dynamic a

Dynamic a represents a dynamically changing value of type a. The current value may be queried at any time (using current), and it's possible to be notified of changes (using changed).

Instances

#current Source

current :: forall a. Dynamic a -> Behavior a

The Behavior representing the current value of the Dynamic. When it is changing (the change event occurs), it has the new value.

The value of current x is always the value of the latest occurence of changed x, if it has ever occured.

#changed Source

changed :: forall a. Dynamic a -> Event a

An Event that fires with the new value every time the Dynamic changes.

#changed_ Source

changed_ :: forall a. Dynamic a -> Event Unit

An Event that fires every time the Dynamic changes.

#switch Source

switch :: forall a. Dynamic (Event a) -> Event a

Make an Event that occurs when the current value of the given Dynamic (an Event) occurs.

switch (pure e) = e

#tagDyn Source

tagDyn :: forall a. Dynamic a -> Event Unit -> Event a

#attachDynWith Source

attachDynWith :: forall a b c. (a -> b -> c) -> Dynamic a -> Event b -> Event c

#latestJust Source

latestJust :: forall m a. MonadFRP m => Dynamic (Maybe a) -> m (Dynamic (Maybe a))

Returns a Dynamic that holds the latest Just value of the input Dynamic after execution of this function. If the input currently has value Nothing, the resulting Dynamic will have the value Nothing until the input changes to a Just.

The resulting Dynamic changes when the input changes to a value that is a Just, and doesn't change when the input changes to Nothing.

#readDynamic Source

readDynamic :: forall m a. MonadEffect m => Dynamic a -> m a

#newDynamic Source

newDynamic :: forall m a. MonadEffect m => a -> m { dynamic :: Dynamic a, modify :: (a -> a) -> Effect Unit, read :: Effect a, set :: a -> Effect Unit }

effectCrash :: forall a. String -> a effectCrash msg = unsafeCoerce (_ -> unsafeCrashWith msg) Construct a new root Dynamic that can be changed from Effect-land.

#holdDyn Source

holdDyn :: forall m a. MonadFRP m => a -> Event a -> m (Dynamic a)

holdDyn initialValue event returns a Dynamic that starts with initialValue, and changes to the occurence value of event when event fires

#foldDyn Source

foldDyn :: forall m a b. MonadFRP m => (a -> b -> b) -> b -> Event a -> m (Dynamic b)

foldDyn f x e - Make a Dynamic that will have the initial value x, and every time e fires, its value will update by applying f to the event occurence value and the old value.

On cleanup, the Dynamic will stop updating in response to the event.

#foldDynMaybe Source

foldDynMaybe :: forall m a b. MonadFRP m => (a -> b -> Maybe b) -> b -> Event a -> m (Dynamic b)

Like foldDyn, but the Dynamic will not update if the folding function returns Nothing.

#holdUniqDynBy Source

holdUniqDynBy :: forall m a. MonadFRP m => (a -> a -> Boolean) -> a -> Event a -> m (Dynamic a)

#uniqDynBy Source

uniqDynBy :: forall m a. MonadFRP m => (a -> a -> Boolean) -> Dynamic a -> m (Dynamic a)

Make a Dynamic that only changes value when the input Dynamic changes value, and the new value is not equal to the previous value with respect to the given equality test.

#uniqDyn Source

uniqDyn :: forall m a. MonadFRP m => Eq a => Dynamic a -> m (Dynamic a)

#newEvent Source

newEvent :: forall m a. MonadEffect m => m { event :: Event a, fire :: a -> Effect Unit }

Create an Event that can be triggered externally. Each fire will run a frame where the event occurs.

#newBehavior Source

newBehavior :: forall m a. MonadEffect m => a -> m { behavior :: Behavior a, set :: a -> Effect Unit }

Create a new Behavior whose value can be modified outside a frame.

#subscribeEvent_ Source

subscribeEvent_ :: forall m a. MonadEffect m => MonadCleanup m => (a -> Effect Unit) -> Event a -> m Unit

#subscribeDyn_ Source

subscribeDyn_ :: forall m a. MonadFRP m => (a -> Effect Unit) -> Dynamic a -> m Unit

#subscribeDyn Source

subscribeDyn :: forall m a b. MonadFRP m => (a -> Effect b) -> Dynamic a -> m (Dynamic b)

#_subscribeEvent Source

#MonadFRP Source

class MonadFRP :: (Type -> Type) -> Constraintclass (MonadEffect m, MonadCleanup m) <= MonadFRP m 

A "type class alias" for the constraints required by most FRP primitives.

Instances

#traceEventIO Source

traceEventIO :: forall a. (a -> Effect Unit) -> Event a -> Event a

#traceDynIO Source

traceDynIO :: forall a. (a -> Effect Unit) -> Dynamic a -> Dynamic a

#annotate Source

annotate :: forall m a. MonadEffect m => Dynamic a -> String -> m Unit

#annotated Source

annotated :: forall a. String -> Dynamic a -> Dynamic a

#map2 Source

map2 :: forall a b c. (a -> b -> c) -> Dynamic a -> Dynamic b -> Dynamic c