lib/isomorfeus/preact/config.rb in isomorfeus-preact-10.9.0 vs lib/isomorfeus/preact/config.rb in isomorfeus-preact-22.9.0.rc1
- old
+ new
@@ -1,16 +1,16 @@
module Isomorfeus
if RUBY_ENGINE == 'opal'
class << self
attr_accessor :browser_history
- attr_accessor :current_user_sid
+ attr_accessor :browser_location
+ attr_accessor :current_user_sid_s
attr_accessor :initial_state_fetched
- attr_accessor :top_component
attr_accessor :ssr_response_status
+ attr_accessor :top_component
attr_reader :initialized
attr_reader :env
- attr_accessor :zeitwerk
def init
return if initialized
@initialized = true
Isomorfeus.init_store
@@ -21,79 +21,68 @@
@initialized = true
Isomorfeus.force_init_store!
execute_init_classes
end
- def add_client_init_class_name(init_class_name)
- client_init_class_names << init_class_name
+ def start_app!
+ Isomorfeus.zeitwerk.setup
+ Isomorfeus::TopLevel.mount!
end
- def add_client_init_after_store_class_name(init_class_name)
- client_init_after_store_class_names << init_class_name
+ def force_render
+ root_element = `document.querySelector('div[data-iso-root]')`
+ Preact.unmount_component_at_node(root_element)
+ Isomorfeus::TopLevel.do_the_mount!(init: false)
+ nil
+ rescue Exception => e
+ `console.error("force_render failed'! Error: " + #{e.message} + "! Reloading page.")`
+ `location.reload()`
end
+ end
+ else # RUBY_ENGINE
+ class << self
+ attr_reader :component_cache_init_block
+ attr_accessor :server_side_rendering
+ attr_accessor :ssr_hot_asset_url
- def add_client_option(key, value = nil)
- self.class.attr_accessor(key)
- self.send("#{key}=", value)
+ def ssr_response_status
+ Thread.current[:@_isomorfeus_preact_ssr_response_status]
end
- def execute_init_classes
- client_init_class_names.each do |constant|
- constant.constantize.send(:init)
- end
+ def ssr_response_status=(s)
+ Thread.current[:@_isomorfeus_preact_ssr_response_status] = s
end
- def execute_init_after_store_classes
- client_init_after_store_class_names.each do |constant_name|
- constant_name.constantize.send(:init)
- end
+ def init
+ return if Thread.current[:@_isomorfeus_initialized]
+ Thread.current[:@_isomorfeus_initialized] = true
+ Isomorfeus.init_store
+ execute_init_classes
end
- # server side env is set in isomorfeus-asset-manager
- def env=(env_string)
- @env = env_string ? env_string : 'development'
- @development = (@env == 'development') ? true : false
- @production = (@env == 'production') ? true : false
- @test = (@env == 'test') ? true : false
+ def force_init!
+ Thread.current[:@_isomorfeus_initialized] = true
+ Isomorfeus.force_init_store!
+ execute_init_classes
end
- def development?
- @development
+ def browser_history
+ @_isomorfeus_browser_history
end
- def production?
- @production
+ def browser_history=(h)
+ @_isomorfeus_browser_history = h
end
- def test?
- @test
+ def browser_location
+ Thread.current[:@_isomorfeus_browser_location]
end
- def start_app!
- Isomorfeus.zeitwerk.setup
- Isomorfeus::TopLevel.mount! unless on_ssr?
+ def browser_location=(l)
+ Thread.current[:@_isomorfeus_browser_location] = l
end
- 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
- end
-
- self.add_client_option(:client_init_class_names, [])
- self.add_client_option(:client_init_after_store_class_names, [])
- else
- class << self
- attr_reader :component_cache_init_block
- attr_accessor :server_side_rendering
- attr_accessor :ssr_hot_asset_url
- attr_accessor :zeitwerk
- attr_accessor :zeitwerk_lock
-
def component_cache_init(&block)
@component_cache_init_block = block
end
def configuration(&block)
@@ -112,18 +101,17 @@
Dir.glob(File.join(directory, '*.rb')).sort.each do |file|
require File.expand_path(file)
end
end
end
- end
+ end # RUBY_ENGINE
class << self
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