Sha256: ff98a70a9f55d72645c6c760ba00370a29d661e90af5d3fea324a1dff57aadff

Contents?: true

Size: 1.83 KB

Versions: 7

Compression:

Stored size: 1.83 KB

Contents

begin
  
  require 'react-rails'
  require 'reactive-ruby'
  
  class ActionController::Base

    def render_component(*args)
      @component_name = ((args[0].is_a? Hash) || args.empty?) ? params[:action].camelize : args.shift
      @render_params = (args[0].is_a? Hash) ? args[0] : {}
      render inline: "<%= react_component @component_name, @render_params, { prerender: !params[:no_prerender] } %>", layout: 'application'
    end

  end
  
  module React
    
    class Railtie < ::Rails::Railtie
      config.before_configuration do
        config.assets.enabled = true
        config.assets.paths << ::Rails.root.join('app', 'views').to_s
      end
    end
    
    module Rails
      module ViewHelper

        alias_method :pre_opal_react_component, :react_component

        def react_component(name, props = {}, render_options={}, &block)
          props = {render_params: props, component_name: name, controller: self.controller.class.name}
          name = 'React.TopLevelRailsComponent'
          if render_options[:prerender]
            render_options[:prerender] = {render_options[:prerender] => true} unless render_options[:prerender].is_a? Hash
            existing_context_initializer = render_options[:prerender][:context_initializer]
            render_options[:prerender][:context_initializer] = lambda do |ctx| 
              React::IsomorphicHelpers.load_context(ctx, self.controller, props[:component_name])
              existing_context_initializer.call ctx if existing_context_initializer
            end
            
          end
          component_rendering = raw(pre_opal_react_component(name, props.react_serializer, render_options, &block))
          footers = React::IsomorphicHelpers.prerender_footers #if render_options[:prerender]
          component_rendering+footers
        end
      end
    end
  end
  
rescue LoadError
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reactive-ruby-0.7.22 lib/rails-helpers/react_component.rb
reactive-ruby-0.7.21 lib/rails-helpers/react_component.rb
reactive-ruby-0.7.20 lib/rails-helpers/react_component.rb
reactive-ruby-0.7.19 lib/rails-helpers/react_component.rb
reactive-ruby-0.7.18 lib/rails-helpers/react_component.rb
reactive-ruby-0.7.17 lib/rails-helpers/react_component.rb
reactive-ruby-0.7.16 lib/rails-helpers/react_component.rb