Module

Hylograph.Transition.Coordinator

Package
purescript-hylograph-transitions
Repository
afcondon/purescript-hylograph-transitions

Tick Coordinator

A unified animation coordinator that owns the RAF loop and routes ticks to multiple consumers (transitions, simulations, etc).

Key concepts:

  • Single RAF loop: One coordinator per visualization, no competing frames
  • TickConsumer: Anything that needs ticks (transitions, simulations)
  • Pull model: Consumers compute on tick, coordinator reads results

Usage:

import Hylograph.Transition.Coordinator as C

main = do
  coord <- C.create

  -- Register a transition
  transitionId <- C.register coord
    { tick: \dt -> do
        -- advance transition
        pure C.StillRunning
    , onComplete: log "done!"
    }

  -- Start the loop
  C.start coord

#Coordinator Source

newtype Coordinator

The tick coordinator - owns the RAF loop

#create Source

create :: Effect Coordinator

Create a new coordinator. The coordinator starts in stopped state - call start to begin.

#start Source

start :: Coordinator -> Effect Unit

Start the animation loop. Does nothing if already running.

#stop Source

stop :: Coordinator -> Effect Unit

Stop the animation loop. Consumers remain registered but stop receiving ticks.

#isRunning Source

isRunning :: Coordinator -> Effect Boolean

Check if the coordinator is currently running.

#ConsumerId Source

newtype ConsumerId

Unique identifier for a registered consumer

Instances

#TickResult Source

data TickResult

Result of a tick - tells coordinator what to do next

Constructors

#Consumer Source

type Consumer = { id :: ConsumerId, onComplete :: Effect Unit, tick :: Milliseconds -> Effect TickResult }

A tick consumer - anything that needs animation frames

#register Source

register :: Coordinator -> { onComplete :: Effect Unit, tick :: Milliseconds -> Effect TickResult } -> Effect ConsumerId

Register a consumer to receive ticks. Returns an ID that can be used to unregister later. If the coordinator is running, the consumer starts receiving ticks immediately.

#unregister Source

unregister :: Coordinator -> ConsumerId -> Effect Unit

Unregister a consumer. It will no longer receive ticks. If this was the last consumer, the loop continues but does nothing.

#Milliseconds Source

type Milliseconds = Number

Time delta in milliseconds