Class: React::TopLevelRailsComponent
- Inherits:
-
Object
- Object
- React::TopLevelRailsComponent
- Defined in:
- lib/react/top_level_rails_component.rb
Class Attribute Summary collapse
-
.event_history ⇒ Object
Returns the value of attribute event_history.
Class Method Summary collapse
- .callback_history_for(proc_name) ⇒ Object
- .clear_callback_history_for(proc_name) ⇒ Object
- .clear_event_history_for(event_name) ⇒ Object
- .event_history_for(event_name) ⇒ Object
- .last_callback_for(proc_name) ⇒ Object
- .last_event_for(event_name) ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.event_history ⇒ Object
Returns the value of attribute event_history.
4 5 6 |
# File 'lib/react/top_level_rails_component.rb', line 4 def event_history @event_history end |
Class Method Details
.callback_history_for(proc_name) ⇒ Object
6 7 8 |
# File 'lib/react/top_level_rails_component.rb', line 6 def callback_history_for(proc_name) event_history[proc_name] end |
.clear_callback_history_for(proc_name) ⇒ Object
14 15 16 |
# File 'lib/react/top_level_rails_component.rb', line 14 def clear_callback_history_for(proc_name) event_history[proc_name] = [] end |
.clear_event_history_for(event_name) ⇒ Object
26 27 28 |
# File 'lib/react/top_level_rails_component.rb', line 26 def clear_event_history_for(event_name) event_history["_on#{event_name.event_camelize}"] = [] end |
.event_history_for(event_name) ⇒ Object
18 19 20 |
# File 'lib/react/top_level_rails_component.rb', line 18 def event_history_for(event_name) event_history["_on#{event_name.event_camelize}"] end |
.last_callback_for(proc_name) ⇒ Object
10 11 12 |
# File 'lib/react/top_level_rails_component.rb', line 10 def last_callback_for(proc_name) event_history[proc_name].last end |
.last_event_for(event_name) ⇒ Object
22 23 24 |
# File 'lib/react/top_level_rails_component.rb', line 22 def last_event_for(event_name) event_history["_on#{event_name.event_camelize}"].last end |
Instance Method Details
#component ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/react/top_level_rails_component.rb', line 31 def component return @component if @component paths_searched = [] component = nil if params.component_name.start_with?('::') # if absolute path of component is given, look it up and fail if not found paths_searched << params.component_name component = begin Object.const_get(params.component_name) rescue NameError nil end else # if relative path is given, look it up like this # 1) we check each path + controller-name + component-name # 2) if we can't find it there we check each path + component-name # if we can't find it we just try const_get # so (assuming controller name is Home) # ::Foo::Bar will only resolve to some component named ::Foo::Bar # but Foo::Bar will check (in this order) ::Home::Foo::Bar, ::Components::Home::Foo::Bar, ::Foo::Bar, ::Components::Foo::Bar self.class.search_path.each do |scope| paths_searched << "#{scope.name}::#{params.controller}::#{params.component_name}" component = begin scope.const_get(params.controller, false).const_get(params.component_name, false) rescue NameError nil end break if component != nil end unless component self.class.search_path.each do |scope| paths_searched << "#{scope.name}::#{params.component_name}" component = begin scope.const_get(params.component_name, false) rescue NameError nil end break if component != nil end end end @component = component return @component if @component && @component.method_defined?(:render) raise "Could not find component class '#{params.component_name}' for params.controller '#{params.controller}' in any component directory. Tried [#{paths_searched.join(", ")}]" end |
#render ⇒ Object
90 91 92 |
# File 'lib/react/top_level_rails_component.rb', line 90 def render React::RenderingContext.render(component, @render_params) end |