isomorfeus-preact 23.6.0.rc5 → 23.7.0.rc1

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: 779986a2bb11f9fa0c6e2843cc7dd178aa260d61545a11e9880029e814e9271a
4
- data.tar.gz: e3f778adfa0d62c4e51528f9823a8c83cf7a0ed2e49e89a8a714203159a3f6e9
3
+ metadata.gz: dc75f42dc15647d420c75efe94ad0fec2a7c94d8fa2732c322953d983b73a605
4
+ data.tar.gz: d86d420916c4d71f1fab8b443924f6ba2c0dc1e09980808965b4aa9f655c0e85
5
5
  SHA512:
6
- metadata.gz: 6897c32a84bf1802b752eb2909634e688dff95f0136cf93ba5fc87b78b6fb7bc719e392e230212a454e4aeb2983860af08044a980c2e1727e3e6c6b9d69f4b7a
7
- data.tar.gz: 63aa3a8557f8ac5101732670b4abb38f9138e2eecf0c801dacde6f3bed47afe44d68f283a11d16de7f6504f7e29eaa8acfc24b22107d493a5b89dab1d0a8bcd5
6
+ metadata.gz: 6a084e4db02bac9c49b0b1825d2737fcb92df7d0ecfcf173635f28394d9b3b832554d64083ad0ef16ae7ca6e19119a4c197720cdc5d6c5a6b90b6f0f6ad2be1f
7
+ data.tar.gz: 76830024265abd1e8d792a3424d01ceb585ab1a0499ce4652ba77bb9c334e7af99504bc541a4835eadaf33ec67fbaff8a86b9bfb3b88c9e365cdce6d7f4324bb
@@ -154,6 +154,19 @@ static VALUE get_context(VALUE node_type, VALUE context) {
154
154
  return context;
155
155
  }
156
156
 
157
+ static VALUE is_renderable_q(VALUE self, VALUE block_result) {
158
+ switch (TYPE(block_result)) {
159
+ case T_BIGNUM:
160
+ case T_FIXNUM:
161
+ case T_FLOAT:
162
+ case T_STRING:
163
+ return Qtrue;
164
+ default:
165
+ return Qfalse;
166
+ }
167
+ return Qfalse;
168
+ }
169
+
157
170
  static VALUE render_class_component(VALUE vnode, VALUE context, VNode *v) {
158
171
  VALUE node_type = v->type;
159
172
  VALUE props = v->props;
@@ -197,7 +210,13 @@ static VALUE render_class_component(VALUE vnode, VALUE context, VNode *v) {
197
210
  rb_obj_freeze(rb_ivar_get(c, iv_state));
198
211
 
199
212
  // render
200
- return rb_funcall(c, id_render, 0);
213
+ VALUE pr = rb_funcall(mPreact, id_render_buffer, 0);
214
+ rb_ary_push(pr, rb_ary_new());
215
+ VALUE block_result = rb_funcall(c, id_render, 0);
216
+ VALUE render_result = rb_ary_pop(pr);
217
+ if (is_renderable_q(mPreact, block_result) == Qtrue)
218
+ rb_ary_push(render_result, block_result);
219
+ return render_result;
201
220
  }
202
221
 
203
222
  void internal_render_to_string(VALUE vnode, VALUE context, VALUE is_svg_mode,
@@ -213,8 +232,9 @@ void internal_render_to_string(VALUE vnode, VALUE context, VALUE is_svg_mode,
213
232
  return;
214
233
  rb_str_buf_append(rres, rb_funcall(self, id_encode_entities, 1, vnode));
215
234
  return;
216
- case T_FIXNUM:
217
235
  case T_BIGNUM:
236
+ case T_FIXNUM:
237
+ case T_FLOAT:
218
238
  rb_str_buf_append(rres, rb_funcall(vnode, id_to_s, 0));
219
239
  return;
220
240
  case T_ARRAY:
@@ -413,27 +433,6 @@ static VALUE render_to_string(int argc, VALUE *argv, VALUE self) {
413
433
  return res;
414
434
  }
415
435
 
416
- static VALUE is_renderable_q(VALUE self, VALUE block_result) {
417
- switch (TYPE(block_result)) {
418
- case T_BIGNUM:
419
- case T_FIXNUM:
420
- case T_FLOAT:
421
- case T_STRING:
422
- return Qtrue;
423
- case T_ARRAY:
424
- if (RARRAY_LEN(block_result) > 0)
425
- return is_renderable_q(self, RARRAY_PTR(block_result)[0]);
426
- return Qfalse;
427
- case T_DATA:
428
- if (RBASIC_CLASS(block_result) == cVNode)
429
- return Qtrue;
430
- return Qfalse;
431
- default:
432
- return Qfalse;
433
- }
434
- return Qfalse;
435
- }
436
-
437
436
  static VALUE create_element(int argc, VALUE *argv, VALUE self) {
438
437
  if (argc < 1 || argc > 3)
439
438
  rb_raise(rb_eArgError, "wrong argument count, required arg: type, optional "
@@ -478,7 +477,11 @@ static VALUE create_element(int argc, VALUE *argv, VALUE self) {
478
477
 
479
478
  static VALUE render_element(int argc, VALUE *argv, VALUE self) {
480
479
  VALUE pr = rb_funcall(self, id_render_buffer, 0);
481
- rb_ary_push(RARRAY_PTR(pr)[RARRAY_LEN(pr) - 1], create_element(argc, argv, self));
480
+ long len = RARRAY_LEN(pr);
481
+ if (len > 0)
482
+ rb_ary_push(RARRAY_PTR(pr)[len - 1], create_element(argc, argv, self));
483
+ else
484
+ rb_ary_push(pr, create_element(argc, argv, self));
482
485
  return Qnil;
483
486
  }
484
487
 
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Preact
3
- VERSION = '23.6.0.rc5'
3
+ VERSION = '23.7.0.rc1'
4
4
  end
5
5
  end
data/lib/link.rb CHANGED
@@ -48,6 +48,6 @@ class Link < Preact::Component
48
48
  }
49
49
  # wraps children in `a` if needed
50
50
  a = children.is_a?(VNode) ? children : Preact.create_element("a", props)
51
- Preact.clone_element(a, extra_props)
51
+ RPE(Preact.clone_element(a, extra_props))
52
52
  end
53
53
  end
data/lib/lucid_app.rb CHANGED
@@ -6,13 +6,13 @@ class LucidApp < LucidComponent
6
6
 
7
7
  def render(&block)
8
8
  define_method(:render) do
9
+ block_result = _internal_render(&block)
9
10
  pr = ::Preact.render_buffer
10
- block_result = _internal_render(pr, &block)
11
11
  children = pr.pop
12
12
  if ::Preact.is_renderable?(block_result)
13
13
  children << block_result
14
14
  end
15
- ::Preact.create_element(::LucidApplicationContext.Provider, state[:_app_ctx], children)
15
+ pr << [::Preact.create_element(::LucidApplicationContext.Provider, state[:_app_ctx], children)]
16
16
  end
17
17
  end
18
18
 
@@ -8,13 +8,7 @@ class LucidComponent < Preact::Component
8
8
 
9
9
  def render(&block)
10
10
  define_method(:render) do
11
- pr = Preact.render_buffer
12
- block_result = _internal_render(pr, &block)
13
- if Preact.is_renderable?(block_result)
14
- pr.pop << block_result
15
- else
16
- pr.pop
17
- end
11
+ _internal_render(&block)
18
12
  end
19
13
  end
20
14
 
@@ -80,8 +74,7 @@ class LucidComponent < Preact::Component
80
74
  @styles = @self_class.css_styles
81
75
  end
82
76
 
83
- def _internal_render(pr, &block)
84
- pr << []
77
+ def _internal_render(&block)
85
78
  outer_loading = ::Isomorfeus.something_loading?
86
79
  ex = nil
87
80
  begin
@@ -91,8 +84,8 @@ class LucidComponent < Preact::Component
91
84
  end
92
85
  if ::Isomorfeus.something_loading?
93
86
  STDERR.puts "#{@class_name} component still loading ...\n#{ex.message}\n#{ex.backtrace&.join("\n")}" if ex && ::Isomorfeus.development?
94
- pr[pr.length-1].clear
95
- block_result = @while_loading_block ? instance_exec(&@while_loading_block) : ::Preact.create_element('div')
87
+ ::Preact.render_buffer.last.clear
88
+ block_result = @while_loading_block ? instance_exec(&@while_loading_block) : RPE(::Preact.create_element('div'))
96
89
  elsif ex
97
90
  raise ex
98
91
  end
@@ -74,14 +74,7 @@ module Preact
74
74
 
75
75
  def render(&block)
76
76
  define_method(:render) do
77
- pr = Preact.render_buffer
78
- pr << []
79
- block_result = instance_exec(&block)
80
- if Preact.is_renderable?(block_result)
81
- pr.pop << block_result
82
- else
83
- pr.pop
84
- end
77
+ instance_exec(&block)
85
78
  end
86
79
  end
87
80
 
@@ -30,7 +30,7 @@ module Preact
30
30
  end
31
31
 
32
32
  def render
33
- @props[:children]
33
+ RPE(@props[:children])
34
34
  end
35
35
 
36
36
  def should_component_update?(next_props, _next_state, _context)
@@ -25,13 +25,15 @@ module Preact::HtmlElements
25
25
  ]
26
26
 
27
27
  if RUBY_ENGINE == 'opal'
28
+ %x{
29
+ const $op = Opal.Preact;
30
+ }
31
+
28
32
  SUPPORTED_HTML_ELEMENTS.each do |element|
29
33
  define_method(element.underscore.JS.toUpperCase()) do |props = nil, &block|
30
34
  %x{
31
- const op = Opal.Preact;
32
- const opr = op.render_buffer;
33
- if (typeof block === 'function') op.$create_element.$$p = block.$to_proc();
34
- opr[opr.length-1].push(op.$create_element(element, props, nil));
35
+ if (typeof block === 'function') $op.$_render_element.$$p = block;
36
+ $op.$_render_element(element, props, block)
35
37
  }
36
38
  end
37
39
  end
@@ -43,6 +45,7 @@ module Preact::HtmlElements
43
45
  end
44
46
  end
45
47
 
48
+ # Get Preact Element from render buffer
46
49
  def GPE(arg, &block)
47
50
  if block_given?
48
51
  el = block.call
@@ -51,6 +54,7 @@ module Preact::HtmlElements
51
54
  ::Preact.render_buffer.last.pop
52
55
  end
53
56
 
57
+ # Render Preact Element to render buffer
54
58
  def RPE(el)
55
59
  ::Preact.render_buffer.last << el
56
60
  nil
@@ -33,13 +33,15 @@ module Preact::MathMlElements
33
33
  ]
34
34
 
35
35
  if RUBY_ENGINE == 'opal'
36
+ %x{
37
+ const $op = Opal.Preact;
38
+ }
39
+
36
40
  SUPPORTED_MATH_ML_ELEMENTS.each do |element|
37
41
  define_method(element.underscore.JS.toUpperCase()) do |props = nil, &block|
38
42
  %x{
39
- const op = Opal.Preact;
40
- const opr = op.render_buffer;
41
- if (typeof block === 'function') op.$create_element.$$p = block.$to_proc();
42
- opr[opr.length-1].push(op.$create_element(element, props, nil));
43
+ if (typeof block === 'function') $op.$_render_element.$$p = block;
44
+ $op.$_render_element(element, props, block)
43
45
  }
44
46
  end
45
47
  end
@@ -45,13 +45,15 @@ module Preact::SvgElements
45
45
  ]
46
46
 
47
47
  if RUBY_ENGINE == 'opal'
48
+ %x{
49
+ const $op = Opal.Preact;
50
+ }
51
+
48
52
  SUPPORTED_SVG_ELEMENTS.each do |element|
49
53
  define_method(element.underscore.JS.toUpperCase()) do |props = nil, &block|
50
54
  %x{
51
- const op = Opal.Preact;
52
- const opr = op.render_buffer;
53
- if (typeof block === 'function') op.$create_element.$$p = block.$to_proc();
54
- opr[opr.length-1].push(op.$create_element(element, props, nil));
55
+ if (typeof block === 'function') $op.$_render_element.$$p = block;
56
+ $op.$_render_element(element, props, block)
55
57
  }
56
58
  end
57
59
  end
data/lib/preact.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # helpers: hash2, hash_get, hash_put
2
+
1
3
  if RUBY_ENGINE == 'opal'
2
4
  class VNode
3
5
  # just a empty place holder to make is_a?(VNode) work
@@ -10,8 +12,18 @@ class Fragment
10
12
  @props = props
11
13
  end
12
14
 
13
- def render
14
- @props[:children]
15
+ if RUBY_ENGINE == 'opal'
16
+ def render
17
+ `Opal.Preact.render_buffer.pop()`
18
+ children = @props[:children]
19
+ `Opal.Preact.render_buffer.push(children.$$is_array ? children : [children])`
20
+ nil
21
+ end
22
+ else
23
+ def render
24
+ ::Preact.render_buffer.pop
25
+ ::Preact.render_buffer.push(@props[:children])
26
+ end
15
27
  end
16
28
  end
17
29
 
@@ -50,10 +62,15 @@ module Preact
50
62
  throw error;
51
63
  }
52
64
 
53
- const EMPTY_OBJ = {};
65
+ const EMPTY_OBJ = Object.create(null);
54
66
  const EMPTY_ARR = [];
55
67
  const slice = EMPTY_ARR.slice;
56
- const isArray = Array.isArray;
68
+ const $has_own = Object.hasOwn || $call.bind(Object.prototype.hasOwnProperty);
69
+
70
+ function hash_fetch(hash, key) {
71
+ let val = $hash_get(hash, key);
72
+ return (val === undefined || val === null) ? nil : val;
73
+ }
57
74
 
58
75
  function assign(obj, props) {
59
76
  for (let i in props) obj[i] = props[i];
@@ -67,7 +84,7 @@ module Preact
67
84
  else if (typeof value.$$class !== 'undefined') { converted_value = value; }
68
85
  else if (value instanceof Element || value instanceof Node) { converted_value = #{Browser::Element.new(`value`)}; }
69
86
  if (typeof ref === "function") ref.$call(converted_value);
70
- else ref["$[]="]("current", converted_value);
87
+ else $hash_put(ref, "current", converted_value);
71
88
  } catch (e) {
72
89
  _catchError(e, vnode);
73
90
  }
@@ -98,7 +115,7 @@ module Preact
98
115
  // Only climb up and search the parent if we aren't searching through a DOM
99
116
  // VNode (meaning we reached the DOM parent of the original vnode that began
100
117
  // the search)
101
- return typeof vnode.type == 'function' ? getDomSibling(vnode) : null;
118
+ return typeof vnode.type === 'function' ? getDomSibling(vnode) : null;
102
119
  }
103
120
 
104
121
  function placeChild(
@@ -166,7 +183,7 @@ module Preact
166
183
  // (childVNode here).
167
184
  vnode._parent = childVNode;
168
185
 
169
- if (typeof vnode.type == 'function') {
186
+ if (typeof vnode.type === 'function') {
170
187
  oldDom = reorderChildren(vnode, oldDom, parentDom);
171
188
  } else {
172
189
  oldDom = placeChild(
@@ -197,7 +214,7 @@ module Preact
197
214
  if (typeof r === "function") {
198
215
  applyRef(r, null, parentVNode);
199
216
  } else {
200
- let rc = r["$[]"]("current");
217
+ let rc = hash_fetch(r, "current");
201
218
  if (rc === nil || rc === vnode._dom) { applyRef(r, null, parentVNode); }
202
219
  }
203
220
  } catch (e) {
@@ -220,7 +237,7 @@ module Preact
220
237
  if ((r = vnode._children)) {
221
238
  for (let i = 0; i < r.length; i++) {
222
239
  if (r[i]) {
223
- self.unmount(r[i], parentVNode, typeof vnode.type != 'function');
240
+ self.unmount(r[i], parentVNode, typeof vnode.type !== 'function');
224
241
  }
225
242
  }
226
243
  }
@@ -256,13 +273,13 @@ module Preact
256
273
  for (i = 0; i < renderResult.length; i++) {
257
274
  childVNode = renderResult[i];
258
275
 
259
- if (childVNode === nil || childVNode == null || typeof childVNode == 'boolean' || childVNode.$$is_boolean) {
276
+ if (childVNode === nil || childVNode == null || typeof childVNode === 'boolean' || childVNode.$$is_boolean) {
260
277
  childVNode = newParentVNode._children[i] = null;
261
278
  }
262
279
  // If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
263
280
  // or we are rendering a component (e.g. setState) copy the oldVNodes so it can have
264
281
  // it's own DOM & etc. pointers
265
- else if (typeof childVNode == 'string' || typeof childVNode == 'number' || typeof childVNode == 'bigint') {
282
+ else if (typeof childVNode === 'string' || typeof childVNode === 'number' || typeof childVNode === 'bigint') {
266
283
  childVNode = newParentVNode._children[i] = self.createVNode(
267
284
  null,
268
285
  childVNode,
@@ -279,7 +296,7 @@ module Preact
279
296
  null,
280
297
  str
281
298
  );
282
- } else if (isArray(childVNode)) {
299
+ } else if (childVNode.$$is_array) {
283
300
  childVNode = newParentVNode._children[i] = self.createVNode(
284
301
  Opal.Fragment,
285
302
  #{{ children: `childVNode` }},
@@ -389,7 +406,7 @@ module Preact
389
406
  );
390
407
  }
391
408
 
392
- if (typeof newParentVNode.type == 'function') {
409
+ if (typeof newParentVNode.type === 'function') {
393
410
  // Because the newParentVNode is Fragment-like, we need to set it's
394
411
  // _nextDom property to the nextSibling of its last child DOM node.
395
412
  //
@@ -567,14 +584,14 @@ module Preact
567
584
 
568
585
  function diff_props(dom, new_props, old_props, is_svg, hydrate) {
569
586
  #{`old_props`.each do |prop, value|
570
- `if (prop !== "children" && prop !== "key" && !(prop.$$is_string && Object.hasOwnProperty.call(new_props.$$smap, prop))) { self.setProperty(dom, prop, null, value, is_svg); }`
587
+ `if (prop !== "children" && prop !== "key" && !(prop.$$is_string && $has_own(new_props.$$smap, prop))) { self.setProperty(dom, prop, null, value, is_svg); }`
571
588
  nil
572
589
  end
573
590
  `new_props`.each do |prop, value|
574
591
  if (`!hydrate || (prop[0] === 'o' && prop[1] === 'n' && prop[2] === '_')` || value.is_a?(Proc)) &&
575
592
  `prop !== "children" && prop !== "key" && prop !== "value" && prop !== "checked"` &&
576
- ((p = `old_props`[prop]) ? p : nil) != value
577
- `self.setProperty(dom, prop, value, old_props["$[]"](prop), is_svg)`
593
+ `hash_fetch(old_props, prop)` != value
594
+ `self.setProperty(dom, prop, value, hash_fetch(old_props, prop), is_svg)`
578
595
  end
579
596
  end
580
597
  }
@@ -653,10 +670,10 @@ module Preact
653
670
  // If excessDomChildren was not null, repopulate it with the current element's children:
654
671
  excessDomChildren = excessDomChildren && slice.call(dom.childNodes);
655
672
 
656
- oldProps = oldVNode.props || Opal.hash();
673
+ oldProps = oldVNode.props || $hash2([], {});
657
674
 
658
- let oldHtml = oldProps["$[]"]("dangerouslySetInnerHTML");
659
- let newHtml = newProps["$[]"]("dangerouslySetInnerHTML");
675
+ let oldHtml = hash_fetch(oldProps, "dangerouslySetInnerHTML");
676
+ let newHtml = hash_fetch(newProps, "dangerouslySetInnerHTML");
660
677
 
661
678
  // During hydration, props are not diffed at all (including dangerouslySetInnerHTML)
662
679
  // @TODO we should warn in debug mode when props don't match here.
@@ -664,9 +681,9 @@ module Preact
664
681
  // But, if we are in a situation where we are using existing DOM (e.g. replaceNode)
665
682
  // we should read the existing DOM attributes to diff them
666
683
  if (excessDomChildren != null) {
667
- oldProps = Opal.hash();
684
+ oldProps = $hash2([], {});
668
685
  for (i = 0; i < dom.attributes.length; i++) {
669
- oldProps["$[]="](dom.attributes[i].name, dom.attributes[i].value);
686
+ $hash_put(oldProps, dom.attributes[i].name, dom.attributes[i].value);
670
687
  }
671
688
  }
672
689
 
@@ -674,10 +691,10 @@ module Preact
674
691
  // Avoid re-applying the same '__html' if it has not changed between re-render
675
692
  if (
676
693
  newHtml === nil ||
677
- ((oldHtml === nil || newHtml["$[]"]("__html") != oldHtml["$[]"]("__html")) &&
678
- newHtml["$[]"]("__html") !== dom.innerHTML)
694
+ ((oldHtml === nil || hash_fetch(newHtml, "__html") != hash_fetch(oldHtml, "__html")) &&
695
+ hash_fetch(newHtml, "__html") !== dom.innerHTML)
679
696
  ) {
680
- dom.innerHTML = (newHtml !== nil && newHtml["$[]"]("__html")) || '';
697
+ dom.innerHTML = (newHtml !== nil && hash_fetch(newHtml, "__html")) || '';
681
698
  }
682
699
  }
683
700
  }
@@ -688,10 +705,10 @@ module Preact
688
705
  if (newHtml !== nil) {
689
706
  newVNode._children = [];
690
707
  } else {
691
- i = newVNode.props["$[]"]("children");
708
+ i = hash_fetch(newVNode.props, "children");
692
709
  diffChildren(
693
710
  dom,
694
- isArray(i) ? i : [i],
711
+ i.$$is_array ? i : [i],
695
712
  newVNode,
696
713
  oldVNode,
697
714
  globalContext,
@@ -716,8 +733,8 @@ module Preact
716
733
  if (!isHydrating) {
717
734
  if (
718
735
  // instead of newProps["$key?"]("value")
719
- Object.hasOwnProperty.call(newProps.$$smap, "value") &&
720
- (i = newProps["$[]"]("value")) !== nil &&
736
+ $has_own(newProps.$$smap, "value") &&
737
+ (i = hash_fetch(newProps, "value")) !== nil &&
721
738
  // #2756 For the <progress>-element the initial value is 0,
722
739
  // despite the attribute not being present. When the attribute
723
740
  // is missing the progress bar is treated as indeterminate.
@@ -726,16 +743,16 @@ module Preact
726
743
  // This is only for IE 11 to fix <select> value not being updated.
727
744
  // To avoid a stale select value we need to set the option.value
728
745
  // again, which triggers IE11 to re-evaluate the select value
729
- (nodeType === 'option' && i !== oldProps["$[]"]("value")))
746
+ (nodeType === 'option' && i !== hash_fetch(oldProps, "value")))
730
747
  ) {
731
- self.setProperty(dom, 'value', i, oldProps["$[]"]("value"), false, null);
748
+ self.setProperty(dom, 'value', i, hash_fetch(oldProps, "value"), false, null);
732
749
  }
733
750
  if (
734
- Object.hasOwnProperty.call(newProps.$$smap, "checked") &&
735
- (i = newProps["$[]"]("checked")) !== nil &&
751
+ $has_own(newProps.$$smap, "checked") &&
752
+ (i = hash_fetch(newProps, "checked")) !== nil &&
736
753
  i !== dom.checked
737
754
  ) {
738
- self.setProperty(dom, 'checked', i, oldProps["$[]"]("checked"), false, null);
755
+ self.setProperty(dom, 'checked', i, hash_fetch(oldProps, "checked"), false, null);
739
756
  }
740
757
  }
741
758
  }
@@ -747,7 +764,7 @@ module Preact
747
764
  if (newType.declared_props && newType.declared_props !== nil) {
748
765
  #{
749
766
  `newType.declared_props`.each do |prop, value|
750
- `if (Object.hasOwnProperty.call(value.$$smap, "default") && !Object.hasOwnProperty.call(newProps.$$smap, prop)) { #{`newProps`[prop] = value[:default]} }`
767
+ `if ($has_own(value.$$smap, "default") && !$has_own(newProps.$$smap, prop)) { #{`newProps`[prop] = value[:default]} }`
751
768
  nil
752
769
  end
753
770
  }
@@ -782,15 +799,15 @@ module Preact
782
799
  }
783
800
 
784
801
  try {
785
- outer: if (typeof newType == 'function') {
802
+ outer: if (typeof newType === 'function') {
786
803
  let c, ctxType, isNew, oldProps, oldState, renderResult, snapshot, clearProcessingException;
787
804
  let newProps = newVNode.props;
788
805
 
789
806
  // Necessary for createContext api. Setting this property will pass
790
807
  // the context value as `this.context` just for this component.
791
808
  ctxType = newType.context_type;
792
- let provider = (ctxType && ctxType !== nil) && globalContext["$[]"](ctxType.context_id);
793
- let componentContext = (ctxType && ctxType !== nil) ? ((provider && provider !== nil) ? provider.props["$[]"]("value") : ctxType.value) : globalContext;
809
+ let provider = (ctxType && ctxType !== nil) && hash_fetch(globalContext, ctxType.context_id);
810
+ let componentContext = (ctxType && ctxType !== nil) ? ((provider && provider !== nil) ? hash_fetch(provider.props, "value") : ctxType.value) : globalContext;
794
811
 
795
812
  // Get component and set it to `c`
796
813
  if (oldVNode._component) {
@@ -807,7 +824,7 @@ module Preact
807
824
  if (provider && provider !== nil) provider.$sub(c);
808
825
 
809
826
  c.props = newProps;
810
- if (c.state === nil || !c.state) c.state = Opal.hash();
827
+ if (c.state === nil || !c.state) c.state = $hash2([], {});
811
828
  c.context = componentContext;
812
829
  c._globalContext = globalContext;
813
830
  isNew = c._dirty = true;
@@ -819,8 +836,11 @@ module Preact
819
836
  c._nextState = c.state;
820
837
  }
821
838
 
822
- if (!isNew) { validate_props(newType, newProps); }
823
- newProps.$freeze();
839
+ if (!isNew) {
840
+ validate_props(newType, newProps);
841
+ newProps.$freeze();
842
+ }
843
+
824
844
  if (c["$respond_to?"]("get_derived_state_from_props")) {
825
845
  if (c._nextState == c.state) {
826
846
  c._nextState = c._nextState.$dup();
@@ -879,7 +899,12 @@ module Preact
879
899
  c.state = c._nextState;
880
900
  c._dirty = false;
881
901
 
882
- renderResult = c.$render();
902
+ self.render_buffer.push([])
903
+ const block_result = c.$render();
904
+ renderResult = self.render_buffer.pop()
905
+ if (self["$is_renderable?"](block_result)) {
906
+ renderResult.push(block_result);
907
+ }
883
908
 
884
909
  // Handle setState called in render, see #2553
885
910
  c.state = c._nextState;
@@ -892,13 +917,9 @@ module Preact
892
917
  snapshot = c.$get_snapshot_before_update(oldProps, oldState);
893
918
  }
894
919
 
895
- if (renderResult !== nil && renderResult != null && renderResult.type === Opal.Fragment && renderResult.key == null) {
896
- renderResult = renderResult.props["$[]"]("children");
897
- }
898
-
899
920
  diffChildren(
900
921
  parentDom,
901
- isArray(renderResult) ? renderResult : [renderResult],
922
+ renderResult, // always is a array
902
923
  newVNode,
903
924
  oldVNode,
904
925
  globalContext,
@@ -973,23 +994,13 @@ module Preact
973
994
  }
974
995
 
975
996
  let vnodeId = 0;
976
- const vnode_class = #{::VNode};
977
-
978
- function is_a_vnode(type) { return type === vnode_class; }
979
- function is_nil() { return false; }
980
- function vnode_eql(me, other) {
981
- for(let prop in me) {
982
- if (prop === 'props') { continue; }
983
- else if (me[prop] != other[prop]) { return false; }
984
- }
985
- return me.props["$=="](other.props);
986
- }
997
+
998
+ function is_a_vnode(type) { return type === Opal.VNode; }
987
999
 
988
1000
  self.createVNode = function(type, props, key, ref, original) {
989
1001
  // V8 seems to be better at detecting type shapes if the object is allocated from the same call site
990
1002
  // Do not inline into createElement and coerceToVNode!
991
- let eql;
992
- const vnode = {
1003
+ return {
993
1004
  type,
994
1005
  props,
995
1006
  key,
@@ -1008,12 +1019,8 @@ module Preact
1008
1019
  constructor: undefined,
1009
1020
  _original: (original == null) ? ++vnodeId : original,
1010
1021
  "$is_a?": is_a_vnode,
1011
- "$==": eql = function(other) { return vnode_eql(vnode, other); },
1012
- "$eql?": eql,
1013
- "$nil?": is_nil,
1014
1022
  "$$is_vnode": true
1015
1023
  };
1016
- return vnode;
1017
1024
  }
1018
1025
 
1019
1026
  self.render = function(vnode, parentDom, replaceNode) {
@@ -1048,7 +1055,7 @@ module Preact
1048
1055
  // our custom `_children` property.
1049
1056
  vnode,
1050
1057
  ov ? oldVNode : EMPTY_OBJ,
1051
- Opal.hash(),
1058
+ $hash2([], {}),
1052
1059
  parentDom.ownerSVGElement !== undefined,
1053
1060
  nohy_reno ? [replaceNode] : ov ? null : parentDom.firstChild ? slice.call(parentDom.childNodes) : null,
1054
1061
  commitQueue,
@@ -1180,10 +1187,8 @@ module Preact
1180
1187
  attr_accessor :render_buffer
1181
1188
  attr_accessor :rerender_queue
1182
1189
 
1183
- def is_renderable?(block_result)
1184
- block_result &&
1185
- (block_result.JS['$$is_vnode'] || block_result.JS['$$is_string'] || block_result.is_a?(Numeric) ||
1186
- (block_result.JS['$$is_array'] && `block_result.length > 0` && is_renderable?(block_result[0])))
1190
+ def is_renderable?(res)
1191
+ `(res !== null && res !== undefined && res !== nil && (res.$$is_string || res.$$is_number))`
1187
1192
  end
1188
1193
 
1189
1194
  def create_element(type, props = nil, children = nil)
@@ -1205,9 +1210,9 @@ module Preact
1205
1210
  end
1206
1211
 
1207
1212
  if block_given?
1208
- `self.render_buffer.push([])`
1209
- block_result = yield
1210
1213
  %x{
1214
+ self.render_buffer.push([]);
1215
+ const block_result = $yield();
1211
1216
  const c = self.render_buffer.pop();
1212
1217
  if (self["$is_renderable?"](block_result)) { c.push(block_result); }
1213
1218
  if (c.length > 0) { children = c; }
@@ -1215,7 +1220,7 @@ module Preact
1215
1220
  end
1216
1221
 
1217
1222
  %x{
1218
- if (children !== nil && children !== null) { normalized_props["$[]="]("children", children); }
1223
+ if (children !== nil && children !== null) { $hash_put(normalized_props, "children", children); }
1219
1224
  return self.createVNode(type, normalized_props, key, ref, null);
1220
1225
  }
1221
1226
  end
@@ -1229,8 +1234,9 @@ module Preact
1229
1234
  def _render_element(component, props, &block)
1230
1235
  %x{
1231
1236
  const opr = self.render_buffer;
1232
- if (typeof block === 'function') self.$create_element.$$p = block.$to_proc();
1233
- opr[opr.length-1].push(self.$create_element(component, props, nil));
1237
+ if (typeof block === 'function') self.$create_element.$$p = block;
1238
+ if (opr.length > 0) { opr[opr.length-1].push(self.$create_element(component, props, nil)); }
1239
+ else { opr.push(self.$create_element(component, props, nil)); }
1234
1240
  }
1235
1241
  nil
1236
1242
  end
data/lib/route.rb CHANGED
@@ -10,9 +10,9 @@ class Route < Preact::Component
10
10
  component_props = props[:component_props] || {}
11
11
  if component
12
12
  component = component.constantize if component.is_a?(String)
13
- Preact.create_element(component, component_props.merge!({ params: params }))
13
+ RPE(Preact.create_element(component, component_props.merge!({ params: params })))
14
14
  else
15
- props[:children]
15
+ RPE(props[:children])
16
16
  end
17
17
  end
18
18
  end
data/lib/router.rb CHANGED
@@ -126,7 +126,7 @@ class Router < Preact::Component
126
126
  @original_location = @router[:original_location]
127
127
  loc = @browser ? current_pathname(@rbase) : current_pathname(@rbase, @original_location)
128
128
  @prev_hash = @browser ? loc + `location.search` : loc
129
- Preact.create_element(RouterContext.Provider, { value: { router: @router, location: loc }, children: props[:children] })
129
+ RPE(Preact.create_element(RouterContext.Provider, { value: { router: @router, location: loc }, children: props[:children] }))
130
130
  end
131
131
 
132
132
  component_did_mount do
data/lib/switch.rb CHANGED
@@ -54,7 +54,6 @@ class Switch < Preact::Component
54
54
  originalLocation = router[:originalLocation]
55
55
  children = flatten(props[:children])
56
56
  location = props[:location]
57
- child = nil
58
57
  if RUBY_ENGINE == 'opal'
59
58
  children.each do |vnode|
60
59
  match = nil
@@ -63,7 +62,7 @@ class Switch < Preact::Component
63
62
  # this allows to use different components that wrap Route
64
63
  # inside of a switch, for example <AnimatedRoute />.
65
64
  if vnode.is_a?(VNode) && (match = (p = vnode.JS[:props][:path]) ? matcher.call(p, location || @context[:location]) : [true, {}])[0]
66
- child = Preact.clone_element(vnode, { match: match })
65
+ RPE(Preact.clone_element(vnode, { match: match }))
67
66
  break
68
67
  end
69
68
  end
@@ -71,11 +70,10 @@ class Switch < Preact::Component
71
70
  children.each do |vnode|
72
71
  match = nil
73
72
  if vnode.is_a?(VNode) && (match = (p = vnode.props[:path]) ? matcher.call(p, location || @context[:location]) : [true, {}])[0]
74
- child = Preact.clone_element(vnode, { match: match })
73
+ RPE(Preact.clone_element(vnode, { match: match }))
75
74
  break
76
75
  end
77
76
  end
78
77
  end
79
- child
80
78
  end
81
79
  end
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: 23.6.0.rc5
4
+ version: 23.7.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-22 00:00:00.000000000 Z
11
+ date: 2023-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -78,28 +78,28 @@ dependencies:
78
78
  requirements:
79
79
  - - '='
80
80
  - !ruby/object:Gem::Version
81
- version: 23.6.0.rc5
81
+ version: 23.7.0.rc1
82
82
  type: :runtime
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - '='
87
87
  - !ruby/object:Gem::Version
88
- version: 23.6.0.rc5
88
+ version: 23.7.0.rc1
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: isomorfeus-redux
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - '='
94
94
  - !ruby/object:Gem::Version
95
- version: 23.6.0.rc5
95
+ version: 23.7.0.rc1
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - '='
101
101
  - !ruby/object:Gem::Version
102
- version: 23.6.0.rc5
102
+ version: 23.7.0.rc1
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: benchmark-ips
105
105
  requirement: !ruby/object:Gem::Requirement