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 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/react/top_level_rails_component.rb', line 31 def component return @component if @component paths_searched = [] if params.component_name.start_with?('::') paths_searched << params.component_name.gsub(/^\:\:/, '') @component = begin params.component_name.gsub(/^\:\:/, '').split('::') .inject(Module) { |scope, next_const| scope.const_get(next_const, false) } rescue nil end return @component if @component && @component.method_defined?(:render) else self.class.search_path.each do |path| # try each path + params.controller + params.component_name paths_searched << "#{path.name + '::' unless path == Module}"\ "#{params.controller}::#{params.component_name}" @component = begin [params.controller, params.component_name] .join('::').split('::') .inject(path) { |scope, next_const| scope.const_get(next_const, false) } rescue nil end return @component if @component && @component.method_defined?(:render) end self.class.search_path.each do |path| # then try each path + params.component_name paths_searched << "#{path.name + '::' unless path == Module}#{params.component_name}" @component = begin params.component_name.to_s.split('::') .inject(path) { |scope, next_const| scope.const_get(next_const, false) } rescue nil end return @component if @component && @component.method_defined?(:render) end end @component = nil 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
100 101 102 |
# File 'lib/react/top_level_rails_component.rb', line 100 def render present component, @render_params end |