isomorfeus-preact 10.6.26 → 10.6.30

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: 0d26f73d028c328b0dc47a55e0bb2c7c413df5b8ab7b186952e50949d96dde08
4
- data.tar.gz: 5952469a0ea71a67f3176f6551e91ed1968dbf0c58131026c6a81d938acc9e75
3
+ metadata.gz: 261bf828fca3276232e1cc9a57f32cb6bd45ddd0fa2d386c42dc799813a5f110
4
+ data.tar.gz: a18cdda3bbb233fd376f90c0cabda7637cd110a34697e2a2d7710e78249775db
5
5
  SHA512:
6
- metadata.gz: 3c44c6fc3355ff2f600e9db9debc14804ff7578339af433a5fb271962412a4f530fd401fb592a3267a3845908f328fb94fa9721ca6859a3c701335298a5d3b8f
7
- data.tar.gz: 65728c2ecc71694b1794d6c4f5d94c5cc9e962db84e4c38569bb36beb6985e408aeaad8e1c77cade61f842c5a8c3d1af0138a80569859b8d3f37a995ddfe74fd
6
+ metadata.gz: a76b3e58d5d4fd34409126b93487eb8f257509f6c9ff4697248c60333d51c416b1232bc78c4e72d694fbbab5b2392405cdda5aa40310f500e0a53e8d7e61e76b
7
+ data.tar.gz: ea99ad3ec25838e3c6c94d971e529fe92b7ba7597e685578fcd097a62a852e095faae7f10d18d7822d5880510350ac1997578818d4cde8ae9a45bd2ec9a8f971
@@ -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; }
@@ -29,19 +29,19 @@ module Preact
29
29
  # check for ruby component and render it
30
30
  # otherwise pass on method missing
31
31
  %x{
32
- var constant;
32
+ var constant = null;
33
33
  if (typeof self.iso_preact_const_cache === 'undefined') { self.iso_preact_const_cache = {}; }
34
- try {
35
- if (typeof self.iso_preact_const_cache[component_name] !== 'undefined') {
36
- constant = self.iso_preact_const_cache[component_name]
37
- } else {
34
+ if (typeof self.iso_preact_const_cache[component_name] !== 'undefined') {
35
+ constant = self.iso_preact_const_cache[component_name]
36
+ } else {
37
+ try {
38
38
  constant = self.$const_get(component_name);
39
39
  self.iso_preact_const_cache[component_name] = constant;
40
- }
41
- if (typeof constant.preact_component !== 'undefined') {
42
- return Opal.Preact.internal_prepare_args_and_render(constant.preact_component, args, block);
43
- }
44
- } catch(err) { }
40
+ } catch(err) { }
41
+ }
42
+ if (constant && typeof constant.preact_component !== 'undefined') {
43
+ return Opal.Preact.internal_prepare_args_and_render(constant.preact_component, args, block);
44
+ }
45
45
  return #{_preact_component_class_resolution_original_method_missing(component_name, *args, block)};
46
46
  }
47
47
  end
@@ -59,7 +59,6 @@ module Preact
59
59
  %x{
60
60
  var constant;
61
61
  if (typeof self.iso_preact_const_cache === 'undefined') { self.iso_preact_const_cache = {}; }
62
-
63
62
  if (typeof self.iso_preact_const_cache[component_name] !== 'undefined') {
64
63
  constant = self.iso_preact_const_cache[component_name]
65
64
  } else if (typeof self.$$is_a_module !== 'undefined') {
@@ -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.26'
2
+ VERSION = '10.6.30'
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() {
@@ -110,25 +112,6 @@ module Preact
110
112
  self.active_components.pop();
111
113
  };
112
114
 
113
- function isObject(obj) { return (obj && typeof obj === 'object'); }
114
-
115
- self.merge_deep = function(one, two) {
116
- return [one, two].reduce(function(pre, obj) {
117
- Object.keys(obj).forEach(function(key){
118
- let pVal = pre[key];
119
- let oVal = obj[key];
120
- if (Array.isArray(pVal) && Array.isArray(oVal)) {
121
- pre[key] = pVal.concat.apply(this, oVal);
122
- } else if (isObject(pVal) && isObject(oVal)) {
123
- pre[key] = self.merge_deep(pVal, oVal);
124
- } else {
125
- pre[key] = oVal;
126
- }
127
- });
128
- return pre;
129
- }, {});
130
- };
131
-
132
115
  self.prop_dictionary = {};
133
116
 
134
117
  self.to_native_preact_props = function(ruby_style_props) {
@@ -231,23 +214,18 @@ module Preact
231
214
  }
232
215
  };
233
216
 
234
- self.deep_force_update = function(component) {
235
- if (component.forceUpdate) { component.forceUpdate(); }
236
- if (component.__c) { self.deep_force_update(component.__c); }
237
- else if (component.base) { self.update_components_from_dom(component.base); }
238
- };
239
-
240
- self.update_components_from_dom = function(node, fn) {
241
- let children = node.childNodes;
242
- for (let i=children && children.length; i--;) {
243
- let child = children[i];
244
- if (child.__c) { self.deep_force_update(child.__c); }
245
- else { self.update_components_from_dom(child, fn); }
217
+ self.deep_force_update = function(vnode) {
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
+ }
224
+ }
246
225
  }
247
226
  };
248
227
  }
249
228
 
250
-
251
229
  def self.create_element(type, props = nil, children = nil, &block)
252
230
  %x{
253
231
  const operabu = self.render_buffer;
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.26
4
+ version: 10.6.30
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-03 00:00:00.000000000 Z
11
+ date: 2022-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby