isomorfeus-preact 10.6.27 → 10.6.31

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: 73f8b8f7d14be7b8a80efda0f1cba6be6edb00ceb1043c5339b1360bfa791924
4
- data.tar.gz: 76be3664fce68b8dbdc29a62068366cc417805664bab7ecd60fcbda689742e66
3
+ metadata.gz: 6db990c75f74db85c901f1457d2d03abf0e9549cf387f451dc3cd177f2f4309a
4
+ data.tar.gz: f042344ddc83fa467b26ad7eb7705821ec330899fd28a9951d779b6cae8fd627
5
5
  SHA512:
6
- metadata.gz: 0ee3ac614f2156b22425ec55e89b97d44c4c216d30358718de94b75aa6c44abc5161fd064fdd69c58f3166d4dcea36eacdfb6bf5a58a72352a731f97925e76cf
7
- data.tar.gz: e2e92fe0838eb9dd82bb24bacd88f7ec420a69f7df6f3f559d7fda08fba3f4823507c3df7539028146afbaa0347a157fc409ee0e77f45021ccfd7dc04ab28e28
6
+ metadata.gz: 756298c04ff0b66478037db121c97c3337f8f58d5496681cd99ada7c14724eb4a33bd416aabdf334378106ae88424550a9755b3deeea7989a2b71fae24ca6578
7
+ data.tar.gz: d97a5569be7b4e1ef7af0bebd0437bb15a4b018f2ab8fe856a987d9742d7ced8893788cd9497f5b3d9995a352e8fe34788972ae3a34bf3ad209f4ad1805e4198
@@ -37,7 +37,9 @@ module LucidApp
37
37
  this[ref] = function(element) {
38
38
  element = oper.native_element_or_component_to_ruby(element);
39
39
  oper.register_active_component(this);
40
- #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
40
+ try {
41
+ #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
42
+ } catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
41
43
  oper.unregister_active_component(this);
42
44
  }
43
45
  this[ref] = this[ref].bind(this);
@@ -47,7 +49,7 @@ module LucidApp
47
49
  }
48
50
  if (base.preload_block) {
49
51
  oper.register_active_component(this);
50
- this.state.preloaded = this.__ruby_instance.$execute_preload_block();
52
+ this.state.preloaded = this.__ruby_instance.$execute_preload_block(); // caught in execute_preload_block itself
51
53
  oper.unregister_active_component(this);
52
54
  }
53
55
  this.listener = this.listener.bind(this);
@@ -61,9 +63,14 @@ module LucidApp
61
63
  oper.render_buffer.push([]);
62
64
  oper.register_active_component(this);
63
65
  let block_result;
64
- if (base.while_loading_block && !state.preloaded) { block_result = #{`this.__ruby_instance`.instance_exec(&`base.while_loading_block`)}; }
65
- else { block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)}; }
66
- if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
66
+ try {
67
+ if (base.while_loading_block && !state.preloaded) { block_result = #{`this.__ruby_instance`.instance_exec(&`base.while_loading_block`)}; }
68
+ else { block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)}; }
69
+ if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
70
+ } catch (e) {
71
+ if (oper.using_did_catch) { throw e; }
72
+ else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
73
+ }
67
74
  oper.unregister_active_component(this);
68
75
  let children = oper.render_buffer.pop();
69
76
  return Opal.global.Preact.createElement(Opal.global.LucidApplicationContext.Provider, { value: { iso_store: this.state.isomorfeus_store_state, iso_theme: base.css_theme }}, children);
@@ -78,6 +85,11 @@ module LucidApp
78
85
  componentWillUnmount() {
79
86
  if (typeof this.unsubscriber === "function") { this.unsubscriber(); }
80
87
  }
88
+ shouldComponentUpdate(next_props, next_state) {
89
+ if (!Opal.Preact.props_are_equal(this.props, next_props)) { return true; }
90
+ if (Opal.Preact.state_is_not_equal(this.state, next_state)) { return true; }
91
+ return false;
92
+ }
81
93
  validateProp(props, propName, componentName) {
82
94
  try { base.$validate_prop(propName, props[propName]) }
83
95
  catch (e) { return new Error(componentName + ": Error: prop validation failed: " + e.message); }
@@ -16,17 +16,14 @@ module LucidComponent
16
16
  `base.preload_block = block`
17
17
  component_did_mount do
18
18
  unless self.state.preloaded
19
- @_preload_promise.then { self.state.preloaded = true }.fail do |result|
20
- err_text = "#{self.class.name}: preloading failed, last result: #{result.nil? ? 'nil' : result}!"
21
- `console.error(err_text)`
22
- end
19
+ @_preload_promise.then { self.state.preloaded = true } if @_preload_promise
23
20
  end
24
21
  end
25
22
  end
26
23
 
27
24
  def while_loading(option = nil, &block)
28
25
  wl_block = proc do
29
- if @_preload_promise.resolved?
26
+ if @_preload_promise && @_preload_promise.resolved?
30
27
  instance_exec(&`base.render_block`)
31
28
  else
32
29
  instance_exec(&block)
@@ -85,8 +82,23 @@ module LucidComponent
85
82
 
86
83
  # preloading
87
84
  def execute_preload_block
88
- @_preload_promise = instance_exec(&self.class.JS[:preload_block])
89
- @_preload_promise.resolved?
85
+ begin
86
+ @_preload_promise = instance_exec(&self.class.JS[:preload_block])
87
+ rescue => e
88
+ %x{
89
+ console.error(e.message);
90
+ console.error(e.stack);
91
+ }
92
+ end
93
+ if @_preload_promise
94
+ @_preload_promise.fail do |result|
95
+ err_text = "#{self.class.name}: preloading failed, last result: #{result.nil? ? 'nil' : result}!"
96
+ `console.error(err_text)`
97
+ end
98
+ @_preload_promise.resolved?
99
+ else
100
+ false
101
+ end
90
102
  end
91
103
 
92
104
  def preloaded?
@@ -33,7 +33,9 @@ module LucidComponent
33
33
  this[ref] = function(element) {
34
34
  element = oper.native_element_or_component_to_ruby(element);
35
35
  oper.register_active_component(this);
36
- #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
36
+ try {
37
+ #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
38
+ } catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
37
39
  oper.unregister_active_component(this);
38
40
  }
39
41
  this[ref] = this[ref].bind(this);
@@ -43,7 +45,7 @@ module LucidComponent
43
45
  }
44
46
  if (base.preload_block) {
45
47
  oper.register_active_component(this);
46
- this.state.preloaded = this.__ruby_instance.$execute_preload_block();
48
+ this.state.preloaded = this.__ruby_instance.$execute_preload_block(); // caught in execute_preload_block itself
47
49
  oper.unregister_active_component(this);
48
50
  }
49
51
  }
@@ -55,9 +57,14 @@ module LucidComponent
55
57
  oper.render_buffer.push([]);
56
58
  oper.register_active_component(this);
57
59
  let block_result;
58
- if (base.while_loading_block && !state.preloaded) { block_result = #{`this.__ruby_instance`.instance_exec(&`base.while_loading_block`)}; }
59
- else { block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)}; }
60
- if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
60
+ try {
61
+ if (base.while_loading_block && !state.preloaded) { block_result = #{`this.__ruby_instance`.instance_exec(&`base.while_loading_block`)}; }
62
+ else { block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)}; }
63
+ if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
64
+ } catch (e) {
65
+ if (oper.using_did_catch) { throw e; }
66
+ else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
67
+ }
61
68
  oper.unregister_active_component(this);
62
69
  let result = oper.render_buffer.pop();
63
70
  return (result.length === 1) ? result[0] : result;
@@ -24,8 +24,13 @@ module LucidFunc
24
24
  const __ruby_instance = __ruby_state.instance;
25
25
  __ruby_instance.props = Object.assign({}, props, context);
26
26
  oper.register_active_component(__ruby_instance);
27
- let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
28
- if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
27
+ try {
28
+ let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
29
+ if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
30
+ } catch (e) {
31
+ if (oper.using_did_catch) { throw e; }
32
+ else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
33
+ }
29
34
  oper.unregister_active_component(__ruby_instance);
30
35
  // console.log("function popping", oper.render_buffer, oper.render_buffer.toString());
31
36
  let result = oper.render_buffer.pop();
@@ -17,8 +17,13 @@ module Preact
17
17
  const __ruby_instance = __ruby_state.instance;
18
18
  __ruby_instance.props = props;
19
19
  oper.register_active_component(__ruby_instance);
20
- let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
21
- if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
20
+ try {
21
+ let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
22
+ if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
23
+ } catch (e) {
24
+ if (oper.using_did_catch) { throw e; }
25
+ else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
26
+ }
22
27
  oper.unregister_active_component(__ruby_instance);
23
28
  let result = oper.render_buffer.pop();
24
29
  return (result.length === 1) ? result[0] : result;
@@ -8,11 +8,14 @@ module Preact
8
8
  %x{
9
9
  var fun = function(error) {
10
10
  Opal.Preact.register_active_component(this);
11
- #{`this.__ruby_instance`.instance_exec(`error`, &block)};
11
+ try {
12
+ #{`this.__ruby_instance`.instance_exec(`error`, &block)};
13
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
12
14
  Opal.Preact.unregister_active_component(this);
13
15
  }
14
16
  if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidCatch = fun; }
15
17
  else { self.preact_component.prototype.componentDidCatch = fun; }
18
+ Opal.Preact.using_did_catch = true;
16
19
  }
17
20
  end
18
21
 
@@ -20,7 +23,9 @@ module Preact
20
23
  %x{
21
24
  let fun = function() {
22
25
  Opal.Preact.register_active_component(this);
23
- #{`this.__ruby_instance`.instance_exec(&block)};
26
+ try {
27
+ #{`this.__ruby_instance`.instance_exec(&block)};
28
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
24
29
  Opal.Preact.unregister_active_component(this);
25
30
  }
26
31
  if (self.lucid_preact_component) {
@@ -41,9 +46,11 @@ module Preact
41
46
  %x{
42
47
  var fun = function(prev_props, prev_state, snapshot) {
43
48
  Opal.Preact.register_active_component(this);
44
- #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
45
- `Opal.Preact.State.$new({state: prev_state})`,
46
- `snapshot`, &block)};
49
+ try {
50
+ #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
51
+ `Opal.Preact.State.$new({state: prev_state})`,
52
+ `snapshot`, &block)};
53
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
47
54
  Opal.Preact.unregister_active_component(this);
48
55
  }
49
56
  if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidUpdate = fun; }
@@ -56,7 +63,9 @@ module Preact
56
63
  var fun = function() {
57
64
  if (typeof this.unsubscriber === "function") { this.unsubscriber(); };
58
65
  Opal.Preact.register_active_component(this);
59
- #{`this.__ruby_instance`.instance_exec(&block)};
66
+ try {
67
+ #{`this.__ruby_instance`.instance_exec(&block)};
68
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
60
69
  Opal.Preact.unregister_active_component(this);
61
70
  }
62
71
  if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentWillUnmount = fun; }
@@ -69,8 +78,10 @@ module Preact
69
78
  %x{
70
79
  var fun = function(props, state) {
71
80
  Opal.Preact.register_active_component(this);
72
- var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: props})`,
73
- `Opal.Preact.State.$new({state: state})`, &block)};
81
+ try {
82
+ var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: props})`,
83
+ `Opal.Preact.State.$new({state: state})`, &block)};
84
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
74
85
  Opal.Preact.unregister_active_component(this);
75
86
  if (typeof result.$to_n === 'function') { result = result.$to_n() }
76
87
  if (result === nil) { return null; }
@@ -85,8 +96,10 @@ module Preact
85
96
  %x{
86
97
  var fun = function(prev_props, prev_state) {
87
98
  Opal.Preact.register_active_component(this);
88
- var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
89
- `Opal.Preact.State.$new({state: prev_state})`, &block)};
99
+ try {
100
+ var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
101
+ `Opal.Preact.State.$new({state: prev_state})`, &block)};
102
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
90
103
  Opal.Preact.unregister_active_component(this);
91
104
  if (result === nil) { return null; }
92
105
  return result;
@@ -24,7 +24,9 @@ module Preact
24
24
  const oper = Opal.Preact;
25
25
  element = oper.native_element_or_component_to_ruby(element);
26
26
  oper.register_active_component(this);
27
- #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
27
+ try {
28
+ #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
29
+ } catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
28
30
  oper.unregister_active_component(this);
29
31
  }
30
32
  this[ref] = this[ref].bind(this);
@@ -40,8 +42,13 @@ module Preact
40
42
  const oper = Opal.Preact;
41
43
  oper.render_buffer.push([]);
42
44
  oper.register_active_component(this);
43
- let block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
44
- if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
45
+ try {
46
+ let block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
47
+ if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
48
+ } catch (e) {
49
+ if (oper.using_did_catch) { throw e; }
50
+ else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
51
+ }
45
52
  oper.unregister_active_component(this);
46
53
  let result = oper.render_buffer.pop();
47
54
  return (result.length === 1) ? result[0] : result;
@@ -50,8 +57,12 @@ module Preact
50
57
  const oper = Opal.Preact;
51
58
  if (base.should_component_update_block) {
52
59
  oper.register_active_component(this);
53
- return #{!!`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: next_props})`, `oper.State.$new({state: next_state })`, &`base.should_component_update_block`)};
60
+ let result;
61
+ try {
62
+ result = #{!!`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: next_props})`, `oper.State.$new({state: next_state })`, &`base.should_component_update_block`)};
63
+ } catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
54
64
  oper.unregister_active_component(this);
65
+ return result;
55
66
  }
56
67
  if (!oper.props_are_equal(this.props, next_props)) { return true; }
57
68
  if (oper.state_is_not_equal(this.state, next_state)) { return true; }
@@ -5,7 +5,7 @@ module Preact
5
5
  def initialize(native)
6
6
  @native = native
7
7
  end
8
-
8
+
9
9
  def is_wrapped_context
10
10
  true
11
11
  end
@@ -22,8 +22,10 @@ module Preact
22
22
  if (block !== nil) {
23
23
  operabu.push([]);
24
24
  // console.log("consumer pushed", operabu, operabu.toString());
25
- let block_result = block.$call(value);
26
- if (block_result && block_result !== nil) { Opal.Preact.render_block_result(block_result); }
25
+ try {
26
+ let block_result = block.$call(value);
27
+ if (block_result && block_result !== nil) { Opal.Preact.render_block_result(block_result); }
28
+ } catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
27
29
  // console.log("consumer popping", operabu, operabu.toString());
28
30
  children = operabu.pop();
29
31
  if (children.length === 1) { children = children[0]; }
@@ -1,3 +1,3 @@
1
1
  module Preact
2
- VERSION = '10.6.27'
2
+ VERSION = '10.6.31'
3
3
  end
data/lib/preact.rb CHANGED
@@ -80,6 +80,8 @@ module Preact
80
80
  } else { operain(component, null, null, block); }
81
81
  };
82
82
 
83
+ self.using_did_catch = false;
84
+
83
85
  self.active_components = [];
84
86
 
85
87
  self.active_component = function() {
@@ -213,10 +215,12 @@ module Preact
213
215
  };
214
216
 
215
217
  self.deep_force_update = function(vnode) {
216
- if (vnode.__c && vnode.__c.forceUpdate) { vnode.__c.forceUpdate(); }
217
- if (vnode.__k) {
218
- for (let i=vnode.__k.length-1; i>=0; i--) {
219
- self.deep_force_update(vnode.__k[i]);
218
+ if(vnode) {
219
+ if (vnode.__c && vnode.__c.forceUpdate) { vnode.__c.forceUpdate(); }
220
+ if (vnode.__k) {
221
+ for (let i=0; i<vnode.__k.length; i++) {
222
+ self.deep_force_update(vnode.__k[i]);
223
+ }
220
224
  }
221
225
  }
222
226
  };
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.27
4
+ version: 10.6.31
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-04 00:00:00.000000000 Z
11
+ date: 2022-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -206,7 +206,7 @@ dependencies:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: '3.10'
209
- description: Write Preact Components in Ruby.
209
+ description: Write Preact Components in Ruby, including styles and reactive data access.
210
210
  email:
211
211
  - jan@kursator.com
212
212
  executables: []
@@ -454,6 +454,7 @@ licenses:
454
454
  - MIT
455
455
  metadata:
456
456
  github_repo: ssh://github.com/isomorfeus/gems
457
+ source_code_uri: https://github.com/isomorfeus/isomorfeus-preact
457
458
  post_install_message:
458
459
  rdoc_options: []
459
460
  require_paths:
@@ -472,5 +473,5 @@ requirements: []
472
473
  rubygems_version: 3.3.3
473
474
  signing_key:
474
475
  specification_version: 4
475
- summary: Preact for the Isomorfeus Framework Project.
476
+ summary: Preact Components for Isomorfeus.
476
477
  test_files: []