module Rooibos
The Elm Architecture for Ruby.
Building TUI applications means managing state, events, and rendering. Mixing them leads to spaghetti code. Bugs hide in the tangles.
This module implements The Elm Architecture (TEA). It separates your application into three pure functions: model, view, and update. The runtime handles the rest.
Use it to build applications with predictable, testable state management.
Constants
- VERSION
-
The version of this gem. See semver.org/spec/v2.0.0.html
Public Class Methods
Source
# File lib/rooibos.rb, line 64 def self.normalize_init(result) Runtime.normalize_init(result) end
Normalizes Init callable return value to [model, command] tuple.
Init callables use DWIM syntax. They can return just a model, just a command, or a full [model, command] tuple.
This method handles all formats. Use it when composing child fragment Inits in fractal architecture.
- result
-
The Init return value.
Examples
# Parent fragment composes children Init = ->(theme:) do stats_model, stats_cmd = Rooibos.normalize_init(StatsPanel::Init.(theme: theme)) network_model, network_cmd = Rooibos.normalize_init(NetworkPanel::Init.(theme: theme)) model = Model.new(stats: stats_model, network: network_model) command = Command.batch(stats_cmd, network_cmd) [model, command] end
Source
# File lib/rooibos.rb, line 31 def self.run(root_fragment = nil, **) Runtime.run(root_fragment, **) end
Starts the MVU event loop.
Convenience delegator to Runtime.run. See Runtime for full documentation.