Module: Isomorfeus

Defined in:
lib/isomorfeus/top_level.rb,
lib/isomorfeus/react/config.rb,
lib/isomorfeus/top_level_ssr.rb,
lib/isomorfeus/props/validator.rb,
lib/isomorfeus/react_view_helper.rb,
lib/isomorfeus/props/validate_hash_proxy.rb,
lib/isomorfeus/react/redis_component_cache.rb,
lib/isomorfeus/react/memcached_component_cache.rb,
lib/isomorfeus/react/thread_local_component_cache.rb

Defined Under Namespace

Modules: Professional, Props, ReactViewHelper Classes: ThreadLocalComponentCache, TopLevel

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.component_cache_init_blockObject (readonly)

Returns the value of attribute component_cache_init_block.



112
113
114
# File 'lib/isomorfeus/react/config.rb', line 112

def component_cache_init_block
  @component_cache_init_block
end

.current_user_sidObject

Returns the value of attribute current_user_sid.



4
5
6
# File 'lib/isomorfeus/react/config.rb', line 4

def current_user_sid
  @current_user_sid
end

.envObject

Returns the value of attribute env.



9
10
11
# File 'lib/isomorfeus/react/config.rb', line 9

def env
  @env
end

.initial_state_fetchedObject

Returns the value of attribute initial_state_fetched.



5
6
7
# File 'lib/isomorfeus/react/config.rb', line 5

def initial_state_fetched
  @initial_state_fetched
end

.initializedObject (readonly)

Returns the value of attribute initialized.



8
9
10
# File 'lib/isomorfeus/react/config.rb', line 8

def initialized
  @initialized
end

.server_side_renderingObject

Returns the value of attribute server_side_rendering.



113
114
115
# File 'lib/isomorfeus/react/config.rb', line 113

def server_side_rendering
  @server_side_rendering
end

.ssr_hot_asset_urlObject

Returns the value of attribute ssr_hot_asset_url.



114
115
116
# File 'lib/isomorfeus/react/config.rb', line 114

def ssr_hot_asset_url
  @ssr_hot_asset_url
end

.ssr_response_statusObject

Returns the value of attribute ssr_response_status.



7
8
9
# File 'lib/isomorfeus/react/config.rb', line 7

def ssr_response_status
  @ssr_response_status
end

.top_componentObject

Returns the value of attribute top_component.



6
7
8
# File 'lib/isomorfeus/react/config.rb', line 6

def top_component
  @top_component
end

.zeitwerkObject

Returns the value of attribute zeitwerk.



10
11
12
# File 'lib/isomorfeus/react/config.rb', line 10

def zeitwerk
  @zeitwerk
end

.zeitwerk_lockObject

Returns the value of attribute zeitwerk_lock.



117
118
119
# File 'lib/isomorfeus/react/config.rb', line 117

def zeitwerk_lock
  @zeitwerk_lock
end

Class Method Details

.add_client_init_after_store_class_name(init_class_name) ⇒ Object



32
33
34
# File 'lib/isomorfeus/react/config.rb', line 32

def add_client_init_after_store_class_name(init_class_name)
  client_init_after_store_class_names << init_class_name
end

.add_client_init_class_name(init_class_name) ⇒ Object



28
29
30
# File 'lib/isomorfeus/react/config.rb', line 28

def add_client_init_class_name(init_class_name)
  client_init_class_names << init_class_name
end

.add_client_option(key, value = nil) ⇒ Object



36
37
38
39
# File 'lib/isomorfeus/react/config.rb', line 36

def add_client_option(key, value = nil)
  self.class.attr_accessor(key)
  self.send("#{key}=", value)
end

.cached_component_class(class_name) ⇒ Object

only used for SSR



47
48
49
50
# File 'lib/isomorfeus/react/config.rb', line 47

def cached_component_class(class_name)
  return cached_component_classes[class_name] if cached_component_classes.key?(class_name)
  cached_component_classes[class_name] = "::#{class_name}".constantize
end

.cached_component_classesObject

only used for SSR



42
43
44
# File 'lib/isomorfeus/react/config.rb', line 42

def cached_component_classes
  @cached_component_classes ||= {}
end

.component_cache_init(&block) ⇒ Object



119
120
121
# File 'lib/isomorfeus/react/config.rb', line 119

def component_cache_init(&block)
  @component_cache_init_block = block
end

.configuration(&block) ⇒ Object



123
124
125
# File 'lib/isomorfeus/react/config.rb', line 123

def configuration(&block)
  block.call(self)
end

.development?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/isomorfeus/react/config.rb', line 71

def development?
  @development
end

.execute_init_after_store_classesObject



58
59
60
61
62
# File 'lib/isomorfeus/react/config.rb', line 58

def execute_init_after_store_classes
  client_init_after_store_class_names.each do |constant|
    constant.constantize.send(:init)
  end
end

.execute_init_classesObject



52
53
54
55
56
# File 'lib/isomorfeus/react/config.rb', line 52

def execute_init_classes
  client_init_class_names.each do |constant|
    constant.constantize.send(:init)
  end
end

.force_init!Object



19
20
21
22
23
24
25
26
# File 'lib/isomorfeus/react/config.rb', line 19

def force_init!
  unless Isomorfeus.initial_state_fetched
    Isomorfeus.initial_state_fetched = true
    Redux::Store.preloaded_state = Isomorfeus.store.get_state
  end
  Isomorfeus.force_init_store!
  execute_init_classes
end

.force_renderObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/isomorfeus/react/config.rb', line 88

def force_render
  begin
    if Isomorfeus.top_component
      ReactDOM.find_dom_node(Isomorfeus.top_component) if on_browser? || on_desktop? # if not mounted will raise
      if `typeof Opal.global.deepForceUpdate === 'undefined'`
        Isomorfeus.top_component.JS.forceUpdate()
      else
        `Opal.global.deepForceUpdate(#{Isomorfeus.top_component})`
      end
    end
  rescue Exception => e
    # TODO try mount first
    # if it fails
    `console.error("force_render failed'! Error: " + #{e.message} + "! Reloading page.")`
    `location.reload()` if on_browser?
  end
  nil
end

.initObject



12
13
14
15
16
17
# File 'lib/isomorfeus/react/config.rb', line 12

def init
  return if initialized
  @initialized = true
  Isomorfeus.init_store
  execute_init_classes
end

.load_configuration(directory) ⇒ Object



154
155
156
157
158
# File 'lib/isomorfeus/react/config.rb', line 154

def load_configuration(directory)
  Dir.glob(File.join(directory, '*.rb')).sort.each do |file|
    require File.expand_path(file)
  end
end

.production?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/isomorfeus/react/config.rb', line 75

def production?
  @production
end

.raise_error(error_class: nil, message: nil, stack: nil) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/isomorfeus/react/config.rb', line 163

def raise_error(error_class: nil, message: nil, stack: nil)
  error_class = RuntimeError unless error_class
  execution_environment = if on_browser? then 'on Browser'
                          elsif on_ssr? then 'in Server Side Rendering'
                          elsif on_server? then 'on Server'
                          elsif on_mobile? then 'on Mobile'
                          elsif on_database? then 'on Database'
                          else
                            'on Client'
                          end
  error = error_class.new("Isomorfeus in #{env} #{execution_environment}:\n#{message}")
  error.set_backtrace(stack) if stack

  if Isomorfeus.development?
    if RUBY_ENGINE == 'opal'
      ecn = error_class ? error_class.name : ''
      m = message ? message : ''
      s = stack ? stack : ''
      `console.error(ecn, m, s)`
    else
      STDERR.puts "#{ecn}: #{m}\n #{s}"
    end
  end
  raise error
end

.ssr_contextsObject



146
147
148
# File 'lib/isomorfeus/react/config.rb', line 146

def ssr_contexts
  @ssr_contexts ||= {}
end

.start_app!Object



83
84
85
86
# File 'lib/isomorfeus/react/config.rb', line 83

def start_app!
  Isomorfeus.zeitwerk.setup
  Isomorfeus::TopLevel.mount!
end

.test?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/isomorfeus/react/config.rb', line 79

def test?
  @test
end

.versionObject



150
151
152
# File 'lib/isomorfeus/react/config.rb', line 150

def version
  Isomorfeus::VERSION
end