Module: Isomorfeus

Defined in:
lib/isomorfeus/top_level.rb,
lib/isomorfeus/preact/config.rb,
lib/isomorfeus/preact/imports.rb,
lib/isomorfeus/props/validator.rb,
lib/isomorfeus/preact_view_helper.rb,
lib/isomorfeus/preact/ssr/top_level.rb,
lib/isomorfeus/preact/ssr/render_core.rb,
lib/isomorfeus/props/validate_hash_proxy.rb,
lib/isomorfeus/preact/redis_component_cache.rb,
lib/isomorfeus/preact/memcached_component_cache.rb,
lib/isomorfeus/preact/thread_local_component_cache.rb

Defined Under Namespace

Modules: Preact, PreactViewHelper, Props, SSR Classes: TopLevel

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.browser_historyObject

Returns the value of attribute browser_history.



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

def browser_history
  @browser_history
end

.component_cache_init_blockObject (readonly)

Returns the value of attribute component_cache_init_block.



89
90
91
# File 'lib/isomorfeus/preact/config.rb', line 89

def component_cache_init_block
  @component_cache_init_block
end

.current_user_sidObject

Returns the value of attribute current_user_sid.



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

def current_user_sid
  @current_user_sid
end

.envObject

Returns the value of attribute env.



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

def env
  @env
end

.initial_state_fetchedObject

Returns the value of attribute initial_state_fetched.



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

def initial_state_fetched
  @initial_state_fetched
end

.initializedObject (readonly)

Returns the value of attribute initialized.



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

def initialized
  @initialized
end

.server_side_renderingObject

Returns the value of attribute server_side_rendering.



90
91
92
# File 'lib/isomorfeus/preact/config.rb', line 90

def server_side_rendering
  @server_side_rendering
end

.ssr_hot_asset_urlObject

Returns the value of attribute ssr_hot_asset_url.



91
92
93
# File 'lib/isomorfeus/preact/config.rb', line 91

def ssr_hot_asset_url
  @ssr_hot_asset_url
end

.ssr_response_statusObject

Returns the value of attribute ssr_response_status.



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

def ssr_response_status
  @ssr_response_status
end

.top_componentObject

Returns the value of attribute top_component.



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

def top_component
  @top_component
end

.zeitwerkObject

Returns the value of attribute zeitwerk.



11
12
13
# File 'lib/isomorfeus/preact/config.rb', line 11

def zeitwerk
  @zeitwerk
end

.zeitwerk_lockObject

Returns the value of attribute zeitwerk_lock.



93
94
95
# File 'lib/isomorfeus/preact/config.rb', line 93

def zeitwerk_lock
  @zeitwerk_lock
end

Class Method Details

.add_client_init_after_store_class_name(init_class_name) ⇒ Object



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

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



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

def add_client_init_class_name(init_class_name)
  client_init_class_names << init_class_name
end

.add_client_option(key, value = nil) ⇒ Object



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

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

.component_cache_init(&block) ⇒ Object



95
96
97
# File 'lib/isomorfeus/preact/config.rb', line 95

def component_cache_init(&block)
  @component_cache_init_block = block
end

.configuration(&block) ⇒ Object



99
100
101
# File 'lib/isomorfeus/preact/config.rb', line 99

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

.development?Boolean

Returns:

  • (Boolean)


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

def development?
  @development
end

.execute_init_after_store_classesObject



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

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

.execute_init_classesObject



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

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

.force_init!Object



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

def force_init!
  @initialized = true
  Isomorfeus.force_init_store!
  execute_init_classes
end

.force_renderObject



76
77
78
79
80
81
82
# File 'lib/isomorfeus/preact/config.rb', line 76

def force_render
  `Opal.Preact.deep_force_update(#{Isomorfeus.top_component})`
  nil
rescue Exception => e
  `console.error("force_render failed'! Error: " + #{e.message} + "! Reloading page.")`
  `location.reload()` if on_browser?
end

.initObject



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

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

.load_configuration(directory) ⇒ Object



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

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)


63
64
65
# File 'lib/isomorfeus/preact/config.rb', line 63

def production?
  @production
end

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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/isomorfeus/preact/config.rb', line 120

def raise_error(error: nil, error_class: nil, message: nil, stack: nil)
  error_class = error.class if error

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

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

.ssr_contextsObject



103
104
105
# File 'lib/isomorfeus/preact/config.rb', line 103

def ssr_contexts
  @ssr_contexts ||= {}
end

.start_app!Object



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

def start_app!
  Isomorfeus.zeitwerk.setup
  Isomorfeus::TopLevel.mount! unless on_ssr?
end

.test?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/isomorfeus/preact/config.rb', line 67

def test?
  @test
end

.versionObject



107
108
109
# File 'lib/isomorfeus/preact/config.rb', line 107

def version
  Isomorfeus::VERSION
end