No release in over 3 years
There's a lot of open issues
This gem is intentionally published early. The API is unstable, but the idea is stable. view_component_reducible brings reducer-style (TEA-inspired) state transitions to Rails ViewComponent. Server-driven, HTTP-based, no WebSocket required.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

 Project Readme

view_component_reducible

Ask DeepWiki

sample

This sample shows state transitions and partial updates powered entirely by ViewComponent. The only thing you add in Rails is a single endpoint:

mount ViewComponentReducible::Engine, at: "/vcr"

Everything else is reducible to ViewComponent—no extra endpoints, controllers, WebSockets, or JS frameworks required.

view_component_reducible brings reducer-based state transitions to Rails ViewComponent, inspired by TEA (The Elm Architecture).

Quick Start

1. Install

# Gemfile
gem "view_component_reducible"
bundle install

2. Mount the endpoint

# config/routes.rb
mount ViewComponentReducible::Engine, at: "/vcr"

3. Configure adapter

# config/initializers/view_component_reducible.rb
ViewComponentReducible.configure do |config|
  config.adapter = ViewComponentReducible::Adapter::HiddenField
  config.secret = Rails.application.secret_key_base
end

Including ViewComponentReducible::Component registers the component automatically.

4. Create component

# app/components/counter_component.rb
class CounterComponent < ViewComponent::Base
  include ViewComponentReducible::Component

  state do
    field :count, default: 0
  end

  def reduce(state, msg)
    case msg
    in { type: :increment }
      state.with(count: state.count + 1)
    else
      state
    end
  end
end
<!-- app/components/counter_component.html.erb -->
<section>
  <p><%= vcr_state.count %></p>
  <%= vcr_button_to("+", type: :increment) %>
</section>

5. Enable partial updates

<!-- app/views/layouts/application.html.erb -->
<%= vcr_dispatch_script_tag %>