Module

Hylograph.ForceEngine.Registry

Package
purescript-hylograph-simulation
Repository
afcondon/purescript-hylograph-simulation

Simulation Registry

Named simulation registry for debugging and coordination. Allows tracking multiple simulations by name, useful when:

  • Running multiple visualizations simultaneously
  • Debugging simulation behavior via browser console
  • Coordinating simulations (e.g., pausing main when popup opens)

Usage:

-- Create and register a simulation
sim <- create defaultConfig
register "main-explorer" sim

-- Later, from browser console or debug code
mainSim <- lookup "main-explorer"
case mainSim of
  Just s -> stop s
  Nothing -> pure unit

-- List all registered simulations
names <- listSimulations
log $ "Running simulations: " <> show names

#AnySimulation Source

data AnySimulation

Internal registry storage. Uses existential encoding to store simulations with different row types. The trade-off is we can only perform operations that work on any simulation.

#register Source

register :: forall row linkRow. String -> Simulation row linkRow -> Effect Unit

Register a simulation with a name.

If a simulation with this name already exists, it will be replaced. The old simulation is NOT stopped automatically.

sim <- create defaultConfig
register "call-graph" sim

#unregister Source

unregister :: String -> Effect Unit

Unregister a simulation by name.

Does nothing if no simulation with this name exists. The simulation is NOT stopped automatically.

#lookup Source

lookup :: String -> Effect (Maybe AnySimulation)

Look up a simulation by name.

WARNING: The returned simulation has an unknown row type. Only use operations that work on any simulation (stop, isRunning, getAlpha). Calling getNodes will require an unsafe cast.

#listSimulations Source

listSimulations :: Effect (Array String)

List all registered simulation names.

#stopAll Source

stopAll :: Effect Unit

Stop all registered simulations.

Useful when cleaning up, e.g., when navigating away from a page.

#clearRegistry Source

clearRegistry :: Effect Unit

Clear the registry without stopping simulations.

Use stopAll first if you want to stop them.

#debugRegistry Source

debugRegistry :: Effect Unit

Print debug information about all registered simulations.

Designed for use from browser console:

// In browser console:
import('./output/Hylograph.ForceEngine.Registry/index.js').then(m => m.debugRegistry())

#unsafeFromAny Source

unsafeFromAny :: forall row linkRow. AnySimulation -> Simulation row linkRow