Module: React::IsomorphicHelpers

Defined in:
lib/reactive-ruby/isomorphic_helpers.rb

Defined Under Namespace

Modules: ClassMethods Classes: Context, IsomorphicProcCall

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.contextObject



33
34
35
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 33

def self.context
  @context
end

.included(base) ⇒ Object



5
6
7
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 5

def self.included(base)
  base.extend(ClassMethods)
end

.load_context(unique_id = nil, name = nil) ⇒ Object



10
11
12
13
14
15
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 10

def self.load_context(ctx, controller, name = nil)
  @context = Context.new("#{controller.object_id}-#{Time.now.to_i}", ctx, controller, name)
  @context.load_opal_context
  ::Rails.logger.debug "************************** React Server Context Initialized #{name} #{Time.now.to_f} *********************************************"
  @context
end

.log(message, message_type = :info) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 37

def self.log(message, message_type = :info)
  message = [message] unless message.is_a? Array

  if (message_type == :info || message_type == :warning) && Hyperloop.env.production?
    return
  end

  if message_type == :info
    if on_opal_server?
      style = 'background: #00FFFF; color: red'
    else
      style = 'background: #222; color: #bada55'
    end
    message = ["%c" + message[0], style]+message[1..-1]
    `console.log.apply(console, message)`
  elsif message_type == :warning
    `console.warn.apply(console, message)`
  else
    `console.error.apply(console, message)`
  end
end

.on_opal_client?Boolean

Returns:



64
65
66
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 64

def self.on_opal_client?
  false
end

.on_opal_server?Boolean

Returns:



60
61
62
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 60

def self.on_opal_server?
  false
end

.prerender_footers(controller = nil) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 89

def self.prerender_footers(controller = nil)
  footer = Context.prerender_footer_blocks.collect { |block| block.call controller }.join("\n")
  if RUBY_ENGINE != 'opal'
    footer = (footer + @context.send_to_opal(:prerender_footers).to_s) if @context
    footer = footer.html_safe
  end
  footer
end

Instance Method Details

#log(*args) ⇒ Object



77
78
79
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 77

def log(*args)
  IsomorphicHelpers.log(*args)
end

#on_opal_client?Boolean

Returns:



85
86
87
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 85

def on_opal_client?
  self.class.on_opal_client?
end

#on_opal_server?Boolean

Returns:



81
82
83
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 81

def on_opal_server?
  self.class.on_opal_server?
end