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

Commit 4f3cd1a

Browse files
committed
wrap lines at 80 char so I can see it with my eyes
1 parent fb65e20 commit 4f3cd1a

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

lib/react/component.rb

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def self.included(base)
2727
base.extend(ClassMethods)
2828

2929
if base.name
30-
parent = base.name.split("::").inject([Module]) { |nesting, next_const| nesting + [nesting.last.const_get(next_const)] }[-2]
30+
parent = base.name.split("::").inject([Module]) { |nesting, next_const|
31+
nesting + [nesting.last.const_get(next_const)]
32+
}[-2]
3133

3234
class << parent
3335
def method_missing(n, *args, &block)
@@ -59,7 +61,8 @@ def render
5961
end unless method_defined?(:render)
6062

6163
def deprecated_params_method(name, *args, &block)
62-
self.class.deprecation_warning "Direct access to param `#{name}`. Use `params.#{name}` instead."
64+
notice = "Direct access to param `#{name}`. Use `params.#{name}` instead."
65+
self.class.deprecation_warning(notice)
6366
params.send(name, *args, &block)
6467
end
6568

@@ -108,13 +111,13 @@ def refs
108111
end
109112

110113
def state
111-
#raise "No native ReactComponent associated" unless @native
112114
@state_wrapper ||= StateWrapper.new(@native, self)
113115
end
114116

115117
def update_react_js_state(object, name, value)
116118
if object
117-
set_state({"***_state_updated_at-***" => Time.now.to_f, "#{object.class.to_s+'.' unless object == self}#{name}" => value})
119+
set_state({"***_state_updated_at-***" => Time.now.to_f,
120+
"#{object.class.to_s+'.' unless object == self}#{name}" => value})
118121
else
119122
set_state({name => value})
120123
end rescue nil
@@ -128,7 +131,9 @@ def component_will_mount
128131
IsomorphicHelpers.load_context(true) if IsomorphicHelpers.on_opal_client?
129132
set_state! initial_state if initial_state
130133
State.initialize_states(self, initial_state)
131-
State.set_state_context_to(self) { self.run_callback(:before_mount) }
134+
State.set_state_context_to(self) do
135+
self.run_callback(:before_mount)
136+
end
132137
rescue Exception => e
133138
self.class.process_exception(e, self)
134139
end
@@ -143,9 +148,12 @@ def component_did_mount
143148
end
144149

145150
def component_will_receive_props(next_props)
146-
# need to rethink how this works in opal-react, or if its actually that useful within the react.rb environment
147-
# for now we are just using it to clear processed_params
148-
State.set_state_context_to(self) { self.run_callback(:before_receive_props, Hash.new(next_props)) }
151+
# need to rethink how this works in opal-react, or if its actually that
152+
# useful within the react.rb environment for now we are just using it to
153+
# clear processed_params
154+
State.set_state_context_to(self) do
155+
self.run_callback(:before_receive_props, Hash.new(next_props))
156+
end
149157
rescue Exception => e
150158
self.class.process_exception(e, self)
151159
end
@@ -177,7 +185,9 @@ def should_component_update?(next_props, next_state)
177185
end
178186

179187
def component_will_update(next_props, next_state)
180-
State.set_state_context_to(self) { self.run_callback(:before_update, Hash.new(next_props), Hash.new(next_state)) }
188+
State.set_state_context_to(self) do
189+
self.run_callback(:before_update, next_props, Hash.new(next_state))
190+
end
181191
rescue Exception => e
182192
self.class.process_exception(e, self)
183193
end
@@ -210,7 +220,9 @@ def p(*args, &block)
210220

211221
def component?(name)
212222
name_list = name.split("::")
213-
scope_list = self.class.name.split("::").inject([Module]) { |nesting, next_const| nesting + [nesting.last.const_get(next_const)] }.reverse
223+
scope_list = self.class.name.split("::").inject([Module]) do |nesting, next_const|
224+
nesting + [nesting.last.const_get(next_const)]
225+
end.reverse
214226
scope_list.each do |scope|
215227
component = name_list.inject(scope) do |scope, class_name|
216228
scope.const_get(class_name)
@@ -221,7 +233,9 @@ def component?(name)
221233
end
222234

223235
def method_missing(n, *args, &block)
224-
return props[n] if props.key? n # TODO deprecate and remove - done so that params shadow tags, no longer needed
236+
# TODO deprecate and remove - done so that params shadow tags, no longer
237+
# needed
238+
return props[n] if props.key?(n)
225239
name = n
226240
if name =~ /_as_node$/
227241
node_only = true
@@ -254,7 +268,11 @@ def define_state(*args, &block)
254268

255269
def _render_wrapper
256270
State.set_state_context_to(self) do
257-
RenderingContext.render(nil) {render || ""}.tap { |element| @waiting_on_resources = element.waiting_on_resources if element.respond_to? :waiting_on_resources }
271+
RenderingContext.render(nil) {render || ""}.tap do |element|
272+
if element.respond_to?(:waiting_on_resources)
273+
@waiting_on_resources = element.waiting_on_resources
274+
end
275+
end
258276
end
259277
rescue Exception => e
260278
self.class.process_exception(e, self)

lib/react/state.rb

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,23 @@ class State
3636
class << self
3737
attr_reader :current_observer
3838

39-
def initialize_states(object, initial_values) # initialize objects' name/value pairs
39+
def initialize_states(object, initial_values)
40+
# initialize objects' name/value pairs
4041
states[object].merge!(initial_values || {})
4142
end
4243

4344
def get_state(object, name, current_observer = @current_observer)
44-
# get current value of name for object, remember that the current object depends on this state, current observer can be overriden with last param
45-
new_observers[current_observer][object] << name if current_observer && !new_observers[current_observer][object].include?(name)
45+
# get current value of name for object, remember that the current object
46+
# depends on this state, current observer can be overriden with last
47+
# param
48+
new_observers[current_observer][object] << name if current_observer &&
49+
!new_observers[current_observer][object].include?(name)
4650
states[object][name]
4751
end
4852

49-
def set_state2(object, name, value) # set object's name state to value, tell all observers it has changed. Observers must implement update_react_js_state
53+
def set_state2(object, name, value)
54+
# set object's name state to value, tell all observers it has changed.
55+
# Observers must implement update_react_js_state
5056
object_needs_notification = object.respond_to? :update_react_js_state
5157
observers_by_name[object][name].dup.each do |observer|
5258
observer.update_react_js_state(object, name, value)
@@ -82,7 +88,9 @@ def is_observing?(object, name, current_observer)
8288
current_observer && observers_by_name[object][name].include?(current_observer)
8389
end
8490

85-
def update_states_to_observe(current_observer = @current_observer) # should be called after the last after_render callback, currently called after components render method
91+
# should be called after the last after_render callback, currently called
92+
# after components render method
93+
def update_states_to_observe(current_observer = @current_observer)
8694
raise "update_states_to_observer called outside of watch block" unless current_observer
8795
current_observers[current_observer].each do |object, names|
8896
names.each do |name|
@@ -108,7 +116,9 @@ def remove # call after component is unmounted
108116
current_observers.delete(@current_observer)
109117
end
110118

111-
def set_state_context_to(observer) # wrap all execution that may set or get states in a block so we know which observer is executing
119+
# wrap all execution that may set or get states in a block so we know
120+
# which observer is executing
121+
def set_state_context_to(observer)
112122
if `typeof window.reactive_ruby_timing !== 'undefined'`
113123
@nesting_level = (@nesting_level || 0) + 1
114124
start_time = Time.now.to_f
@@ -120,7 +130,9 @@ def set_state_context_to(observer) # wrap all execution that may set or get stat
120130
return_value
121131
ensure
122132
@current_observer = saved_current_observer
123-
@nesting_level = [0, @nesting_level - 1].max if `typeof window.reactive_ruby_timing !== 'undefined'`
133+
if `typeof window.reactive_ruby_timing !== 'undefined'`
134+
@nesting_level = [0, @nesting_level - 1].max
135+
end
124136
return_value
125137
end
126138

@@ -134,7 +146,6 @@ def states
134146
instance_variable_set("@#{method_name}", Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } })
135147
end
136148
end
137-
138149
end
139150
end
140151
end

0 commit comments

Comments
 (0)