class Rooibos::Command::Mapped
Wraps another commandās result with a transformation.
Fractal Architecture requires composition. Child fragments produce commands with their own tags. Parent fragments need those results routed back with a parent prefix. Without transformation, update functions become monolithic āGod Reducersā that know about every childās internals.
This command wraps an inner command and transforms its result message. The parent fragment delegates to the child, then intercepts the result and adds its routing prefix. Clean separation. No coupling.
Use it to compose child fragments that return their own commands.
Prefer the Command.map factory method for convenience.
Example
# Using the factory method (recommended) Command.map(child_command) { |msg| [:sidebar, msg] } # Using the class directly Mapped.new(inner_command: child_command, mapper: ->(msg) { [:sidebar, msg] })
Public Instance Methods
Source
# File lib/rooibos/command.rb, line 476 def call(out, token) inner_channel = Concurrent::Promises::Channel.new inner_outlet = Outlet.new(inner_channel, lifecycle: out.live) Concurrent::Promises.future do if inner_command.respond_to?(:call) inner_command.call(inner_outlet, token) else raise ArgumentError, "Inner command must respond to #call" end inner_channel.push(DONE) end loop do msg = inner_channel.pop break if msg.equal?(DONE) transformed = mapper.call(msg) out.put(*transformed) if transformed end end
Executes the inner command and transforms each message.
Source
# File lib/rooibos/command.rb, line 470 def rooibos_cancellation_grace_period inner_command.respond_to?(:rooibos_cancellation_grace_period) ? inner_command.rooibos_cancellation_grace_period : 0.1 end
Grace period delegates to inner command.