isomorfeus-preact 10.6.48 → 10.6.49

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df8ec0a8eda33bce33533c8c7f8ec7485574034aa647ad1e5a57387b23e801f7
4
- data.tar.gz: a29e92d4cc416139cc3ae2d27a31cfd68b8800a7090013d9fd2c173307340758
3
+ metadata.gz: ac176b7d030eed4294beeb72b72652408b2270d22a0bb9a840b2e7e6e54a503e
4
+ data.tar.gz: 02d28d07b2ea5051493bd26a986299ddc26bce85dfbef06a2693a2b5680065e9
5
5
  SHA512:
6
- metadata.gz: 694f965dc3c05541466f84e7fe0ca2b5612a277d4413bbdd4565985d89f0832cc28a7a78a4244a2ac417064949d5c6943eb0dd846adb6c37e68f30324ad5b9d0
7
- data.tar.gz: 5aa3ce6a0b8178712c7752aca97e96b4b25bc51affba39573a1acf8284e63f10ad69f71873f2509557aa0992fe4aa00d4c64ea595a126d672b577e8bf0758a1a
6
+ metadata.gz: 7f88f2d320dd5e3cb866607e91de65ddeb565df8aab74162d72d0c8b239c95548db9612df2c62948011646677469707682ebdfa71fc7d9c53775d1cd0083f70f
7
+ data.tar.gz: 691d9f6cd7e681cdbc402bcb16448f77c742ae0021bbb6f409d896042df6e3e3563d8c772bcbb6cac3ba82aa4f2bea88d8d6f0358dc8bd4dad29b03554317d1d
@@ -0,0 +1,31 @@
1
+ module Browser
2
+ class History
3
+ include Native::Wrapper
4
+
5
+ alias_native :back
6
+ alias_native :forward
7
+ alias_native :go
8
+
9
+ native_reader :length
10
+
11
+ def push_state(state, title = '', url = `null`)
12
+ `#@native.pushState(#{state.to_n}, #{title}, #{url})`
13
+ end
14
+
15
+ def replace_state(state, title = '', url = `null`)
16
+ `#@native.replaceState(#{state.to_n}, #{title}, #{url})`
17
+ end
18
+
19
+ def scroll_restoration
20
+ `#@native.scrollRestoration`
21
+ end
22
+
23
+ def scroll_restoration=(s)
24
+ `#@native.scrollRestoration = #{s}`
25
+ end
26
+
27
+ def state
28
+ ::Hash.new(`#@native.state`)
29
+ end
30
+ end
31
+ end
@@ -1,6 +1,7 @@
1
1
  module Isomorfeus
2
2
  if RUBY_ENGINE == 'opal'
3
3
  class << self
4
+ attr_accessor :browser_history
4
5
  attr_accessor :current_user_sid
5
6
  attr_accessor :initial_state_fetched
6
7
  attr_accessor :top_component
@@ -51,7 +51,7 @@ module Isomorfeus
51
51
  # build javascript for rendering first pass
52
52
  # it will initialize buffers to guard against leaks, maybe caused by previous exceptions
53
53
  javascript = <<~JAVASCRIPT
54
- return Opal.Isomorfeus.SSR.first_pass('#{Thread.current[:isomorfeus_session_id]}', '#{Isomorfeus.env}', '#{props[:locale]}', '#{props[:location]}', '#{api_ws_path}', '#{transport_ws_url}', '#{component_name}', #{Oj.dump(props, mode: :strict)})
54
+ return Opal.Isomorfeus.SSR.first_pass('#{Thread.current[:isomorfeus_session_id]}', '#{Isomorfeus.env}', '#{props[:locale]}', '#{props[:location]}', '#{transport_ws_url}', '#{component_name}', #{Oj.dump(props, mode: :strict)})
55
55
  JAVASCRIPT
56
56
 
57
57
  finished = false
@@ -65,13 +65,14 @@ module Isomorfeus
65
65
  end
66
66
 
67
67
  if has_transport
68
+ sleep 0.001 # give node a chance connecting to ruby by allowing other threads to run
68
69
  # wait for first pass to finish
69
70
  first_pass_finished, need_further_pass, exception = ctx.eval_script(key: :first_pass_check)
70
71
  Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
71
72
  unless first_pass_finished
72
73
  start_time = Time.now
73
74
  while !first_pass_finished
74
- break if (Time.now - start_time) > 10
75
+ # break if (Time.now - start_time) > 10
75
76
  sleep 0.005
76
77
  first_pass_finished, need_further_pass, exception = ctx.eval_script(key: :first_pass_check)
77
78
  Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
@@ -79,13 +80,13 @@ module Isomorfeus
79
80
  end
80
81
 
81
82
  # wait for transport to settle
82
- transport_busy = ctx.eval_script(key: :transport_busy)
83
- if transport_busy
83
+ still_busy = ctx.eval_script(key: :still_busy)
84
+ if still_busy
84
85
  start_time = Time.now
85
- while transport_busy
86
+ while still_busy
86
87
  break if (Time.now - start_time) > 5
87
88
  sleep 0.005
88
- transport_busy = ctx.eval_script(key: :transport_busy)
89
+ still_busy = ctx.eval_script(key: :still_busy)
89
90
  end
90
91
  end
91
92
  end
@@ -95,26 +96,22 @@ module Isomorfeus
95
96
  Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
96
97
  else
97
98
  start_time = Time.now
98
- script_key = if has_transport
99
- :still_busy
100
- else
101
- :store_busy
102
- end
99
+ javascript = <<~JAVASCRIPT
100
+ return Opal.Isomorfeus.SSR.further_pass('#{component_name}', #{Oj.dump(props, mode: :strict)})
101
+ JAVASCRIPT
103
102
  while need_further_pass
104
103
  # execute further render passes
105
- javascript = <<~JAVASCRIPT
106
- return Opal.Isomorfeus.SSR.further_pass('#{component_name}', #{Oj.dump(props, mode: :strict)})
107
- JAVASCRIPT
108
104
  pass += 1
109
105
  rendered_tree, application_state, @ssr_styles, @ssr_response_status, need_further_pass, exception = ctx.exec(javascript)
110
106
  Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
111
- if need_further_pass && script_key
112
- break if (Time.now - start_time) > 5
113
- still_busy = ctx.eval_script(key: script_key)
107
+ if need_further_pass
108
+ sleep 0.001 # give other threads a chance
109
+ # break if (Time.now - start_time) > 5
110
+ still_busy = ctx.eval_script(key: :still_busy)
114
111
  while still_busy
115
- break if (Time.now - start_time) > 5
112
+ # break if (Time.now - start_time) > 5
116
113
  sleep 0.005
117
- still_busy = ctx.eval_script(key: script_key)
114
+ still_busy = ctx.eval_script(key: :still_busy)
118
115
  end
119
116
  break if pass >= max_passes
120
117
  else
@@ -177,21 +174,19 @@ module Isomorfeus
177
174
  ctx = Isomorfeus.ssr_contexts[thread_id_asset]
178
175
  ctx.exec(top_level_mod)
179
176
  ctx.exec(ssr_mod)
180
- ctx.add_script(key: :first_pass_check, source: '[global.FirstPassFinished, global.NeedFurtherPass, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false ]')
177
+ ctx.add_script(key: :first_pass_check, source: 'Opal.Isomorfeus.SSR.first_pass_check()')
181
178
  ctx.add_script(key: :first_pass_result, source: 'Opal.Isomorfeus.SSR.first_pass_result()')
182
179
  ctx.add_script(key: :still_busy, source: 'Opal.Isomorfeus.SSR.still_busy()')
183
- ctx.add_script(key: :store_busy, source: 'Opal.Isomorfeus.SSR.store_busy()')
184
- ctx.add_script(key: :transport_busy, source: 'global.Opal.Isomorfeus.Transport["$busy?"]()')
185
180
  ctx.add_script(key: :transport_disconnect, source: 'global.Opal.Isomorfeus.SSR.$disconnect_transport()')
186
181
  end
187
182
  end
188
183
 
189
184
  def ssr_mod
190
- @_ssr_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'ssr.rb'))))
185
+ @_ssr_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'ssr.rb'))), { use_strict: true })
191
186
  end
192
187
 
193
188
  def top_level_mod
194
- @_top_level_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'top_level_ssr.rb'))))
189
+ @_top_level_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'top_level_ssr.rb'))), { use_strict: true })
195
190
  end
196
191
  end
197
192
  end
@@ -1,72 +1,91 @@
1
1
  module Isomorfeus
2
2
  module SSR
3
3
  %x{
4
- self.first_pass = function(session_id, env, locale, location, api_ws_path, transport_ws_url, component_name, props) {
5
- global.Opal.Preact.render_buffer = [];
6
- global.Opal.Preact.active_components = [];
7
- global.Opal.Preact.active_redux_components = [];
4
+ self.first_pass = function(session_id, env, locale, location, transport_ws_url, component_name, props) {
5
+ const oper = global.Opal.Preact;
6
+ const opi = global.Opal.Isomorfeus;
7
+ oper.render_buffer = [];
8
+ oper.active_components = [];
9
+ oper.active_redux_components = [];
8
10
  global.FirstPassFinished = false;
9
11
  global.NeedFurtherPass = false;
10
12
  global.RenderedTree = '';
11
13
  global.Exception = false;
12
14
  global.IsomorfeusSessionId = session_id;
13
- global.HasTransport = (typeof global.Opal.Isomorfeus.Transport !== 'undefined') && (api_ws_path !== '');
14
- global.Opal.Isomorfeus['$env='](env);
15
- if (typeof global.Opal.Isomorfeus["$current_locale="] === 'function') { global.Opal.Isomorfeus["$current_locale="](locale); }
16
- global.Opal.Isomorfeus['$force_init!']();
17
- global.Opal.Isomorfeus['$ssr_response_status='](200);
18
- global.Opal.Isomorfeus.TopLevel['$ssr_route_path='](location);
15
+ global.HasTransport = (typeof opi.Transport !== 'undefined');
16
+ opi['$env='](env);
17
+ if (typeof opi["$current_locale="] === 'function') { opi["$current_locale="](locale); }
18
+ opi['$force_init!']();
19
+ opi['$ssr_response_status='](200);
20
+ opi.TopLevel['$ssr_route_path='](location);
19
21
  if (global.HasTransport) {
20
- global.Opal.Isomorfeus.TopLevel["$transport_ws_url="](transport_ws_url);
21
- global.Opal.send(global.Opal.Isomorfeus.Transport.$promise_connect(global.IsomorfeusSessionId), 'then', [], ($$1 = function(){
22
+ opi.TopLevel["$transport_ws_url="](transport_ws_url);
23
+ let $$1;
24
+ global.Opal.send(opi.Transport.$promise_connect(global.IsomorfeusSessionId), 'then', [], ($$1 = function(){
22
25
  try {
23
- global.RenderedTree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string(component_name, props);
26
+ global.RenderedTree = opi.TopLevel.$render_component_to_string(component_name, props);
24
27
  global.NeedFurtherPass = self.still_busy();
25
28
  global.FirstPassFinished = true;
26
29
  } catch (e) {
27
30
  global.Exception = e;
31
+ global.FirstPassFinished = true;
28
32
  global.NeedFurtherPass = false;
29
33
  }
30
34
  }, $$1.$$s = this, $$1.$$arity = 0, $$1))
35
+ global.NeedFurtherPass = true;
31
36
  } else {
32
37
  try {
33
- global.RenderedTree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string(component_name, props);
38
+ global.RenderedTree = opi.TopLevel.$render_component_to_string(component_name, props);
34
39
  global.NeedFurtherPass = self.store_busy();
35
40
  } catch (e) {
36
41
  global.Exception = e;
42
+ global.FirstPassFinished = true;
37
43
  global.NeedFurtherPass = false;
38
44
  }
39
45
  };
40
- return [global.HasTransport, global.NeedFurtherPass, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false];
46
+ return [global.HasTransport, global.NeedFurtherPass, self.get_exception()];
47
+ }
48
+
49
+ self.first_pass_check = function() {
50
+ return [global.FirstPassFinished, global.NeedFurtherPass, self.get_exception()];
41
51
  }
42
52
 
43
53
  self.first_pass_result = function() {
44
- let ssr_styles;
45
- let application_state = global.Opal.Isomorfeus.store.native.getState();
46
- if (typeof global.NanoCSSInstance !== 'undefined') { ssr_styles = global.NanoCSSInstance.raw }
47
- return [global.RenderedTree, application_state, ssr_styles, global.Opal.Isomorfeus['$ssr_response_status'](), global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false];
54
+ const opi = global.Opal.Isomorfeus;
55
+ let application_state = opi.store.native.getState();
56
+ let ssr_styles = global?.NanoCSSInstance?.raw;
57
+ return [global.RenderedTree, application_state, ssr_styles, opi['$ssr_response_status'](), self.get_exception()];
48
58
  }
49
59
 
50
60
  self.further_pass = function(component_name, props) {
51
- global.Opal.Preact.render_buffer = [];
52
- global.Opal.Preact.active_components = [];
53
- global.Opal.Preact.active_redux_components = [];
61
+ const oper = global.Opal.Preact;
62
+ const opi = global.Opal.Isomorfeus;
63
+ oper.render_buffer = [];
64
+ oper.active_components = [];
65
+ oper.active_redux_components = [];
66
+ global.NeedFurtherPass = false;
54
67
  global.Exception = false;
55
- let rendered_tree;
56
- let ssr_styles;
68
+ let application_state = null;
69
+ let rendered_tree = null;
70
+ let ssr_styles = null;
57
71
  try {
58
- rendered_tree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string(component_name, props);
72
+ rendered_tree = opi.TopLevel.$render_component_to_string(component_name, props);
73
+ application_state = opi.store.native.getState();
74
+ ssr_styles = global?.NanoCSSInstance?.raw;
75
+ global.NeedFurtherPass = self.still_busy();
59
76
  } catch (e) {
60
77
  global.Exception = e;
61
78
  }
62
- let application_state = global.Opal.Isomorfeus.store.native.getState();
63
- if (typeof global.NanoCSSInstance !== 'undefined') { ssr_styles = global.NanoCSSInstance.raw }
64
- global.NeedFurtherPass = ((global.HasTransport && global.Opal.Isomorfeus.Transport["$busy?"]()) || self.store_busy());
65
- return [rendered_tree, application_state, ssr_styles, global.Opal.Isomorfeus['$ssr_response_status'](), global.NeedFurtherPass, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false];
79
+ return [rendered_tree, application_state, ssr_styles, opi['$ssr_response_status'](), global.NeedFurtherPass, self.get_exception()];
80
+ }
81
+
82
+ self.get_exception = function() {
83
+ if (global.Exception) { return { message: global.Exception.message, stack: global.Exception.stack }; }
84
+ return false;
66
85
  }
67
86
 
68
87
  self.still_busy = function(){
69
- if (global.Opal.Isomorfeus.Transport["$busy?"]()) { return true; }
88
+ if (global.Opal.Isomorfeus?.Transport?.["$busy?"]?.()) { return true; }
70
89
  return self.store_busy();
71
90
  }
72
91
 
@@ -1,6 +1,9 @@
1
1
  module Isomorfeus
2
2
  class TopLevel
3
3
  class << self
4
+ attr_accessor :hydrated
5
+ attr_accessor :first_pass
6
+
4
7
  if on_browser?
5
8
  def mount!
6
9
  Isomorfeus.init
@@ -27,7 +30,7 @@ module Isomorfeus
27
30
  props_json = root_element.JS.getAttribute('data-iso-props')
28
31
  props = `Opal.Hash.$new(JSON.parse(props_json))`
29
32
  raw_hydrated = root_element.JS.getAttribute('data-iso-hydrated')
30
- hydrated = (raw_hydrated && raw_hydrated == "true")
33
+ self.hydrated = (raw_hydrated && raw_hydrated == "true")
31
34
  %x{
32
35
  if (global.ServerSideRenderingStateJSON) {
33
36
  var state = global.ServerSideRenderingStateJSON;
@@ -41,10 +44,13 @@ module Isomorfeus
41
44
  }
42
45
  Isomorfeus.execute_init_after_store_classes
43
46
  begin
44
- result = Isomorfeus::TopLevel.mount_component(component, props, root_element, hydrated)
47
+ self.first_pass = true
48
+ result = Isomorfeus::TopLevel.mount_component(component, props, root_element, self.hydrated)
49
+ self.first_pass = false
45
50
  @tried_another_time = false
46
51
  result
47
52
  rescue Exception => e
53
+ self.first_pass = false
48
54
  if !@tried_another_time
49
55
  @tried_another_time = true
50
56
  `console.warn("Deferring mount: " + #{e.message})`
@@ -8,10 +8,13 @@ if RUBY_ENGINE == 'opal'
8
8
  require 'browser/event_target'
9
9
  require 'browser/delegate_native'
10
10
  require 'browser/element' # depends on 'preact'
11
+ require 'browser/history'
11
12
  end
12
13
 
13
14
  require 'isomorfeus/preact/config'
14
-
15
+ if on_browser? && `window?.history`
16
+ Isomorfeus.browser_history = Browser::History.new(`window.history`)
17
+ end
15
18
  # allow mounting of components
16
19
  require 'isomorfeus/top_level'
17
20
 
@@ -74,26 +74,31 @@ module Preact::FunctionComponent::Api
74
74
  end
75
75
 
76
76
  def get_preact_element(arg, &block)
77
+ `let operabu = Opal.Preact.render_buffer`
77
78
  if block_given?
78
79
  # execute block, fetch last element from buffer
79
80
  %x{
80
- let last_buffer_length = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].length;
81
- let last_buffer_element = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1][last_buffer_length - 1];
81
+ let last_buffer_length = operabu[operabu.length - 1].length;
82
+ let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
82
83
  block.$call();
83
- // console.log("get_preact_element popping", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())
84
- let new_element = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].pop();
84
+ // console.log("get_preact_element popping", operabu, operabu.toString())
85
+ let new_element = operabu[operabu.length - 1].pop();
85
86
  if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any Preact element!")} }
86
87
  return new_element;
87
88
  }
88
89
  else
89
90
  # element was rendered before being passed as arg
90
91
  # fetch last element from buffer
91
- # `console.log("get_preact_element popping", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())`
92
- `Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].pop()`
92
+ # `console.log("get_preact_element popping", operabu, operabu.toString())`
93
+ `operabu[operabu.length - 1].pop()`
93
94
  end
94
95
  end
95
96
  alias gpe get_preact_element
96
97
 
98
+ def history
99
+ Isomorfeus.browser_history
100
+ end
101
+
97
102
  def render_preact_element(el)
98
103
  # push el to buffer
99
104
  `Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].push(el)`
@@ -105,7 +110,7 @@ module Preact::FunctionComponent::Api
105
110
  def method_ref(method_symbol, *args)
106
111
  method_key = "#{method_symbol}#{args}"
107
112
  %x{
108
- if (#{self}.method_refs && #{self}.method_refs[#{method_key}]) { return #{self}.method_refs[#{method_key}]; }
113
+ if (#{self}.method_refs?.[#{method_key}]) { return #{self}.method_refs[#{method_key}]; }
109
114
  if (!#{self}.method_refs) { #{self}.method_refs = {}; }
110
115
  #{self}.method_refs[#{method_key}] = { m: #{method(method_symbol)}, a: args };
111
116
  return #{self}.method_refs[#{method_key}];
@@ -66,30 +66,35 @@ module Preact::Component::Api
66
66
  end
67
67
 
68
68
  def get_preact_element(arg, &block)
69
+ `const operabu = Opal.Preact.render_buffer`
69
70
  if block_given?
70
71
  # execute block, fetch last element from buffer
71
72
  %x{
72
- let last_buffer_length = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].length;
73
- let last_buffer_element = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1][last_buffer_length - 1];
73
+ let last_buffer_length = operabu[operabu.length - 1].length;
74
+ let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
74
75
  block.$call();
75
- // console.log("get_preact_element popping", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())
76
- let new_element = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].pop();
76
+ // console.log("get_preact_element popping", operabu, operabu.toString())
77
+ let new_element = operabu[operabu.length - 1].pop();
77
78
  if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any Preact element!")} }
78
79
  return new_element;
79
80
  }
80
81
  else
81
82
  # element was rendered before being passed as arg
82
83
  # fetch last element from buffer
83
- # `console.log("get_preact_element popping", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())`
84
- `Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].pop()`
84
+ # `console.log("get_preact_element popping", operabu, operabu.toString())`
85
+ `operabu[operabu.length - 1].pop()`
85
86
  end
86
87
  end
87
88
  alias gpe get_preact_element
88
89
 
90
+ def history
91
+ Isomorfeus.browser_history
92
+ end
93
+
89
94
  def method_ref(method_symbol, *args)
90
95
  method_key = "#{method_symbol}#{args}"
91
96
  %x{
92
- if (#@native.method_refs && #@native.method_refs[#{method_key}]) { return #@native.method_refs[#{method_key}]; }
97
+ if (#@native.method_refs?.[#{method_key}]) { return #@native.method_refs[#{method_key}]; }
93
98
  if (!#@native.method_refs) { #@native.method_refs = {}; }
94
99
  #@native.method_refs[#{method_key}] = { m: #{method(method_symbol)}, a: args };
95
100
  return #@native.method_refs[#{method_key}];
@@ -5,11 +5,12 @@ module Preact::Component::Callbacks
5
5
  # TODO convert error
6
6
  %x{
7
7
  var fun = function(error) {
8
- Opal.Preact.register_active_component(this);
8
+ const oper = Opal.Preact;
9
+ oper.register_active_component(this);
9
10
  try {
10
11
  #{`this.__ruby_instance`.instance_exec(`error`, &block)};
11
12
  } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
12
- Opal.Preact.unregister_active_component(this);
13
+ oper.unregister_active_component(this);
13
14
  }
14
15
  if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidCatch = fun; }
15
16
  else { self.preact_component.prototype.componentDidCatch = fun; }
@@ -20,22 +21,24 @@ module Preact::Component::Callbacks
20
21
  def component_did_mount(&block)
21
22
  %x{
22
23
  let fun = function() {
23
- Opal.Preact.register_active_component(this);
24
+ const oper = Opal.Preact;
25
+ oper.register_active_component(this);
24
26
  try {
25
27
  #{`this.__ruby_instance`.instance_exec(&block)};
26
28
  } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
27
- Opal.Preact.unregister_active_component(this);
29
+ oper.unregister_active_component(this);
28
30
  }
29
31
  if (self.lucid_preact_component) {
30
- if (self.lucid_preact_component.prototype.componentDidMount) {
31
- self.lucid_preact_component.prototype.componentDidMountTwo = self.lucid_preact_component.prototype.componentDidMount;
32
- self.lucid_preact_component.prototype.componentDidMountOne = fun;
32
+ let proto = self.lucid_preact_component.prototype;
33
+ if (proto.componentDidMount) {
34
+ proto.componentDidMountTwo = proto.componentDidMount;
35
+ proto.componentDidMountOne = fun;
33
36
  fun = function() {
34
37
  this.componentDidMountOne();
35
38
  this.componentDidMountTwo();
36
39
  }
37
40
  }
38
- self.lucid_preact_component.prototype.componentDidMount = fun;
41
+ proto.componentDidMount = fun;
39
42
  } else { self.preact_component.prototype.componentDidMount = fun; }
40
43
  }
41
44
  end
@@ -43,13 +46,14 @@ module Preact::Component::Callbacks
43
46
  def component_did_update(&block)
44
47
  %x{
45
48
  var fun = function(prev_props, prev_state, snapshot) {
46
- Opal.Preact.register_active_component(this);
49
+ const oper = Opal.Preact;
50
+ oper.register_active_component(this);
47
51
  try {
48
- #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
49
- `Opal.Preact.State.$new({state: prev_state})`,
50
- `snapshot`, &block)};
52
+ #{`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: prev_props})`,
53
+ `oper.State.$new({state: prev_state})`,
54
+ `snapshot`, &block)};
51
55
  } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
52
- Opal.Preact.unregister_active_component(this);
56
+ oper.unregister_active_component(this);
53
57
  }
54
58
  if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidUpdate = fun; }
55
59
  else { self.preact_component.prototype.componentDidUpdate = fun; }
@@ -59,12 +63,13 @@ module Preact::Component::Callbacks
59
63
  def component_will_unmount(&block)
60
64
  %x{
61
65
  var fun = function() {
66
+ const oper = Opal.Preact;
62
67
  if (typeof this.unsubscriber === "function") { this.unsubscriber(); };
63
- Opal.Preact.register_active_component(this);
68
+ oper.register_active_component(this);
64
69
  try {
65
70
  #{`this.__ruby_instance`.instance_exec(&block)};
66
71
  } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
67
- Opal.Preact.unregister_active_component(this);
72
+ oper.unregister_active_component(this);
68
73
  }
69
74
  if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentWillUnmount = fun; }
70
75
  else { self.preact_component.prototype.componentWillUnmount = fun; }
@@ -75,12 +80,13 @@ module Preact::Component::Callbacks
75
80
  def get_derived_state_from_props(&block)
76
81
  %x{
77
82
  var fun = function(props, state) {
78
- Opal.Preact.register_active_component(this);
83
+ const oper = Opal.Preact;
84
+ oper.register_active_component(this);
79
85
  try {
80
- var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: props})`,
81
- `Opal.Preact.State.$new({state: state})`, &block)};
86
+ var result = #{`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: props})`,
87
+ `oper.State.$new({state: state})`, &block)};
82
88
  } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
83
- Opal.Preact.unregister_active_component(this);
89
+ oper.unregister_active_component(this);
84
90
  if (typeof result.$to_n === 'function') { result = result.$to_n() }
85
91
  if (result === nil) { return null; }
86
92
  return result;
@@ -93,12 +99,13 @@ module Preact::Component::Callbacks
93
99
  def get_snapshot_before_update(&block)
94
100
  %x{
95
101
  var fun = function(prev_props, prev_state) {
96
- Opal.Preact.register_active_component(this);
102
+ const oper = Opal.Preact;
103
+ oper.register_active_component(this);
97
104
  try {
98
- var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
99
- `Opal.Preact.State.$new({state: prev_state})`, &block)};
105
+ var result = #{`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: prev_props})`,
106
+ `oper.State.$new({state: prev_state})`, &block)};
100
107
  } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
101
- Opal.Preact.unregister_active_component(this);
108
+ oper.unregister_active_component(this);
102
109
  if (result === nil) { return null; }
103
110
  return result;
104
111
  }
@@ -1,3 +1,3 @@
1
1
  module Preact
2
- VERSION = '10.6.48'
2
+ VERSION = '10.6.49'
3
3
  end
data/lib/preact.rb CHANGED
@@ -145,12 +145,12 @@ module Preact
145
145
  let method_name = '$' + value;
146
146
  if (typeof active_component[method_name] === "function") {
147
147
  // got a ruby instance
148
- if (active_component.native && active_component.native.method_refs && active_component.native.method_refs[value]) { method_ref = active_component.native.method_refs[value]; } // ruby instance with native
149
- else if (active_component.method_refs && active_component.method_refs[value]) { method_ref = active_component.method_refs[value]; } // ruby function component
148
+ if (active_component.native?.method_refs?.[value]) { method_ref = active_component.native.method_refs[value]; } // ruby instance with native
149
+ else if (active_component.method_refs?.[value]) { method_ref = active_component.method_refs[value]; } // ruby function component
150
150
  else { method_ref = active_component.$method_ref(value); } // create the ref
151
151
  } else if (typeof active_component.__ruby_instance[method_name] === "function") {
152
152
  // got a native instance
153
- if (active_component.method_refs && active_component.method_refs[value]) { method_ref = active_component.method_refs[value]; }
153
+ if (active_component.method_refs?.[value]) { method_ref = active_component.method_refs[value]; }
154
154
  else { method_ref = active_component.__ruby_instance.$method_ref(value); } // create ref for native
155
155
  }
156
156
  if (method_ref) {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-preact
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.6.48
4
+ version: 10.6.49
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-22 00:00:00.000000000 Z
11
+ date: 2022-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -222,6 +222,7 @@ files:
222
222
  - lib/browser/event.rb
223
223
  - lib/browser/event_target.rb
224
224
  - lib/browser/file_list.rb
225
+ - lib/browser/history.rb
225
226
  - lib/browser/iterable.rb
226
227
  - lib/isomorfeus-preact.rb
227
228
  - lib/isomorfeus/preact/config.rb