module RatatuiRuby::Tea::Router
Declarative DSL for Fractal Architecture.
Large applications decompose into fragments. Each fragment has its own Model, UPDATE, and VIEW. Parent fragments route messages to child fragments and compose views. Writing this routing logic by hand is tedious and error-prone.
Include this module to declare routes and keymaps. Call from_router to generate an UPDATE lambda that handles routing automatically.
A fragment is a module containing Model, INITIAL, UPDATE, and VIEW constants. Fragments compose: parent fragments delegate to child fragments.
Example
class Dashboard
include Tea::Router
route :stats, to: StatsPanel
route :network, to: NetworkPanel
keymap do
key "s", -> { SystemInfo.fetch_command }, route: :stats
key "q", -> { Command.exit }
end
Model = Data.define(:stats, :network)
INITIAL = Model.new(stats: StatsPanel::INITIAL, network: NetworkPanel::INITIAL)
VIEW = ->(model, tui) { ... }
UPDATE = from_router
end
Constants
- ClickHandlerConfig
-
Configuration for click handlers (x, y coordinates).
- KeyHandlerConfig
-
Configuration for key handlers.
- ScrollHandlerConfig
-
Configuration for scroll handlers (no coordinates).