Sha256: e0dd70e1bb0152194bf9f986c693ee745087bde430a3e67449608571ec1c67d4

Contents?: true

Size: 1.36 KB

Versions: 19

Compression:

Stored size: 1.36 KB

Contents

module ReactiveRuby
  module Rails
    class ComponentMount < React::Rails::ComponentMount
      attr_accessor :controller

      def setup(controller)
        self.controller = controller
      end

      def react_component(name, props = {}, options = {}, &block)
        options = context_initializer_options(options, name) if options[:prerender]
        props = serialized_props(props, name, controller)
        super(top_level_name, props, options, &block) + footers
      end

      private

      def context_initializer_options(options, name)
        options[:prerender] = {options[:prerender] => true} unless options[:prerender].is_a? Hash
        existing_context_initializer = options[:prerender][:context_initializer]

        options[:prerender][:context_initializer] = lambda do |ctx|
          React::IsomorphicHelpers.load_context(ctx, controller, name)
          existing_context_initializer.call ctx if existing_context_initializer
        end

        options
      end

      def serialized_props(props, name, controller)
        { render_params: props, component_name: name,
          controller: controller.class.name.gsub(/Controller$/,"") }.react_serializer
      end

      def top_level_name
        'React.TopLevelRailsComponent'
      end

      def footers
        React::IsomorphicHelpers.prerender_footers #if options[:prerender]
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
reactrb-0.8.3 lib/reactive-ruby/rails/component_mount.rb
reactrb-0.8.1 lib/reactive-ruby/rails/component_mount.rb
reactrb-0.8.0 lib/reactive-ruby/rails/component_mount.rb
reactrb-0.7.42 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.41 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.40 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.39 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.38 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.36 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.35 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.34 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.33 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.32 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.31 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.30 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.29 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.28 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.27 lib/reactive-ruby/rails/component_mount.rb
reactive-ruby-0.7.26 lib/reactive-ruby/rails/component_mount.rb