Module: Isomorfeus

Defined in:
lib/isomorfeus/config.rb,
lib/isomorfeus/top_level.rb,
lib/isomorfeus/top_level_ssr.rb,
lib/isomorfeus/vivify_module.rb,
lib/isomorfeus/props/validator.rb,
lib/isomorfeus/react_view_helper.rb,
lib/isomorfeus/thread_local_cache.rb,
lib/isomorfeus/props/validate_hash_proxy.rb

Defined Under Namespace

Modules: Props, ReactViewHelper Classes: ThreadLocalCache, TopLevel, VivifyModule

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.component_cache_classObject

Returns the value of attribute component_cache_class.



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

def component_cache_class
  @component_cache_class
end

.envObject

Returns the value of attribute env.



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

def env
  @env
end

.initial_state_fetchedObject

Returns the value of attribute initial_state_fetched.



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

def initial_state_fetched
  @initial_state_fetched
end

.initializedObject (readonly)

Returns the value of attribute initialized.



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

def initialized
  @initialized
end

.server_side_renderingObject

Returns the value of attribute server_side_rendering.



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

def server_side_rendering
  @server_side_rendering
end

.ssr_hot_asset_urlObject

Returns the value of attribute ssr_hot_asset_url.



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

def ssr_hot_asset_url
  @ssr_hot_asset_url
end

.ssr_response_statusObject

Returns the value of attribute ssr_response_status.



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

def ssr_response_status
  @ssr_response_status
end

.top_componentObject

Returns the value of attribute top_component.



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

def top_component
  @top_component
end

.zeitwerkObject

Returns the value of attribute zeitwerk.



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

def zeitwerk
  @zeitwerk
end

.zeitwerk_lockObject

Returns the value of attribute zeitwerk_lock.



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

def zeitwerk_lock
  @zeitwerk_lock
end

Class Method Details

.add_client_init_after_store_class_name(init_class_name) ⇒ Object



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

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



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

def add_client_init_class_name(init_class_name)
  client_init_class_names << init_class_name
end

.add_client_option(key, value = nil) ⇒ Object



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

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



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

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



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

def cached_component_classes
  @cached_component_classes ||= {}
end

.configuration(&block) ⇒ Object



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

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

.development?Boolean

Returns:

  • (Boolean)


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

def development?
  @development
end

.execute_init_after_store_classesObject



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

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

.execute_init_classesObject



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

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

.force_init!Object



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

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



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

def force_render
  begin
    if Isomorfeus.top_component
      ReactDOM.find_dom_node(Isomorfeus.top_component) # 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



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

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

.production?Boolean

Returns:

  • (Boolean)


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

def production?
  @production
end

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



152
153
154
155
156
157
158
159
160
161
# File 'lib/isomorfeus/config.rb', line 152

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'
                          end
  error = error_class.new("Isomorfeus in #{env} #{execution_environment}:\n#{message}")
  error.set_backtrace(stack) if stack
  raise error
end

.ssr_contextsObject



141
142
143
# File 'lib/isomorfeus/config.rb', line 141

def ssr_contexts
  @ssr_contexts ||= {}
end

.start_app!Object



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

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

.test?Boolean

Returns:

  • (Boolean)


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

def test?
  @test
end

.versionObject



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

def version
  Isomorfeus::VERSION
end