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 CoordinatorThe tick coordinator - owns the RAF loop
#create Source
create :: Effect CoordinatorCreate a new coordinator.
The coordinator starts in stopped state - call start to begin.
#start Source
start :: Coordinator -> Effect UnitStart the animation loop. Does nothing if already running.
#stop Source
stop :: Coordinator -> Effect UnitStop the animation loop. Consumers remain registered but stop receiving ticks.
#isRunning Source
isRunning :: Coordinator -> Effect BooleanCheck if the coordinator is currently running.
#TickResult Source
#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 ConsumerIdRegister 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 UnitUnregister a consumer. It will no longer receive ticks. If this was the last consumer, the loop continues but does nothing.
#Milliseconds Source
type Milliseconds = NumberTime delta in milliseconds