Module: React::Component
- Included in:
- Components::HelloWorld, Components::Todo, TopLevelRailsComponent
- Defined in:
- lib/react/component.rb,
lib/react/component/api.rb,
lib/react/component/base.rb,
lib/react/component/tags.rb,
lib/reactrb/deep-compare.rb,
lib/react/component/params.rb,
lib/react/component/class_methods.rb,
lib/react/component/props_wrapper.rb,
lib/react/component/dsl_instance_methods.rb,
lib/react/component/should_component_update.rb
Defined Under Namespace
Modules: API, ClassMethods, DslInstanceMethods, Params, ShouldComponentUpdate, Tags
Classes: Base, PropsWrapper
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#waiting_on_resources ⇒ Object
Returns the value of attribute waiting_on_resources.
100
101
102
|
# File 'lib/react/component.rb', line 100
def waiting_on_resources
@waiting_on_resources
end
|
Class Method Details
.deprecation_warning(message) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/react/component.rb', line 33
def self.deprecation_warning(message)
@deprecation_messages ||= []
message = "Warning: Deprecated feature used in #{name}. #{message}"
unless @deprecation_messages.include? message
@deprecation_messages << message
IsomorphicHelpers.log message, :warning
end
end
|
.included(base) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/react/component.rb', line 15
def self.included(base)
base.include(API)
base.include(Callbacks)
base.include(Tags)
base.include(DslInstanceMethods)
base.include(ShouldComponentUpdate)
base.class_eval do
class_attribute :initial_state
define_callback :before_mount
define_callback :after_mount
define_callback :before_receive_props
define_callback :before_update
define_callback :after_update
define_callback :before_unmount
end
base.extend(ClassMethods)
end
|
Instance Method Details
#_render_wrapper ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/react/component.rb', line 118
def _render_wrapper
State.set_state_context_to(self, true) do
element = React::RenderingContext.render(nil) { render || '' }
@waiting_on_resources =
element.waiting_on_resources if element.respond_to? :waiting_on_resources
element
end
rescue Exception => e
self.class.process_exception(e, self)
end
|
#component_did_update(prev_props, prev_state) ⇒ Object
#component_will_mount ⇒ Object
#component_will_receive_props(next_props) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/react/component.rb', line 68
def component_will_receive_props(next_props)
State.set_state_context_to(self) { self.run_callback(:before_receive_props, Hash.new(next_props)) }
rescue Exception => e
self.class.process_exception(e, self)
end
|
#component_will_unmount ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'lib/react/component.rb', line 91
def component_will_unmount
State.set_state_context_to(self) do
self.run_callback(:before_unmount)
State.remove
end
rescue Exception => e
self.class.process_exception(e, self)
end
|
#component_will_update(next_props, next_state) ⇒ Object
76
77
78
79
80
|
# File 'lib/react/component.rb', line 76
def component_will_update(next_props, next_state)
State.set_state_context_to(self) { self.run_callback(:before_update, Hash.new(next_props), Hash.new(next_state)) }
rescue Exception => e
self.class.process_exception(e, self)
end
|
#define_state(*args, &block) ⇒ Object
135
136
137
|
# File 'lib/react/component.rb', line 135
def define_state(*args, &block)
State.initialize_states(self, self.class.define_state(*args, &block))
end
|
#deprecated_params_method(name, *args, &block) ⇒ Object
4
5
6
7
|
# File 'lib/react/component/props_wrapper.rb', line 4
def deprecated_params_method(name, *args, &block)
React::Component.deprecation_warning"Direct access to param `#{name}`. Use `params.#{name}` instead."
params.send(name, *args, &block)
end
|
#emit(event_name, *args) ⇒ Object
46
47
48
|
# File 'lib/react/component.rb', line 46
def emit(event_name, *args)
params["_on#{event_name.to_s.event_camelize}"].call(*args)
end
|
#initialize(native_element) ⇒ Object
42
43
44
|
# File 'lib/react/component.rb', line 42
def initialize(native_element)
@native = native_element
end
|
114
115
116
|
# File 'lib/react/component.rb', line 114
def render
raise 'no render defined'
end
|
#update_react_js_state(object, name, value) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/react/component.rb', line 102
def update_react_js_state(object, name, value)
if object
name = "#{object.class}.#{name}" unless object == self
set_state(
'***_state_updated_at-***' => Time.now.to_f,
name => value
)
else
set_state name => value
end
end
|
#watch(value, &on_change) ⇒ Object
131
132
133
|
# File 'lib/react/component.rb', line 131
def watch(value, &on_change)
Observable.new(value, on_change)
end
|