isomorfeus-preact 23.9.0.rc5 → 23.9.0.rc6

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: 6d444d107a9f4342d932c6ee2874ce754c8fe7bffbbdb5dc484a9e068fae3cdd
4
- data.tar.gz: 53b6ee295e9104a4fcdb57b993641e9f9856a20498f991e4172d0554d1fcdb02
3
+ metadata.gz: d5aa4a25a9b3f27b2951a433289c589471801da4b3b66d1819bb75d70199808d
4
+ data.tar.gz: b4f0f1192906a0bfee1d47d484c166a5e065756f6b52f80efc5a384e2812b1dc
5
5
  SHA512:
6
- metadata.gz: 59a632dc3ea15976a62cb50d98b113d0681c6c786fce8806c07a76285454da61e639499556dc0a440ca3f5a7491db64826b9cd2cbed20efa3b5e62bd554f3add
7
- data.tar.gz: a3dedb4b6551c642584aea4db408c816253a9200e586898d5fa1c356f930fbe6d16d39cd1e9bebab0ffc5a48a2027091f210864911314eac8d843f24aa73bf31
6
+ metadata.gz: 2602c1a0568bb8db7288dd6c5cc4d24660810012d6ac01bede2fbaf6a79e1bc17aceeb27261f0aa02392531aa19c2247148b9fe84424048f707ff49e30dc620c
7
+ data.tar.gz: '087bd77fb267ccb1d04b38264d98e295255c5e9fa30f4877e7e93843712b8cf03e77659d01f23160b753295bfc7626ebecfaa636261d618436701044b3549ea8'
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Preact
3
- VERSION = '23.9.0.rc5'
3
+ VERSION = '23.9.0.rc6'
4
4
  end
5
5
  end
data/lib/preact.rb CHANGED
@@ -2,9 +2,49 @@
2
2
  # helpers: hash_get, hash_put
3
3
 
4
4
  if RUBY_ENGINE == 'opal'
5
- class VNode
6
- # just a empty place holder to make is_a?(VNode) work
7
- # internally using the js implementation
5
+ %x{
6
+ let vnodeId = 0;
7
+
8
+ function vnode_eql(me, other) {
9
+ for(let prop in me) {
10
+ if (prop === 'props' && !(me[prop]["$=="](other[prop]))) {
11
+ return false;
12
+ } else if (me[prop] != other[prop]) {
13
+ return false;
14
+ }
15
+ }
16
+ return true;
17
+ }
18
+
19
+ class VNode {
20
+ constructor(type, props, key, ref, original) {
21
+ this.type = type;
22
+ this.props = props;
23
+ this.key = key;
24
+ this.ref = ref;
25
+ this._children = null;
26
+ this._parent = null;
27
+ this._depth = 0;
28
+ this._dom = null;
29
+ this._nextDom = undefined;
30
+ this._component = null;
31
+ this._hydrating = null;
32
+ this._original = (original == null || original == nil) ? ++vnodeId : original;
33
+ this.constructor = undefined;
34
+ }
35
+ "$=="(other) { return vnode_eql(this, other); }
36
+ "$eql?"(other) { return vnode_eql(this, other); }
37
+ "$is_a?"(t) { return t === Opal.VNode; }
38
+ "$type"() { return this.type; }
39
+ "$props"() { return this.props; }
40
+ "$key"() { return this.key; }
41
+ "$ref"() { return this.ref; }
42
+ }
43
+ }
44
+ class VNode < `VNode`
45
+ def self.new(type, props, key, ref, original)
46
+ return `new VNode(type, props, key, ref, original)`
47
+ end
8
48
  end
9
49
  end
10
50
 
@@ -13,18 +53,9 @@ class Fragment
13
53
  @props = props
14
54
  end
15
55
 
16
- if RUBY_ENGINE == 'opal'
17
- def render
18
- `Opal.Preact.render_buffer.pop()`
19
- children = @props[:children]
20
- `Opal.Preact.render_buffer.push(children.$$is_array ? children : [children])`
21
- nil
22
- end
23
- else
24
- def render
25
- ::Preact.render_buffer.pop
26
- ::Preact.render_buffer.push(@props[:children])
27
- end
56
+ def render
57
+ ::Preact.render_buffer.pop
58
+ ::Preact.render_buffer.push(@props[:children])
28
59
  end
29
60
  end
30
61
 
@@ -34,40 +65,6 @@ module Preact
34
65
 
35
66
  if RUBY_ENGINE == 'opal'
36
67
  %x{
37
- let vnodeId = 0;
38
-
39
- function vnode_eql(me, other) {
40
- for(let prop in me) {
41
- if (prop === 'props' && !(me[prop]["$=="](other[prop]))) {
42
- return false;
43
- } else if (me[prop] != other[prop]) {
44
- return false;
45
- }
46
- }
47
- return true;
48
- }
49
-
50
- class VNode {
51
- constructor(type, props, key, ref, original) {
52
- this.type = type;
53
- this.props = props;
54
- this.key = key;
55
- this.ref = ref;
56
- this._children = null;
57
- this._parent = null;
58
- this._depth = 0;
59
- this._dom = null;
60
- this._nextDom = undefined;
61
- this._component = null;
62
- this._hydrating = null;
63
- this._original = (original == null) ? ++vnodeId : original;
64
- this.constructor = undefined;
65
- }
66
- "$=="(other) { return vnode_eql(this, other); }
67
- "$eql?"(other) { return vnode_eql(this, other); }
68
- "$is_a?"(t) { return t === Opal.VNode; }
69
- }
70
-
71
68
  function _catchError(error, vnode, oldVNode) {
72
69
  let component, ctor, handled;
73
70
 
@@ -97,12 +94,12 @@ module Preact
97
94
  throw error;
98
95
  }
99
96
 
100
- const EMPTY_OBJ = new VNode();
97
+ const EMPTY_VNODE = new VNode();
101
98
  const EMPTY_ARR = [];
102
99
  const slice = EMPTY_ARR.slice;
103
100
 
104
101
  function hash_fetch(hash, key) {
105
- let val = $hash_get(hash, key);
102
+ let val = hash.get(key);
106
103
  return (val === undefined || val === null) ? nil : val;
107
104
  }
108
105
 
@@ -297,8 +294,8 @@ module Preact
297
294
  ) {
298
295
  let i, j, oldVNode, childVNode, newDom, firstChildDom, refs;
299
296
 
300
- // This is a compression of oldParentVNode!=null && oldParentVNode != EMPTY_OBJ && oldParentVNode._children || EMPTY_ARR
301
- // as EMPTY_OBJ._children should be `undefined`.
297
+ // This is a compression of oldParentVNode!=null && oldParentVNode != EMPTY_VNODE && oldParentVNode._children || EMPTY_ARR
298
+ // as EMPTY_VNODE._children should be `undefined`.
302
299
  let oldChildren = (oldParentVNode && oldParentVNode !== nil && oldParentVNode._children) ? oldParentVNode._children : EMPTY_ARR;
303
300
 
304
301
  let oldChildrenLength = oldChildren.length;
@@ -307,7 +304,7 @@ module Preact
307
304
  for (i = 0; i < renderResult.length; i++) {
308
305
  childVNode = renderResult[i];
309
306
 
310
- if (childVNode === nil || childVNode == null || typeof childVNode === 'boolean' || childVNode.$$is_boolean) {
307
+ if (childVNode === nil || childVNode == null || typeof childVNode === 'boolean' || childVNode.$$is_boolean || typeof childVNode === 'number' || childVNode.$$is_number) {
311
308
  childVNode = newParentVNode._children[i] = null;
312
309
  }
313
310
  // If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
@@ -333,7 +330,7 @@ module Preact
333
330
  } else if (childVNode.$$is_array) {
334
331
  childVNode = newParentVNode._children[i] = new VNode(
335
332
  Opal.Fragment,
336
- #{{ children: `childVNode` }},
333
+ new Map([['children', childVNode]]),
337
334
  null,
338
335
  null,
339
336
  null
@@ -357,6 +354,7 @@ module Preact
357
354
  if (childVNode === nil || childVNode == null) {
358
355
  continue;
359
356
  }
357
+
360
358
  childVNode._parent = newParentVNode;
361
359
  childVNode._depth = newParentVNode._depth + 1;
362
360
 
@@ -392,7 +390,7 @@ module Preact
392
390
  }
393
391
  }
394
392
 
395
- oldVNode = (oldVNode && oldVNode !== nil) ? oldVNode : EMPTY_OBJ;
393
+ oldVNode = (oldVNode && oldVNode !== nil) ? oldVNode : EMPTY_VNODE;
396
394
 
397
395
  // Morph the old element into the new one, but don't append it to the dom yet
398
396
  diff(
@@ -792,7 +790,7 @@ module Preact
792
790
  if (newType.declared_props && newType.declared_props !== nil) {
793
791
  #{
794
792
  `newType.declared_props`.each do |prop, value|
795
- `if (value.has("default") && !newProps.has(prop)) { newProps.set(prop, value.get("default")) }`
793
+ `if (value.has("default") && !newProps.has(prop)) { newProps.set(prop, hash_fetch(value, "default")) }`
796
794
  nil
797
795
  end
798
796
  }
@@ -973,7 +971,7 @@ module Preact
973
971
 
974
972
  c._force = false;
975
973
 
976
- } else if (
974
+ } else if (
977
975
  excessDomChildren == null &&
978
976
  newVNode._original === oldVNode._original
979
977
  ) {
@@ -1021,8 +1019,6 @@ module Preact
1021
1019
  });
1022
1020
  }
1023
1021
 
1024
-
1025
-
1026
1022
  self.createVNode = function(type, props, key, ref, original) {
1027
1023
  // V8 seems to be better at detecting type shapes if the object is allocated from the same call site
1028
1024
  // Do not inline into createElement and coerceToVNode!
@@ -1035,7 +1031,7 @@ module Preact
1035
1031
  // element..
1036
1032
  let isHydrating = typeof replaceNode === 'function';
1037
1033
 
1038
- let reno = (replaceNode !== nil && replaceNode);
1034
+ let reno = (replaceNode && replaceNode !== nil);
1039
1035
  let nohy_reno = (!isHydrating && reno);
1040
1036
 
1041
1037
  // To be able to support calling `render()` multiple times on the same
@@ -1049,23 +1045,31 @@ module Preact
1049
1045
 
1050
1046
  let ov = (oldVNode && oldVNode !== nil);
1051
1047
 
1052
- vnode = (
1053
- nohy_reno || parentDom
1054
- )._children = self.$create_element(Opal.Fragment, nil, [vnode]);
1048
+ vnode = (nohy_reno ? replaceNode : parentDom)._children = self.$create_element(Opal.Fragment, nil, [vnode]);
1055
1049
 
1056
1050
  // List of effects that need to be called after diffing.
1057
1051
  let commitQueue = [];
1052
+
1053
+ // Determine the new vnode tree and store it on the DOM element on
1054
+ // our custom `_children` property.
1058
1055
  diff(
1056
+ // parentDom
1059
1057
  parentDom,
1060
- // Determine the new vnode tree and store it on the DOM element on
1061
- // our custom `_children` property.
1058
+ // newVNode
1062
1059
  vnode,
1063
- ov ? oldVNode : EMPTY_OBJ,
1060
+ // oldVNode
1061
+ ov ? oldVNode : EMPTY_VNODE,
1062
+ // globalContext
1064
1063
  new Map(),
1064
+ // isSvg
1065
1065
  parentDom.ownerSVGElement !== undefined,
1066
+ // excessDomChildren
1066
1067
  nohy_reno ? [replaceNode] : ov ? null : parentDom.firstChild ? slice.call(parentDom.childNodes) : null,
1068
+ // commitQueue
1067
1069
  commitQueue,
1070
+ // oldDom
1068
1071
  nohy_reno ? replaceNode : ov ? oldVNode._dom : parentDom.firstChild,
1072
+ // isHydrating
1069
1073
  isHydrating
1070
1074
  );
1071
1075
 
@@ -1119,7 +1123,7 @@ module Preact
1119
1123
 
1120
1124
  self.process = function() {
1121
1125
  let queue;
1122
- while ((self.process._rerenderCount = self.rerender_queue.length)) {
1126
+ while ((self.rerender_count = self.rerender_queue.length)) {
1123
1127
  queue = self.rerender_queue.sort((a, b) => a._vnode._depth - b._vnode._depth);
1124
1128
  self.rerender_queue = [];
1125
1129
  // Don't update `renderCount` yet. Keep its value non-zero to prevent unnecessary
@@ -1129,7 +1133,8 @@ module Preact
1129
1133
  });
1130
1134
  }
1131
1135
  }
1132
- self.process._rerenderCount = 0;
1136
+ self.rerender_count = 0;
1137
+ self.rerender_queue = [];
1133
1138
  }
1134
1139
  else
1135
1140
  IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i.freeze
@@ -1153,11 +1158,7 @@ module Preact
1153
1158
 
1154
1159
  def clone_element(vnode, props = nil, children = nil)
1155
1160
  normalized_props = {}
1156
- if RUBY_ENGINE == 'opal'
1157
- normalized_props.merge!(`vnode.props`)
1158
- else
1159
- normalized_props.merge!(vnode.props)
1160
- end
1161
+ normalized_props.merge!(vnode.props)
1161
1162
 
1162
1163
  if props
1163
1164
  normalized_props.merge!(props)
@@ -1170,11 +1171,7 @@ module Preact
1170
1171
 
1171
1172
  normalized_props[:children] = children unless children.nil?
1172
1173
 
1173
- if RUBY_ENGINE == 'opal'
1174
- `self.createVNode(vnode.type, normalized_props, #{key || `vnode.key`}, #{ref || `vnode.ref`}, null)`
1175
- else
1176
- ::VNode.new(vnode.type, normalized_props, key || vnode.key, ref || vnode.ref)
1177
- end
1174
+ ::VNode.new(vnode.type, normalized_props, key || vnode.key, ref || vnode.ref)
1178
1175
  end
1179
1176
 
1180
1177
  def create_context(const_name, default_value = nil)
@@ -1191,9 +1188,10 @@ module Preact
1191
1188
  if RUBY_ENGINE == 'opal'
1192
1189
  attr_accessor :render_buffer
1193
1190
  attr_accessor :rerender_queue
1191
+ attr_accessor :rerender_count
1194
1192
 
1195
1193
  def is_renderable?(res)
1196
- `(res !== null && res !== undefined && res !== nil && res.$$is_string)`
1194
+ `!!(res && res !== nil && res.$$is_string)`
1197
1195
  end
1198
1196
 
1199
1197
  def create_element(type, props = nil, children = nil)
@@ -1225,13 +1223,20 @@ module Preact
1225
1223
  end
1226
1224
 
1227
1225
  %x{
1228
- if (children !== nil && children !== null) { normalized_props.set("children", children); }
1226
+ if (children !== nil && children !== null) {
1227
+ normalized_props.set("children", children.$$is_array ? children : [children]);
1228
+ } else {
1229
+ children = normalized_props.get("children");
1230
+ if (children && !children.$$is_array) {
1231
+ normalized_props.set("children", [children]);
1232
+ }
1233
+ }
1229
1234
  return self.createVNode(type, normalized_props, key, ref, null);
1230
1235
  }
1231
1236
  end
1232
1237
 
1233
1238
  def _enqueue_render(c)
1234
- if ((`!c._dirty` && (`c._dirty = true`) && (rerender_queue << c) && `!self.process._rerenderCount++`))
1239
+ if ((`!c._dirty` && (`c._dirty = true`) && (self.rerender_queue << c) && `!self.rerender_count++`))
1235
1240
  `setTimeout(self.process)`
1236
1241
  end
1237
1242
  end
@@ -1246,16 +1251,12 @@ module Preact
1246
1251
  nil
1247
1252
  end
1248
1253
 
1249
- def hydrate(vnode, container_node)
1250
- render(vnode, container_node, `self.render`)
1251
- end
1252
-
1253
1254
  def element_or_query_to_n(element_or_query)
1254
1255
  if `!element_or_query || element_or_query === nil`
1255
1256
  return `null`
1256
1257
  elsif `(element_or_query instanceof HTMLElement)`
1257
1258
  return element_or_query
1258
- elsif `(typeof element_or_query === 'string')` || element_or_query.is_a?(String)
1259
+ elsif `(typeof element_or_query === 'string') || element_or_query.$$is_string`
1259
1260
  return `document.body.querySelector(element_or_query)`
1260
1261
  elsif `(typeof element_or_query === 'function')`
1261
1262
  return element_or_query
@@ -1266,6 +1267,10 @@ module Preact
1266
1267
  end
1267
1268
  end
1268
1269
 
1270
+ def hydrate(vnode, container_node)
1271
+ render(vnode, container_node, `self.render`)
1272
+ end
1273
+
1269
1274
  def render(vnode, container_node, replace_node = nil)
1270
1275
  _init_render
1271
1276
  container_node = element_or_query_to_n(container_node)
@@ -1322,4 +1327,3 @@ module Preact
1322
1327
  end # RUBY_ENGINE
1323
1328
  end
1324
1329
  end
1325
-
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.9.0.rc5
4
+ version: 23.9.0.rc6
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-09-16 00:00:00.000000000 Z
11
+ date: 2023-09-17 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.9.0.rc5
81
+ version: 23.9.0.rc6
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.9.0.rc5
88
+ version: 23.9.0.rc6
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.9.0.rc5
95
+ version: 23.9.0.rc6
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.9.0.rc5
102
+ version: 23.9.0.rc6
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: benchmark-ips
105
105
  requirement: !ruby/object:Gem::Requirement