Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 3439649

Browse files
author
Luke Cassar
committed
Modify force_update! to return component called upon.
1 parent bf79d4e commit 3439649

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/react/component/api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def mounted?
1111

1212
def force_update!
1313
`#{self}.native.forceUpdate()`
14+
self
1415
end
1516

1617
def set_props(prop, &block)

spec/react/component_spec.rb

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,48 @@ def render
136136
end
137137
end
138138

139+
describe 'Misc Methods' do
140+
it 'has a force_update! method' do
141+
mount 'Foo' do
142+
class Foo < Hyperloop::Component
143+
class << self
144+
attr_accessor :render_counter
145+
attr_accessor :instance
146+
end
147+
before_mount do
148+
Foo.render_counter = 0
149+
Foo.instance = self
150+
end
151+
def render
152+
Foo.render_counter += 1
153+
DIV { "I have been rendered #{Foo.render_counter} times" }
154+
end
155+
end
156+
end
157+
expect_evaluate_ruby do
158+
Foo.instance.force_update!
159+
Foo.render_counter
160+
end.to eq(2)
161+
end
162+
163+
it 'has its force_update! method return itself' do
164+
mount 'Foo' do
165+
class Foo < Hyperloop::Component
166+
class << self
167+
attr_accessor :instance
168+
end
169+
before_mount do
170+
Foo.instance = self
171+
end
172+
def render
173+
DIV { "I have been rendered" }
174+
end
175+
end
176+
end
177+
expect_evaluate_ruby('Foo.instance == Foo.instance.force_update!').to be_truthy
178+
end
179+
end
180+
139181
describe 'New style setter & getter' do
140182
before(:each) do
141183
on_client do
@@ -843,7 +885,7 @@ def render
843885

844886
it 'only overrides `p` in render context' do
845887
mount 'Foo' do
846-
888+
847889
class Foo
848890
include React::Component
849891

0 commit comments

Comments
 (0)