Class: Hyperloop::Console::DebugConsole

Inherits:
Hyperloop::Component show all
Defined in:
lib/hyperloop/console/client_components.rb

Constant Summary

Constants inherited from Hyperloop::Component

Hyperloop::Component::VERSION

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.application_window_idObject

Returns the value of attribute application_window_id.



12
13
14
# File 'lib/hyperloop/console/client_components.rb', line 12

def application_window_id
  @application_window_id
end

.contextObject

Returns the value of attribute context.



13
14
15
# File 'lib/hyperloop/console/client_components.rb', line 13

def context
  @context
end

Class Method Details

.console_idObject



15
16
17
18
19
20
21
# File 'lib/hyperloop/console/client_components.rb', line 15

def console_id
  @console_id ||=
    (
      `sessionStorage.getItem('Hyperloop::Console::ConsoleId')` ||
      SecureRandom.uuid.tap { |id| `sessionStorage.setItem('Hyperloop::Console::ConsoleId', #{id})` }
    )
end

.evaluate(compiled_code) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/hyperloop/console/client_components.rb', line 29

def evaluate(compiled_code)
  @code_to_send = @code_to_send[0..-2]
  mutate.history << {eval: @code_to_send}
  mutate.console_state :sending
  # if using actioncable with opal_hot_reloader the connection will close
  # so this hack will reopen the connection before sending the message.
  HTTP.get("#{`window.HyperloopEnginePath`}/server_up") do
    `#{Hyperloop.action_cable_consumer}.connection.open()` if Hyperloop.action_cable_consumer && `#{Hyperloop.action_cable_consumer}.connection.disconnected`
    Evaluate.run target_id: application_window_id, sender_id: console_id, context: context, string: compiled_code
  end
end

.ready!(code, compiled_code) ⇒ Object



23
24
25
26
27
# File 'lib/hyperloop/console/client_components.rb', line 23

def ready!(code, compiled_code)
  @code_to_send = code
  mutate.error_message nil
  evaluate compiled_code if @code_to_send =~ /.\n$/
end