lib/react/rails/railtie.rb in react-rails-1.2.0 vs lib/react/rails/railtie.rb in react-rails-1.3.0
- old
+ new
@@ -2,38 +2,51 @@
module React
module Rails
class Railtie < ::Rails::Railtie
config.react = ActiveSupport::OrderedOptions.new
-
# Sensible defaults. Can be overridden in application.rb
config.react.variant = (::Rails.env.production? ? :production : :development)
config.react.addons = false
config.react.jsx_transform_options = {}
config.react.jsx_transformer_class = nil # defaults to BabelTransformer
# Server rendering:
config.react.server_renderer_pool_size = 1 # increase if you're on JRuby
config.react.server_renderer_timeout = 20 # seconds
config.react.server_renderer = nil # defaults to SprocketsRenderer
config.react.server_renderer_options = {} # SprocketsRenderer provides defaults
+ # View helper implementation:
+ config.react.view_helper_implementation = nil # Defaults to ComponentMount
# Watch .jsx files for changes in dev, so we can reload the JS VMs with the new JS code.
initializer "react_rails.add_watchable_files", group: :all do |app|
app.config.watchable_files.concat Dir["#{app.root}/app/assets/javascripts/**/*.jsx*"]
end
# Include the react-rails view helper lazily
initializer "react_rails.setup_view_helpers", group: :all do |app|
+ app.config.middleware.use(::React::Rails::RenderMiddleware)
app.config.react.jsx_transformer_class ||= React::JSX::DEFAULT_TRANSFORMER
React::JSX.transformer_class = app.config.react.jsx_transformer_class
React::JSX.transform_options = app.config.react.jsx_transform_options
+ app.config.react.view_helper_implementation ||= React::Rails::ComponentMount
+ React::Rails::ViewHelper.helper_implementation_class = app.config.react.view_helper_implementation
ActiveSupport.on_load(:action_view) do
include ::React::Rails::ViewHelper
end
end
+ initializer "react_rails.add_component_renderer", group: :all do |app|
+ ActionController::Renderers.add :component do |component_name, options|
+ renderer = ::React::Rails::ControllerRenderer.new(request: request)
+ html = renderer.call(component_name, options)
+ render_options = options.merge(inline: html)
+ render(render_options)
+ end
+ end
+
initializer "react_rails.bust_cache", group: :all do |app|
asset_variant = React::Rails::AssetVariant.new({
variant: app.config.react.variant,
addons: app.config.react.addons,
})
@@ -41,10 +54,10 @@
sprockets_env = app.assets || app.config.assets # sprockets-rails 3.x attaches this at a different config
sprockets_env.version = [sprockets_env.version, "react-#{asset_variant.react_build}",].compact.join('-')
end
- config.before_initialize do |app|
+ initializer "react_rails.set_variant", after: :engines_blank_point, group: :all do |app|
asset_variant = React::Rails::AssetVariant.new({
variant: app.config.react.variant,
addons: app.config.react.addons,
})