isomorfeus-preact 10.6.32 → 10.6.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isomorfeus-preact.rb +15 -0
  3. data/lib/isomorfeus_preact/lucid_app/api.rb +30 -32
  4. data/lib/isomorfeus_preact/lucid_app/mixin.rb +12 -13
  5. data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +88 -90
  6. data/lib/isomorfeus_preact/lucid_component/api.rb +96 -98
  7. data/lib/isomorfeus_preact/lucid_component/initializer.rb +8 -10
  8. data/lib/isomorfeus_preact/lucid_component/mixin.rb +11 -12
  9. data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +77 -79
  10. data/lib/isomorfeus_preact/lucid_func/initializer.rb +7 -9
  11. data/lib/isomorfeus_preact/lucid_func/mixin.rb +8 -9
  12. data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +49 -51
  13. data/lib/isomorfeus_preact/preact/function_component/api.rb +102 -106
  14. data/lib/isomorfeus_preact/preact/function_component/base.rb +5 -7
  15. data/lib/isomorfeus_preact/preact/function_component/initializer.rb +4 -8
  16. data/lib/isomorfeus_preact/preact/function_component/mixin.rb +6 -10
  17. data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +41 -45
  18. data/lib/preact/component/api.rb +99 -103
  19. data/lib/preact/component/base.rb +5 -7
  20. data/lib/preact/component/callbacks.rb +99 -103
  21. data/lib/preact/component/initializer.rb +5 -9
  22. data/lib/preact/component/mixin.rb +9 -13
  23. data/lib/preact/component/native_component_constructor.rb +67 -71
  24. data/lib/preact/component_resolution.rb +78 -80
  25. data/lib/preact/elements.rb +55 -57
  26. data/lib/preact/version.rb +1 -1
  27. metadata +1 -1
@@ -1,81 +1,77 @@
1
- module Preact
2
- module Component
3
- module NativeComponentConstructor
4
- # for should_component_update we apply ruby semantics for comparing props
5
- # to do so, we convert the props to ruby hashes and then compare
6
- # this makes sure, that for example rubys Nil object gets handled properly
7
- def self.extended(base)
8
- component_name = base.to_s
9
- %x{
10
- base.preact_component = class extends Opal.global.Preact.Component {
11
- constructor(props) {
12
- super(props);
13
- if (base.$default_state_defined()) {
14
- this.state = base.$state().$to_n();
15
- } else {
16
- this.state = {};
17
- };
18
- this.__ruby_instance = base.$new(this);
19
- var defined_refs = #{base.defined_refs};
20
- for (var ref in defined_refs) {
21
- if (defined_refs[ref] != null) {
22
- let r = ref; // to ensure closure for function below gets correct ref name
23
- this[ref] = function(element) {
24
- const oper = Opal.Preact;
25
- element = oper.native_element_or_component_to_ruby(element);
26
- oper.register_active_component(this);
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); }
30
- oper.unregister_active_component(this);
31
- }
32
- this[ref] = this[ref].bind(this);
33
- } else {
34
- this[ref] = Opal.global.Preact.createRef();
35
- }
36
- }
37
- }
38
- static get displayName() {
39
- return #{component_name};
40
- }
41
- render(props, state) {
42
- const oper = Opal.Preact;
43
- oper.render_buffer.push([]);
44
- oper.register_active_component(this);
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
- }
52
- oper.unregister_active_component(this);
53
- let result = oper.render_buffer.pop();
54
- return (result.length === 1) ? result[0] : result;
55
- }
56
- shouldComponentUpdate(next_props, next_state) {
57
- const oper = Opal.Preact;
58
- if (base.should_component_update_block) {
1
+ module Preact::Component::NativeComponentConstructor
2
+ # for should_component_update we apply ruby semantics for comparing props
3
+ # to do so, we convert the props to ruby hashes and then compare
4
+ # this makes sure, that for example rubys Nil object gets handled properly
5
+ def self.extended(base)
6
+ component_name = base.to_s
7
+ %x{
8
+ base.preact_component = class extends Opal.global.Preact.Component {
9
+ constructor(props) {
10
+ super(props);
11
+ if (base.$default_state_defined()) {
12
+ this.state = base.$state().$to_n();
13
+ } else {
14
+ this.state = {};
15
+ };
16
+ this.__ruby_instance = base.$new(this);
17
+ var defined_refs = #{base.defined_refs};
18
+ for (var ref in defined_refs) {
19
+ if (defined_refs[ref] != null) {
20
+ let r = ref; // to ensure closure for function below gets correct ref name
21
+ this[ref] = function(element) {
22
+ const oper = Opal.Preact;
23
+ element = oper.native_element_or_component_to_ruby(element);
59
24
  oper.register_active_component(this);
60
- let result;
61
25
  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`)};
26
+ #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
63
27
  } catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
64
28
  oper.unregister_active_component(this);
65
- return result;
66
29
  }
67
- if (!oper.props_are_equal(this.props, next_props)) { return true; }
68
- if (oper.state_is_not_equal(this.state, next_state)) { return true; }
69
- return false;
70
- }
71
- validateProp(props, propName, componentName) {
72
- try { base.$validate_prop(propName, props[propName]) }
73
- catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
74
- return null;
30
+ this[ref] = this[ref].bind(this);
31
+ } else {
32
+ this[ref] = Opal.global.Preact.createRef();
75
33
  }
76
34
  }
77
35
  }
78
- end
79
- end
36
+ static get displayName() {
37
+ return #{component_name};
38
+ }
39
+ render(props, state) {
40
+ const oper = Opal.Preact;
41
+ oper.render_buffer.push([]);
42
+ oper.register_active_component(this);
43
+ try {
44
+ let block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
45
+ if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
46
+ } catch (e) {
47
+ if (oper.using_did_catch) { throw e; }
48
+ else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
49
+ }
50
+ oper.unregister_active_component(this);
51
+ let result = oper.render_buffer.pop();
52
+ return (result.length === 1) ? result[0] : result;
53
+ }
54
+ shouldComponentUpdate(next_props, next_state) {
55
+ const oper = Opal.Preact;
56
+ if (base.should_component_update_block) {
57
+ oper.register_active_component(this);
58
+ let result;
59
+ try {
60
+ result = #{!!`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: next_props})`, `oper.State.$new({state: next_state })`, &`base.should_component_update_block`)};
61
+ } catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
62
+ oper.unregister_active_component(this);
63
+ return result;
64
+ }
65
+ if (!oper.props_are_equal(this.props, next_props)) { return true; }
66
+ if (oper.state_is_not_equal(this.state, next_state)) { return true; }
67
+ return false;
68
+ }
69
+ validateProp(props, propName, componentName) {
70
+ try { base.$validate_prop(propName, props[propName]) }
71
+ catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
72
+ return null;
73
+ }
74
+ }
75
+ }
80
76
  end
81
77
  end
@@ -1,94 +1,92 @@
1
- module Preact
2
- module ComponentResolution
3
- def self.included(base)
4
- base.instance_exec do
5
- unless method_defined?(:_preact_component_class_resolution_original_const_missing)
6
- alias _preact_component_class_resolution_original_const_missing const_missing
7
- end
1
+ module Preact::ComponentResolution
2
+ def self.included(base)
3
+ base.instance_exec do
4
+ unless method_defined?(:_preact_component_class_resolution_original_const_missing)
5
+ alias _preact_component_class_resolution_original_const_missing const_missing
6
+ end
8
7
 
9
- def const_missing(const_name)
10
- %x{
11
- if (typeof Opal.global[const_name] !== "undefined" && (const_name[0] === const_name[0].toUpperCase())) {
12
- var new_const = Opal.Preact.NativeConstantWrapper.$new(Opal.global[const_name], const_name);
13
- new_const.preact_component = Opal.global[const_name];
14
- Opal.Object.$const_set(const_name, new_const);
15
- return new_const;
16
- } else {
17
- return #{_preact_component_class_resolution_original_const_missing(const_name)};
18
- }
8
+ def const_missing(const_name)
9
+ %x{
10
+ if (typeof Opal.global[const_name] !== "undefined" && (const_name[0] === const_name[0].toUpperCase())) {
11
+ var new_const = Opal.Preact.NativeConstantWrapper.$new(Opal.global[const_name], const_name);
12
+ new_const.preact_component = Opal.global[const_name];
13
+ Opal.Object.$const_set(const_name, new_const);
14
+ return new_const;
15
+ } else {
16
+ return #{_preact_component_class_resolution_original_const_missing(const_name)};
19
17
  }
20
- end
18
+ }
19
+ end
21
20
 
22
- # this is required for autoloading support, as the component may not be loaded and so its method is not registered.
23
- # must load it first, done by const_get, and next time the method will be there.
24
- unless method_defined?(:_preact_component_class_resolution_original_method_missing)
25
- alias _preact_component_class_resolution_original_method_missing method_missing
26
- end
21
+ # this is required for autoloading support, as the component may not be loaded and so its method is not registered.
22
+ # must load it first, done by const_get, and next time the method will be there.
23
+ unless method_defined?(:_preact_component_class_resolution_original_method_missing)
24
+ alias _preact_component_class_resolution_original_method_missing method_missing
25
+ end
27
26
 
28
- def method_missing(component_name, *args, &block)
29
- # check for ruby component and render it
30
- # otherwise pass on method missing
31
- %x{
32
- var constant = null;
33
- if (typeof self.iso_preact_const_cache === 'undefined') { self.iso_preact_const_cache = {}; }
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
- constant = self.$const_get(component_name);
39
- self.iso_preact_const_cache[component_name] = constant;
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
- return #{_preact_component_class_resolution_original_method_missing(component_name, *args, block)};
27
+ def method_missing(component_name, *args, &block)
28
+ # check for ruby component and render it
29
+ # otherwise pass on method missing
30
+ %x{
31
+ var constant = null;
32
+ if (typeof self.iso_preact_const_cache === 'undefined') { self.iso_preact_const_cache = {}; }
33
+ if (typeof self.iso_preact_const_cache[component_name] !== 'undefined') {
34
+ constant = self.iso_preact_const_cache[component_name]
35
+ } else {
36
+ try {
37
+ constant = self.$const_get(component_name);
38
+ self.iso_preact_const_cache[component_name] = constant;
39
+ } catch(err) { }
40
+ }
41
+ if (constant && typeof constant.preact_component !== 'undefined') {
42
+ return Opal.Preact.internal_prepare_args_and_render(constant.preact_component, args, block);
46
43
  }
47
- end
44
+ return #{_preact_component_class_resolution_original_method_missing(component_name, *args, block)};
45
+ }
48
46
  end
49
47
  end
48
+ end
50
49
 
51
- unless method_defined?(:_preact_component_resolution_original_method_missing)
52
- alias _preact_component_resolution_original_method_missing method_missing
53
- end
50
+ unless method_defined?(:_preact_component_resolution_original_method_missing)
51
+ alias _preact_component_resolution_original_method_missing method_missing
52
+ end
54
53
 
55
- def method_missing(component_name, *args, &block)
56
- # Further on it must check for modules, because $const_get does not take
57
- # the full nesting into account, as usually its called via $$ with the
58
- # nesting provided by the compiler.
59
- %x{
60
- var constant;
61
- if (typeof self.iso_preact_const_cache === 'undefined') { self.iso_preact_const_cache = {}; }
62
- if (typeof self.iso_preact_const_cache[component_name] !== 'undefined') {
63
- constant = self.iso_preact_const_cache[component_name]
64
- } else if (typeof self.$$is_a_module !== 'undefined') {
65
- try {
66
- constant = self.$const_get(component_name);
67
- self.iso_preact_const_cache[component_name] = constant;
68
- } catch(err) { }
69
- } else {
70
- let sc = self.$class();
71
- try {
72
- constant = sc.$const_get(component_name);
73
- self.iso_preact_const_cache[component_name] = constant;
74
- } catch(err) {
75
- var module_names = sc.$to_s().split("::");
76
- var module_name;
77
- for (var i = module_names.length - 1; i > 0; i--) {
78
- module_name = module_names.slice(0, i).join('::');
79
- try {
80
- constant = sc.$const_get(module_name).$const_get(component_name, false);
81
- self.iso_preact_const_cache[component_name] = constant;
82
- break;
83
- } catch(err) { }
84
- }
54
+ def method_missing(component_name, *args, &block)
55
+ # Further on it must check for modules, because $const_get does not take
56
+ # the full nesting into account, as usually its called via $$ with the
57
+ # nesting provided by the compiler.
58
+ %x{
59
+ var constant;
60
+ if (typeof self.iso_preact_const_cache === 'undefined') { self.iso_preact_const_cache = {}; }
61
+ if (typeof self.iso_preact_const_cache[component_name] !== 'undefined') {
62
+ constant = self.iso_preact_const_cache[component_name]
63
+ } else if (typeof self.$$is_a_module !== 'undefined') {
64
+ try {
65
+ constant = self.$const_get(component_name);
66
+ self.iso_preact_const_cache[component_name] = constant;
67
+ } catch(err) { }
68
+ } else {
69
+ let sc = self.$class();
70
+ try {
71
+ constant = sc.$const_get(component_name);
72
+ self.iso_preact_const_cache[component_name] = constant;
73
+ } catch(err) {
74
+ var module_names = sc.$to_s().split("::");
75
+ var module_name;
76
+ for (var i = module_names.length - 1; i > 0; i--) {
77
+ module_name = module_names.slice(0, i).join('::');
78
+ try {
79
+ constant = sc.$const_get(module_name).$const_get(component_name, false);
80
+ self.iso_preact_const_cache[component_name] = constant;
81
+ break;
82
+ } catch(err) { }
85
83
  }
86
84
  }
87
- if (constant && typeof constant.preact_component !== 'undefined') {
88
- return Opal.Preact.internal_prepare_args_and_render(constant.preact_component, args, block);
89
- }
90
- return #{_preact_component_resolution_original_method_missing(component_name, *args, block)};
91
85
  }
92
- end
86
+ if (constant && typeof constant.preact_component !== 'undefined') {
87
+ return Opal.Preact.internal_prepare_args_and_render(constant.preact_component, args, block);
88
+ }
89
+ return #{_preact_component_resolution_original_method_missing(component_name, *args, block)};
90
+ }
93
91
  end
94
92
  end
@@ -1,62 +1,60 @@
1
- module Preact
2
- module Elements
3
- # https://www.w3.org/TR/html52/fullindex.html#index-elements
4
- # https://www.w3.org/TR/SVG11/eltindex.html
5
- SUPPORTED_HTML_AND_SVG_ELEMENTS = %w[
6
- a abbr address area article aside audio
7
- b base bdi bdo blockquote body br button
8
- canvas caption cite code col colgroup
9
- data datalist dd del details dfn dialog div dl dt
10
- em embed
11
- fieldset figcaption figure footer form
12
- h1 h2 h3 h4 h5 h6 head header hr html
13
- i iframe img input ins
14
- kbd
15
- label legend li link
16
- main map mark meta meter
17
- nav noscript
18
- object ol optgroup option output
19
- p param picture pre progress
20
- q
21
- rp rt rtc ruby
22
- s samp script section select small source span strong style sub summary sup
23
- table tbody td template textarea tfoot th thead time title tr track
24
- u ul
25
- var video
26
- wbr
27
- altGlyph altGlyphDef altGlyphItem animate animateColor animateMotion animateTransform
28
- circle clipPath color-profile cursor
29
- defs desc
30
- ellipse
31
- feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting
32
- feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur
33
- feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting
34
- feSpotLight feTile feTurbulence
35
- filter font font-face font-face-format font-face-name font-face-src font-face-uri foreignObject
36
- g glyph glyphRef
37
- hkern
38
- image
39
- line linearGradient
40
- marker mask metadata missing-glyph mpath
41
- path pattern polygon polyline
42
- radialGradient rect
43
- script set stop style svg switch symbol
44
- text textPath tref tspan
45
- use
46
- view vkern
47
- ]
1
+ module Preact::Elements
2
+ # https://www.w3.org/TR/html52/fullindex.html#index-elements
3
+ # https://www.w3.org/TR/SVG11/eltindex.html
4
+ SUPPORTED_HTML_AND_SVG_ELEMENTS = %w[
5
+ a abbr address area article aside audio
6
+ b base bdi bdo blockquote body br button
7
+ canvas caption cite code col colgroup
8
+ data datalist dd del details dfn dialog div dl dt
9
+ em embed
10
+ fieldset figcaption figure footer form
11
+ h1 h2 h3 h4 h5 h6 head header hr html
12
+ i iframe img input ins
13
+ kbd
14
+ label legend li link
15
+ main map mark meta meter
16
+ nav noscript
17
+ object ol optgroup option output
18
+ p param picture pre progress
19
+ q
20
+ rp rt rtc ruby
21
+ s samp script section select small source span strong style sub summary sup
22
+ table tbody td template textarea tfoot th thead time title tr track
23
+ u ul
24
+ var video
25
+ wbr
26
+ altGlyph altGlyphDef altGlyphItem animate animateColor animateMotion animateTransform
27
+ circle clipPath color-profile cursor
28
+ defs desc
29
+ ellipse
30
+ feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting
31
+ feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur
32
+ feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting
33
+ feSpotLight feTile feTurbulence
34
+ filter font font-face font-face-format font-face-name font-face-src font-face-uri foreignObject
35
+ g glyph glyphRef
36
+ hkern
37
+ image
38
+ line linearGradient
39
+ marker mask metadata missing-glyph mpath
40
+ path pattern polygon polyline
41
+ radialGradient rect
42
+ script set stop style svg switch symbol
43
+ text textPath tref tspan
44
+ use
45
+ view vkern
46
+ ]
48
47
 
49
- SUPPORTED_HTML_AND_SVG_ELEMENTS.each do |element|
50
- define_method(element) do |*args, &block|
51
- `Opal.Preact.internal_prepare_args_and_render(element, args, block)`
52
- end
53
- define_method(`element.toUpperCase()`) do |*args, &block|
54
- `Opal.Preact.internal_prepare_args_and_render(element, args, block)`
55
- end
48
+ SUPPORTED_HTML_AND_SVG_ELEMENTS.each do |element|
49
+ define_method(element) do |*args, &block|
50
+ `Opal.Preact.internal_prepare_args_and_render(element, args, block)`
56
51
  end
57
-
58
- def Fragment(*args, &block)
59
- `Opal.Preact.internal_prepare_args_and_render(Opal.global.Preact.Fragment, args, block)`
52
+ define_method(`element.toUpperCase()`) do |*args, &block|
53
+ `Opal.Preact.internal_prepare_args_and_render(element, args, block)`
60
54
  end
61
55
  end
56
+
57
+ def Fragment(*args, &block)
58
+ `Opal.Preact.internal_prepare_args_and_render(Opal.global.Preact.Fragment, args, block)`
59
+ end
62
60
  end
@@ -1,3 +1,3 @@
1
1
  module Preact
2
- VERSION = '10.6.32'
2
+ VERSION = '10.6.33'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-preact
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.6.32
4
+ version: 10.6.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann