module Rooibos::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, Init, Update, and View constants. Fragments compose: parent fragments delegate to child fragments.

Example

class Dashboard
  include Rooibos::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)
  Init = -> { Model.new(stats: StatsPanel::Init.(), network: NetworkPanel::Init.()) }
  View = ->(model, tui) { ... }
  Update = from_router
end