isomorfeus-preact 22.10.0.rc2 → 23.1.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: ed19ddda76f48b8c66af26970d4f7b4e1927b9061bf6ec9080dc40d5e51ff1cd
4
- data.tar.gz: 97cc9fc63e4a06bb9a7d8dd6f7b2d90737f681935bc21f274870658c26e77e5d
3
+ metadata.gz: e85fc4bc0d60fef17a258c8258cd5504d99b2858ee72accca8c8379eae111250
4
+ data.tar.gz: 6d536d46743e666dba8b065b8dc65bd341335abcbdf20f909b41d675f3c28341
5
5
  SHA512:
6
- metadata.gz: e39ee8b131d18503cb85f83b0a3750b32163661aa46d368933f06bf4d09b873c5d1a36a03b2c54c352956c49c785be245530fa65d4eeee2526c583ce6a2f33f2
7
- data.tar.gz: 53961fada45da80ce23e4ef9f1ebbb5bbda85358e410c5cb70f00b5457f4ffff88d1605943bdbaba88c37aed574e1ea3d513f57e69347065b59c60f347104d4c
6
+ metadata.gz: 223fd1527f4cde895a172c2e4316494d6c60ab44e9a82594004a87406429c80b9b4c9071f1a2159594f4c9204dbddd73672ba2f1901c45fb491d6e168e6916aa
7
+ data.tar.gz: 1bc4550c3bd80124883658451a13388e43aaea6cafc50dbcabd8eda1c7a821fc71e048aa65974f0e04d498f31160cbeac101e0c93f246c0947c5d933e6f0f117
@@ -20,6 +20,7 @@ static ID id_downcase;
20
20
  static ID id_encode_entities;
21
21
  static ID id_eqeq;
22
22
  static ID id_for;
23
+ static ID id_freeze;
23
24
  static ID id_get_child_context;
24
25
  static ID id_get_derived_state_from_props;
25
26
  static ID id_gsub;
@@ -155,6 +156,7 @@ VALUE render_class_component(VALUE vnode, VALUE context) {
155
156
 
156
157
  VALUE node_type = v->type;
157
158
  VALUE props = v->props;
159
+ VALUE state = rb_hash_new();
158
160
 
159
161
  // get context
160
162
  VALUE cctx = get_context(node_type, context);
@@ -166,13 +168,16 @@ VALUE render_class_component(VALUE vnode, VALUE context) {
166
168
  if (rb_funcall(mIsomorfeus, id_development, 0) == Qtrue) { rb_funcall(node_type, id_validate_props, 1, props); }
167
169
  }
168
170
 
171
+ // freeze props
172
+ rb_funcall(props, id_freeze, 0);
173
+
169
174
  // instantiate component
170
175
  VALUE c = rb_funcall(node_type, id_new, 2, props, cctx);
171
176
  v->component = c;
172
177
 
173
178
  // set state, props, context
174
179
  rb_ivar_set(c, iv_props, props);
175
- if (rb_funcall(c, id_state, 0) == Qnil) { rb_ivar_set(c, iv_state, rb_hash_new()); }
180
+ if (rb_funcall(c, id_state, 0) == Qnil) { rb_ivar_set(c, iv_state, state); }
176
181
  if (rb_ivar_get(c, iv_next_state) == Qnil) { rb_ivar_set(c, iv_next_state, rb_funcall(c, id_state, 0)); }
177
182
  rb_ivar_set(c, iv_context, cctx);
178
183
 
@@ -183,6 +188,9 @@ VALUE render_class_component(VALUE vnode, VALUE context) {
183
188
  rb_ivar_set(c, iv_state, rb_funcall(state, id_merge, res));
184
189
  }
185
190
 
191
+ // freeze state
192
+ rb_funcall(rb_funcall(c, id_state, 0), id_freeze, 0);
193
+
186
194
  // render
187
195
  return rb_funcall(c, id_render, 0);
188
196
  }
@@ -460,6 +468,7 @@ void Init_Preact(void) {
460
468
  id_gsub = rb_intern("gsub");
461
469
  id_html_for = rb_intern("html_for");
462
470
  id_for = rb_intern("for");
471
+ id_freeze = rb_intern("freeze");
463
472
  id_include = rb_intern("include?");
464
473
  id_is_a = rb_intern("is_a?");
465
474
  id_is_renderable = rb_intern("is_renderable?");
@@ -27,7 +27,7 @@ module Browser
27
27
  end
28
28
 
29
29
  def state
30
- ::Hash.new(`#@native.state`)
30
+ `Opal.hash(#@native.state)`
31
31
  end
32
32
  else
33
33
  def back; end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Preact
3
- VERSION = '22.10.0.rc2'
3
+ VERSION = '23.1.0.rc1'
4
4
  end
5
5
  end
@@ -28,7 +28,7 @@ module Isomorfeus
28
28
  end
29
29
  end
30
30
  if component
31
- props = Hash.new(p.JS[:props])
31
+ props = `Opal.hash(p.props)`
32
32
  if init
33
33
  Isomorfeus::TopLevel.hydrated = p.JS[:hydrated]
34
34
  %x{
@@ -37,7 +37,7 @@ module Isomorfeus
37
37
  var keys = Object.keys(state);
38
38
  for(var i=0; i < keys.length; i++) {
39
39
  if (Object.keys(state[keys[i]]).length > 0) {
40
- #{Isomorfeus.store.dispatch({ type: `keys[i].toUpperCase()`, set_state: Hash.new(`state[keys[i]]`) })}
40
+ #{Isomorfeus.store.dispatch({ type: `keys[i].toUpperCase()`, set_state: Hash.recursive_new(`state[keys[i]]`) })}
41
41
  }
42
42
  }
43
43
  }
data/lib/lucid_app.rb CHANGED
@@ -10,7 +10,7 @@ class LucidApp < LucidComponent
10
10
  block_result = _internal_render(pr, &block)
11
11
  children = pr.pop
12
12
  if Preact.is_renderable?(block_result)
13
- children.push(block_result)
13
+ children << block_result
14
14
  end
15
15
  Preact.create_element(LucidApplicationContext.Provider, state[:_app_ctx], children)
16
16
  end
@@ -11,7 +11,7 @@ class LucidComponent < Preact::Component
11
11
  pr = Preact.render_buffer
12
12
  block_result = _internal_render(pr, &block)
13
13
  if Preact.is_renderable?(block_result)
14
- pr.pop.push(block_result)
14
+ pr.pop << block_result
15
15
  else
16
16
  pr.pop
17
17
  end
@@ -81,7 +81,7 @@ class LucidComponent < Preact::Component
81
81
  end
82
82
 
83
83
  def _internal_render(pr, &block)
84
- pr.push([])
84
+ pr << []
85
85
  outer_loading = Isomorfeus.something_loading?
86
86
  ex = nil
87
87
  begin
data/lib/nano_css.rb CHANGED
@@ -120,7 +120,7 @@ class NanoCSS
120
120
 
121
121
  decls.each do |prop, value|
122
122
  if value.is_a?(Hash) && !value.is_a?(Array)
123
- postponed.push(prop)
123
+ postponed << prop
124
124
  else
125
125
  str += decl(prop, value)
126
126
  end
@@ -237,19 +237,19 @@ class NanoCSS
237
237
  if pos
238
238
  if parents.empty?
239
239
  replaced_selector = sel.gsub(/&/, parent)
240
- result.push(replaced_selector)
240
+ result << replaced_selector
241
241
  else
242
242
  parents.each do |parent|
243
243
  replaced_selector = sel.gsub(/&/, parent)
244
- result.push(replaced_selector)
244
+ result << replaced_selector
245
245
  end
246
246
  end
247
247
  else
248
248
  if parents.empty?
249
- result.push(sel)
249
+ result << sel
250
250
  else
251
251
  parents.each do |parent|
252
- result.push("#{parent} #{sel}")
252
+ result << "#{parent} #{sel}"
253
253
  end
254
254
  end
255
255
  end
@@ -75,10 +75,10 @@ module Preact
75
75
  def render(&block)
76
76
  define_method(:render) do
77
77
  pr = Preact.render_buffer
78
- pr.push([])
78
+ pr << []
79
79
  block_result = instance_exec(&block)
80
80
  if Preact.is_renderable?(block_result)
81
- pr.pop.push(block_result)
81
+ pr.pop << block_result
82
82
  else
83
83
  pr.pop
84
84
  end
@@ -168,7 +168,7 @@ module Preact
168
168
  # is coming from. We need this because forceUpdate should never call
169
169
  # should_component_update
170
170
  @_force = true
171
- @_renderCallbacks.push(block.to_n) if block_given?
171
+ @_renderCallbacks << block.to_n if block_given?
172
172
  Preact._enqueue_render(self)
173
173
  end
174
174
  end
@@ -190,7 +190,7 @@ module Preact
190
190
  end
191
191
 
192
192
  if @_vnode
193
- @_renderCallbacks.push(block.to_n) if block_given?
193
+ @_renderCallbacks << block.to_n if block_given?
194
194
  Preact._enqueue_render(self)
195
195
  end
196
196
  end
@@ -13,9 +13,16 @@ module Preact::ComponentResolution
13
13
  let sc = self.$class();
14
14
  // disable stack traces here for improved performance
15
15
  // if const cannot be found, the orignal method_mising will throw with stacktrace
16
- Opal.config.enable_stack_trace = false
16
+ let orig_est = Opal.config.enable_stack_trace;
17
+ Opal.config.enable_stack_trace = false;
17
18
  try {
18
- constant = sc.$const_get(component_name);
19
+ // disable the const cache for development, so that always the latest constant
20
+ // version is used to make hot reloading reliable
21
+ if (!Opal.Isomorfeus.development) {
22
+ if (!self.$$iso_preact_const_cache) { self.$$iso_preact_const_cache = {}; }
23
+ constant = self.$$iso_preact_const_cache[component_name];
24
+ }
25
+ if (!constant) { constant = sc.$const_get(component_name); }
19
26
  } catch(err) {
20
27
  let module_names;
21
28
  if (sc.$$full_name) { module_names = sc.$$full_name.split("::"); }
@@ -29,9 +36,12 @@ module Preact::ComponentResolution
29
36
  } catch(err) { }
30
37
  }
31
38
  } finally {
32
- Opal.config.enable_stack_trace = true
39
+ Opal.config.enable_stack_trace = orig_est;
33
40
  }
34
41
  if (constant) {
42
+ if (!Opal.Isomorfeus.development && !self.$$iso_preact_const_cache[component_name]) {
43
+ self.$$iso_preact_const_cache[component_name] = constant;
44
+ }
35
45
  let last = args[args.length-1];
36
46
  #{`Opal.Preact`._render_element(`constant`, `(last === undefined || last === null) ? nil : last`, &block)};
37
47
  return nil;
@@ -48,21 +58,25 @@ module Preact::ComponentResolution
48
58
  # Further on it must check for modules, because const_get does not take
49
59
  # the full nesting into account
50
60
  constant = nil
51
- if self.is_a?(Module)
52
- constant = const_get(component_name) rescue nil
53
- else
54
- begin
55
- constant = self.class.const_get(component_name)
56
- rescue
57
- module_names = self.class.to_s.split('::')
58
- module_names.each_index do |i|
59
- module_name = module_names[0..i].join('::')
60
- constant = self.class.const_get(module_name).const_get(component_name, false) rescue nil
61
- break if constant
62
- end
61
+ begin
62
+ if !Isomorfeus.development?
63
+ @iso_preact_const_cache = {} unless @iso_preact_const_cache
64
+ constant = @iso_preact_const_cache[component_name]
65
+ end
66
+ constant = self.class.const_get(component_name) unless constant
67
+ rescue
68
+ module_names = self.class.to_s.split('::')
69
+ module_names.each_index do |i|
70
+ module_name = module_names[0..i].join('::')
71
+ constant = self.class.const_get(module_name).const_get(component_name, false) rescue nil
72
+ break if constant
63
73
  end
64
74
  end
75
+
65
76
  if constant
77
+ if !Isomorfeus.development? && @iso_preact_const_cache.key?(component_name)
78
+ @iso_preact_const_cache[component_name] = constant
79
+ end
66
80
  Preact._render_element(constant, args.last, &block)
67
81
  nil
68
82
  else
@@ -43,7 +43,7 @@ module Preact
43
43
  end
44
44
 
45
45
  def sub(component)
46
- @subs.push(component)
46
+ @subs << component
47
47
  component.provider_subs = @subs
48
48
  end
49
49
  end
@@ -52,7 +52,7 @@ module Preact::HtmlElements
52
52
  end
53
53
 
54
54
  def RPE(el)
55
- Preact.render_buffer.last.push(el)
55
+ Preact.render_buffer.last << el
56
56
  nil
57
57
  end
58
58
  end
@@ -17,6 +17,12 @@ class Module
17
17
  // if const cannot be found, the orignal method_mising will throw with stacktrace
18
18
  Opal.config.enable_stack_trace = false;
19
19
  try {
20
+ // disable the const cache for development, so that always the latest constant
21
+ // version is used to make hot reloading reliable
22
+ if (!Opal.Isomorfeus.development) {
23
+ if (!self.$$iso_preact_const_cache) { self.$$iso_preact_const_cache = {}; }
24
+ constant = self.$$iso_preact_const_cache[component_name];
25
+ }
20
26
  constant = self.$const_get(component_name);
21
27
  } catch(err) {
22
28
  // nothing
@@ -24,6 +30,9 @@ class Module
24
30
  Opal.config.enable_stack_trace = true;
25
31
  }
26
32
  if (constant) {
33
+ if (!Opal.Isomorfeus.development && !self.$$iso_preact_const_cache[component_name]) {
34
+ self.$$iso_preact_const_cache[component_name] = constant;
35
+ }
27
36
  let last = args[args.length-1];
28
37
  #{`Opal.Preact`._render_element(`constant`, `(last === undefined || last === null) ? nil : last`, &block)};
29
38
  return nil;
@@ -42,11 +51,19 @@ class Module
42
51
  def method_missing(component_name, *args, &block)
43
52
  # check for ruby component and render it
44
53
  # otherwise pass on method missing
45
- component_name_s = component_name.to_s
46
- c = component_name_s[0]
54
+ c = component_name.to_s[0]
47
55
  if c == c.upcase
48
- constant = const_get(component_name) rescue nil
56
+ if !Isomorfeus.development?
57
+ @iso_preact_const_cache = {} unless @iso_preact_const_cache
58
+ constant = @iso_preact_const_cache[component_name]
59
+ end
60
+ unless constant
61
+ constant = const_get(component_name) rescue nil
62
+ end
49
63
  if constant && constant.ancestors.include?(Preact::Component)
64
+ if !Isomorfeus.development? && @iso_preact_const_cache.key?(component_name)
65
+ @iso_preact_const_cache[component_name] = constant
66
+ end
50
67
  Preact._render_element(constant, args.last, &block)
51
68
  return nil
52
69
  end
data/lib/preact.rb CHANGED
@@ -650,7 +650,7 @@ module Preact
650
650
  // If excessDomChildren was not null, repopulate it with the current element's children:
651
651
  excessDomChildren = excessDomChildren && slice.call(dom.childNodes);
652
652
 
653
- oldProps = oldVNode.props || Opal.Hash.$new();
653
+ oldProps = oldVNode.props || Opal.hash();
654
654
 
655
655
  let oldHtml = oldProps["$[]"]("dangerouslySetInnerHTML");
656
656
  let newHtml = newProps["$[]"]("dangerouslySetInnerHTML");
@@ -661,7 +661,7 @@ module Preact
661
661
  // But, if we are in a situation where we are using existing DOM (e.g. replaceNode)
662
662
  // we should read the existing DOM attributes to diff them
663
663
  if (excessDomChildren != null) {
664
- oldProps = Opal.Hash.$new();
664
+ oldProps = Opal.hash();
665
665
  for (i = 0; i < dom.attributes.length; i++) {
666
666
  oldProps["$[]="](dom.attributes[i].name, dom.attributes[i].value);
667
667
  }
@@ -797,13 +797,14 @@ module Preact
797
797
  // Instantiate the new component
798
798
  // validate props
799
799
  validate_props(newType, newProps);
800
- // The check above verifies that newType is suppose to be constructed
800
+ newProps.$freeze();
801
+ // The check above verifies that newType is supposed to be constructed
801
802
  newVNode._component = c = newType.$new(newProps, componentContext);
802
803
 
803
804
  if (provider && provider !== nil) provider.$sub(c);
804
805
 
805
806
  c.props = newProps;
806
- if (c.state === nil || !c.state) c.state = Opal.Hash.$new();
807
+ if (c.state === nil || !c.state) c.state = Opal.hash();
807
808
  c.context = componentContext;
808
809
  c._globalContext = globalContext;
809
810
  isNew = c._dirty = true;
@@ -811,11 +812,12 @@ module Preact
811
812
  }
812
813
 
813
814
  // Invoke get_derived_state_from_props
814
- if (c._nextState === nil) {
815
+ if (!c._nextState || c._nextState === nil) {
815
816
  c._nextState = c.state;
816
817
  }
817
818
 
818
819
  if (!isNew) { validate_props(newType, newProps); }
820
+ newProps.$freeze();
819
821
  if (c["$respond_to?"]("get_derived_state_from_props")) {
820
822
  if (c._nextState == c.state) {
821
823
  c._nextState = c._nextState.$dup();
@@ -825,6 +827,7 @@ module Preact
825
827
 
826
828
  oldProps = c.props;
827
829
  oldState = c.state;
830
+ c._nextState.$freeze();
828
831
 
829
832
  // Invoke pre-render lifecycle methods
830
833
  if (isNew) {
@@ -1007,7 +1010,6 @@ module Preact
1007
1010
  "$nil?": is_nil,
1008
1011
  "$$is_vnode": true
1009
1012
  };
1010
-
1011
1013
  return vnode;
1012
1014
  }
1013
1015
 
@@ -1043,7 +1045,7 @@ module Preact
1043
1045
  // our custom `_children` property.
1044
1046
  vnode,
1045
1047
  ov ? oldVNode : EMPTY_OBJ,
1046
- Opal.Hash.$new(),
1048
+ Opal.hash(),
1047
1049
  parentDom.ownerSVGElement !== undefined,
1048
1050
  nohy_reno ? [replaceNode] : ov ? null : parentDom.firstChild ? slice.call(parentDom.childNodes) : null,
1049
1051
  commitQueue,
@@ -1216,7 +1218,7 @@ module Preact
1216
1218
  end
1217
1219
 
1218
1220
  def _enqueue_render(c)
1219
- if ((`!c._dirty` && (`c._dirty = true`) && rerender_queue.push(c) && `!self.process._rerenderCount++`))
1221
+ if ((`!c._dirty` && (`c._dirty = true`) && (rerender_queue << c) && `!self.process._rerenderCount++`))
1220
1222
  `setTimeout(self.process)`
1221
1223
  end
1222
1224
  end
@@ -1320,7 +1322,7 @@ module Preact
1320
1322
 
1321
1323
  def _render_element(element, props, &block)
1322
1324
  pr = Preact.render_buffer
1323
- pr[pr.length-1].push(create_element(element, props, nil, &block))
1325
+ pr[pr.length-1] << create_element(element, props, nil, &block)
1324
1326
  nil
1325
1327
  end
1326
1328
 
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: 22.10.0.rc2
4
+ version: 23.1.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: 2022-10-07 00:00:00.000000000 Z
11
+ date: 2023-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.13.21
19
+ version: 3.13.23
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.13.21
26
+ version: 3.13.23
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: opal
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.5.1
33
+ version: 1.7.0.rc1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.5.1
40
+ version: 1.7.0.rc1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: opal-activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,48 +52,62 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.3.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: isomorfeus-asset-manager
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.16.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.16.2
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: isomorfeus-i18n
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - '='
60
74
  - !ruby/object:Gem::Version
61
- version: 22.10.0.rc2
75
+ version: 23.1.0.rc1
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - '='
67
81
  - !ruby/object:Gem::Version
68
- version: 22.10.0.rc2
82
+ version: 23.1.0.rc1
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: isomorfeus-redux
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - '='
74
88
  - !ruby/object:Gem::Version
75
- version: 22.10.0.rc2
89
+ version: 23.1.0.rc1
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - '='
81
95
  - !ruby/object:Gem::Version
82
- version: 22.10.0.rc2
96
+ version: 23.1.0.rc1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: isomorfeus-puppetmaster
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 0.8.1
103
+ version: 0.8.4
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 0.8.1
110
+ version: 0.8.4
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -217,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
231
  - !ruby/object:Gem::Version
218
232
  version: 1.3.1
219
233
  requirements: []
220
- rubygems_version: 3.4.0.dev
234
+ rubygems_version: 3.4.1
221
235
  signing_key:
222
236
  specification_version: 4
223
237
  summary: Preact Components for Isomorfeus.