Class: ReactiveRuby::ComponentLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/reactive-ruby/component_loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(v8_context) ⇒ ComponentLoader

Returns a new instance of ComponentLoader.



6
7
8
9
10
11
# File 'lib/reactive-ruby/component_loader.rb', line 6

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

Instance Method Details

#load(file = components) ⇒ Object



13
14
15
16
# File 'lib/reactive-ruby/component_loader.rb', line 13

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

#load!(file = components) ⇒ Object



18
19
20
21
22
23
# File 'lib/reactive-ruby/component_loader.rb', line 18

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

#loaded?Boolean

Returns:



25
26
27
28
29
# File 'lib/reactive-ruby/component_loader.rb', line 25

def loaded?
  !!v8_context.eval('Opal.React !== undefined')
rescue ::ExecJS::Error
  false
end