Sha256: 42857fb5ec29b55e8284552d4a516d9040db4500ad1c907d95338b3911fd582f

Contents?: true

Size: 929 Bytes

Versions: 16

Compression:

Stored size: 929 Bytes

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
      # Make this configurable at some point
      'components'
    end

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

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

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
reactrb-0.8.6 lib/reactive-ruby/component_loader.rb
reactrb-0.8.5 lib/reactive-ruby/component_loader.rb
reactrb-0.8.4 lib/reactive-ruby/component_loader.rb
reactrb-0.8.3 lib/reactive-ruby/component_loader.rb
reactrb-0.8.1 lib/reactive-ruby/component_loader.rb
reactrb-0.8.0 lib/reactive-ruby/component_loader.rb
reactrb-0.7.42 lib/reactive-ruby/component_loader.rb
reactive-ruby-0.7.41 lib/reactive-ruby/component_loader.rb
reactive-ruby-0.7.40 lib/reactive-ruby/component_loader.rb
reactive-ruby-0.7.39 lib/reactive-ruby/component_loader.rb
reactive-ruby-0.7.38 lib/reactive-ruby/component_loader.rb
reactive-ruby-0.7.36 lib/reactive-ruby/component_loader.rb
reactive-ruby-0.7.35 lib/reactive-ruby/component_loader.rb
reactive-ruby-0.7.34 lib/reactive-ruby/component_loader.rb
reactive-ruby-0.7.33 lib/reactive-ruby/component_loader.rb
reactive-ruby-0.7.32 lib/reactive-ruby/component_loader.rb