Class: React::IsomorphicHelpers::Context

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unique_id, ctx = nil, controller = nil, name = nil) ⇒ Context

Returns a new instance of Context.



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 106

def initialize(unique_id, ctx = nil, controller = nil, name = nil)
  @unique_id = unique_id
  if RUBY_ENGINE != 'opal'
    @controller = controller
    @ctx = ctx
    ctx["ServerSideIsomorphicMethods"] = self
    send_to_opal(:load_context, @unique_id, name)
  end
  Hyperloop::Application::Boot.run(context: self)
  self.class.before_first_mount_blocks.each { |block| block.call(self) }
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



95
96
97
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 95

def controller
  @controller
end

#unique_idObject (readonly)

Returns the value of attribute unique_id.



96
97
98
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 96

def unique_id
  @unique_id
end

Class Method Details

.before_first_mount_blocksObject



98
99
100
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 98

def self.before_first_mount_blocks
  @before_first_mount_blocks ||= []
end


102
103
104
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 102

def self.prerender_footer_blocks
  @prerender_footer_blocks ||= []
end

.register_before_first_mount_block(&block) ⇒ Object



129
130
131
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 129

def self.register_before_first_mount_block(&block)
  before_first_mount_blocks << block
end


133
134
135
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 133

def self.register_prerender_footer_block(&block)
  prerender_footer_blocks << block
end

Instance Method Details

#eval(js) ⇒ Object



118
119
120
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 118

def eval(js)
  @ctx.eval(js) if @ctx
end

#send_to_opal(method, *args) ⇒ Object



122
123
124
125
126
127
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 122

def send_to_opal(method, *args)
  return unless @ctx
  args = [1] if args.length == 0
  ::ReactiveRuby::ComponentLoader.new(@ctx).load!
  @ctx.eval("Opal.React.$const_get('IsomorphicHelpers').$#{method}(#{args.collect { |arg| "'#{arg}'"}.join(', ')})")
end