git.iko.soy/rowtype-yoga/purescript-yoga-om-rom
on main help sign in
git clone ssh://git.iko.soy/rowtype-yoga/purescript-yoga-om-rom

yoga-om-rom

Reactive Om - Bolson-based FRP integration for yoga-om, bridging Om computations with Bolson's event system.

Installation

spago install yoga-om-core yoga-om-rom bolson

What's Included

Usage

Converting Om to Event

import Yoga.Om.Rom as Rom

myEvent :: Event User
myEvent = Rom.omToEvent ctx handlers fetchUser

-- Use with Bolson's event combinators
userEvent = myEvent <#> _.name

Converting Event to Om

import Yoga.Om.Rom as Rom

processClicks :: Om _ _ Unit
processClicks = do
  clickData <- Rom.eventToOm buttonClickEvent
  -- Process the first click
  Console.log $ "Clicked: " <> show clickData

Streaming Multiple Oms

import Yoga.Om.Rom as Rom

allUsers :: Event User
allUsers = Rom.streamOms ctx handlers
  [ fetchUser 1
  , fetchUser 2
  , fetchUser 3
  ]

Event Fold with Om

import Yoga.Om.Rom as Rom

runningTotal :: Event Int
runningTotal = Rom.foldOms
  (\total value -> do
    -- Can do Om operations here
    Console.log $ "Adding " <> show value
    pure (total + value)
  )
  0
  ctx
  handlers
  numberEvent

Working with Event Streams in Om Context

import Yoga.Om.Rom as Rom

reactToEvents :: Om { logger :: Logger } _ (Event String)
reactToEvents = Rom.withEventStream inputEvent \input -> do
  { logger } <- Om.ask
  -- Process input within Om context
  log logger input
  pure (String.toUpper input)

Integration with Bolson

This package is designed to work seamlessly with Bolson's FRP system. You can:

Testing

Tests are colocated with the implementation in the test/ directory:

# Run tests
cd packages/yoga-om-rom && spago test

# Or from workspace root
bun test:rom

See test/Test/Rom.purs for test examples.

Package Structure

yoga-om-rom/
├── src/
│   └── Yoga/
│       └── Om/
│           └── Rom.purs    # Bolson FRP integration
└── test/                    # Tests colocated here!
    └── Test/
        ├── Main.purs       # Test runner
        └── Rom.purs        # Rom tests

See Also

For more examples, see the tests and main README.