Sha256: 0a02b9e5529d3c4638877d0cb73153498a9c59e07729a7847a4e9441ebb2a72b

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

module ReactiveRuby
  class ComponentLoader
    attr_reader :v8_context
    private :v8_context

    def initialize(v8_context)
      unless v8_context
        raise ArgumentError.new('Could not obtain ExecJS runtime context')
      end
      @v8_context = v8_context
    end

    def load(file = components)
      return true if loaded?
      !!v8_context.eval(opal(file))
    end

    def load!(file = components)
      return true if loaded?
      self.load(file)
    ensure
      raise "No react.rb components found in #{components}.rb" unless loaded?
    end

    def loaded?
      !!v8_context.eval('Opal.React')
    end

    private

    def components
      opts = ::Rails.configuration.react.server_renderer_options
      return opts[:files].first.gsub(/.js$/,'') if opts && opts[:files]
      'components'
    end

    def opal(file)
      if Opal::Processor.respond_to?(:load_asset_code)
        Opal::Processor.load_asset_code(assets, file)
      else
        Opal::Sprockets.load_asset(file, assets)
      end
    rescue # What exception is being caught here?
    end

    def assets
      ::Rails.application.assets
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hyper-react-0.12.7 lib/reactive-ruby/component_loader.rb
hyper-react-0.12.6 lib/reactive-ruby/component_loader.rb
hyper-react-0.12.5 lib/reactive-ruby/component_loader.rb
hyper-react-0.12.4 lib/reactive-ruby/component_loader.rb
hyper-react-0.12.3 lib/reactive-ruby/component_loader.rb
hyper-react-0.12.2 lib/reactive-ruby/component_loader.rb
hyper-react-0.12.1 lib/reactive-ruby/component_loader.rb
hyper-react-0.12.0 lib/reactive-ruby/component_loader.rb