Skip to content

Commit a3baa6c

Browse files
Remove component_name from AsyncValue class
The component_name attribute was unused and unnecessary. This change simplifies AsyncValue to only store the task, matching the interface of ImmediateAsyncValue for consistency. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 38d0dfd commit a3baa6c

File tree

4 files changed

+11
-26
lines changed

4 files changed

+11
-26
lines changed

react_on_rails_pro/app/helpers/react_on_rails_pro_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def async_react_component(component_name, options = {})
245245
react_component(component_name, options)
246246
end
247247

248-
ReactOnRailsPro::AsyncValue.new(component_name: component_name, task: task)
248+
ReactOnRailsPro::AsyncValue.new(task: task)
249249
end
250250

251251
# Renders a React component asynchronously with caching support.
@@ -397,7 +397,7 @@ def render_async_react_component_uncached(component_name, raw_options, &block)
397397
react_component(component_name, options)
398398
end
399399

400-
ReactOnRailsPro::AsyncValue.new(component_name: component_name, task: task)
400+
ReactOnRailsPro::AsyncValue.new(task: task)
401401
end
402402

403403
# Renders async and writes to cache on completion
@@ -410,7 +410,7 @@ def render_async_react_component_with_cache(component_name, raw_options, cache_k
410410
result
411411
end
412412

413-
ReactOnRailsPro::AsyncValue.new(component_name: component_name, task: task)
413+
ReactOnRailsPro::AsyncValue.new(task: task)
414414
end
415415

416416
def prepare_async_render_options(raw_options)

react_on_rails_pro/lib/react_on_rails_pro/async_value.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ module ReactOnRailsPro
1010
# html = async_value.value # blocks until result is ready
1111
#
1212
class AsyncValue
13-
attr_reader :component_name
14-
15-
def initialize(component_name:, task:)
16-
@component_name = component_name
13+
def initialize(task:)
1714
@task = task
1815
end
1916

react_on_rails_pro/sig/react_on_rails_pro/async_value.rbs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
module ReactOnRailsPro
22
class AsyncValue
3-
attr_reader component_name: String
4-
53
@task: untyped
6-
@component_name: String
74

8-
def initialize: (component_name: String, task: untyped) -> void
5+
def initialize: (task: untyped) -> void
96

107
def value: () -> untyped
118

react_on_rails_pro/spec/react_on_rails_pro/async_value_spec.rb

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,14 @@
66

77
module ReactOnRailsPro
88
RSpec.describe AsyncValue do
9-
describe "#initialize" do
10-
it "stores the component name and task" do
11-
task = instance_double(Async::Task)
12-
async_value = described_class.new(component_name: "MyComponent", task: task)
13-
14-
expect(async_value.component_name).to eq("MyComponent")
15-
end
16-
end
17-
189
describe "#value" do
1910
it "returns the task result when task completes successfully" do
2011
Sync do
2112
task = Async do
2213
"<div>Hello</div>"
2314
end
2415

25-
async_value = described_class.new(component_name: "MyComponent", task: task)
16+
async_value = described_class.new(task: task)
2617
expect(async_value.value).to eq("<div>Hello</div>")
2718
end
2819
end
@@ -33,7 +24,7 @@ module ReactOnRailsPro
3324
raise StandardError, "Render failed"
3425
end
3526

36-
async_value = described_class.new(component_name: "MyComponent", task: task)
27+
async_value = described_class.new(task: task)
3728
expect { async_value.value }.to raise_error(StandardError, "Render failed")
3829
end
3930
end
@@ -49,7 +40,7 @@ module ReactOnRailsPro
4940
"result"
5041
end
5142

52-
async_value = described_class.new(component_name: "MyComponent", task: task)
43+
async_value = described_class.new(task: task)
5344
expect(async_value.resolved?).to be false
5445

5546
barrier.wait
@@ -63,7 +54,7 @@ module ReactOnRailsPro
6354
end
6455

6556
task.wait
66-
async_value = described_class.new(component_name: "MyComponent", task: task)
57+
async_value = described_class.new(task: task)
6758
expect(async_value.resolved?).to be true
6859
end
6960
end
@@ -76,7 +67,7 @@ module ReactOnRailsPro
7667
"<div>Content</div>"
7768
end
7869

79-
async_value = described_class.new(component_name: "MyComponent", task: task)
70+
async_value = described_class.new(task: task)
8071
expect(async_value.to_s).to eq("<div>Content</div>")
8172
end
8273
end
@@ -89,7 +80,7 @@ module ReactOnRailsPro
8980
"<div>Content</div>"
9081
end
9182

92-
async_value = described_class.new(component_name: "MyComponent", task: task)
83+
async_value = described_class.new(task: task)
9384
result = async_value.html_safe
9485

9586
expect(result).to be_html_safe

0 commit comments

Comments
 (0)