isomorfeus-react 16.13.9 → 16.13.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -10
  3. data/lib/isomorfeus/props/validator.rb +2 -2
  4. data/lib/isomorfeus/{react_config.rb → react/config.rb} +189 -189
  5. data/lib/isomorfeus/react/memcached_component_cache.rb +19 -0
  6. data/lib/isomorfeus/react/redis_component_cache.rb +19 -0
  7. data/lib/isomorfeus/{thread_local_component_cache.rb → react/thread_local_component_cache.rb} +15 -15
  8. data/lib/isomorfeus/react_view_helper.rb +231 -231
  9. data/lib/isomorfeus/top_level.rb +103 -103
  10. data/lib/isomorfeus/top_level_ssr.rb +42 -42
  11. data/lib/isomorfeus-react-material-ui.rb +4 -4
  12. data/lib/isomorfeus-react-native.rb +5 -0
  13. data/lib/isomorfeus-react-paper.rb +4 -0
  14. data/lib/isomorfeus-react.rb +120 -118
  15. data/lib/isomorfeus_react/lucid_app/api.rb +26 -26
  16. data/lib/isomorfeus_react/lucid_app/base.rb +7 -7
  17. data/lib/isomorfeus_react/lucid_app/mixin.rb +23 -22
  18. data/lib/isomorfeus_react/lucid_app/native_component_constructor.rb +48 -49
  19. data/lib/isomorfeus_react/lucid_app/native_lucid_component_constructor.rb +94 -95
  20. data/lib/isomorfeus_react/lucid_component/api.rb +75 -102
  21. data/lib/isomorfeus_react/lucid_component/app_store_proxy.rb +37 -37
  22. data/lib/isomorfeus_react/lucid_component/base.rb +7 -7
  23. data/lib/isomorfeus_react/lucid_component/class_store_proxy.rb +44 -44
  24. data/lib/isomorfeus_react/lucid_component/initializer.rb +14 -14
  25. data/lib/isomorfeus_react/lucid_component/instance_store_proxy.rb +44 -44
  26. data/lib/isomorfeus_react/lucid_component/mixin.rb +22 -21
  27. data/lib/isomorfeus_react/lucid_component/native_component_constructor.rb +35 -35
  28. data/lib/isomorfeus_react/lucid_component/native_lucid_component_constructor.rb +82 -108
  29. data/lib/isomorfeus_react/lucid_component/styles_api.rb +34 -0
  30. data/lib/isomorfeus_react/lucid_func/base.rb +7 -7
  31. data/lib/isomorfeus_react/lucid_func/initializer.rb +11 -11
  32. data/lib/isomorfeus_react/lucid_func/mixin.rb +18 -17
  33. data/lib/isomorfeus_react/lucid_func/native_component_constructor.rb +81 -81
  34. data/lib/isomorfeus_react/react/function_component/api.rb +105 -104
  35. data/lib/isomorfeus_react/react/function_component/base.rb +8 -8
  36. data/lib/isomorfeus_react/react/function_component/initializer.rb +10 -10
  37. data/lib/isomorfeus_react/react/function_component/mixin.rb +17 -17
  38. data/lib/isomorfeus_react/react/function_component/native_component_constructor.rb +48 -48
  39. data/lib/isomorfeus_react/react/memo_component/base.rb +8 -8
  40. data/lib/isomorfeus_react/react/memo_component/mixin.rb +17 -17
  41. data/lib/isomorfeus_react/react/memo_component/native_component_constructor.rb +49 -49
  42. data/lib/isomorfeus_react_material/lucid_material/app/base.rb +8 -8
  43. data/lib/isomorfeus_react_material/lucid_material/app/mixin.rb +20 -19
  44. data/lib/isomorfeus_react_material/lucid_material/app/native_component_constructor.rb +50 -51
  45. data/lib/isomorfeus_react_material/lucid_material/component/base.rb +9 -9
  46. data/lib/isomorfeus_react_material/lucid_material/component/mixin.rb +19 -18
  47. data/lib/isomorfeus_react_material/lucid_material/component/native_component_constructor.rb +36 -36
  48. data/lib/isomorfeus_react_material/lucid_material/func/base.rb +9 -9
  49. data/lib/isomorfeus_react_material/lucid_material/func/mixin.rb +15 -14
  50. data/lib/isomorfeus_react_material/lucid_material/func/native_component_constructor.rb +83 -83
  51. data/lib/isomorfeus_react_paper/lucid_paper/app/base.rb +9 -0
  52. data/lib/isomorfeus_react_paper/lucid_paper/app/mixin.rb +19 -0
  53. data/lib/isomorfeus_react_paper/lucid_paper/app/native_component_constructor.rb +32 -0
  54. data/lib/isomorfeus_react_paper/lucid_paper/component/base.rb +9 -0
  55. data/lib/isomorfeus_react_paper/lucid_paper/component/mixin.rb +18 -0
  56. data/lib/isomorfeus_react_paper/lucid_paper/component/native_component_constructor.rb +25 -0
  57. data/lib/isomorfeus_react_paper/lucid_paper/func/base.rb +9 -0
  58. data/lib/isomorfeus_react_paper/lucid_paper/func/mixin.rb +14 -0
  59. data/lib/isomorfeus_react_paper/lucid_paper/func/native_component_constructor.rb +71 -0
  60. data/lib/lucid_app/context.rb +7 -7
  61. data/lib/lucid_prop_declaration/mixin.rb +126 -126
  62. data/lib/react/children.rb +34 -34
  63. data/lib/react/component/api.rb +134 -133
  64. data/lib/react/component/base.rb +8 -8
  65. data/lib/react/component/callbacks.rb +115 -115
  66. data/lib/react/component/elements.rb +60 -60
  67. data/lib/react/component/features.rb +48 -48
  68. data/lib/react/component/history.rb +69 -65
  69. data/lib/react/component/initializer.rb +11 -11
  70. data/lib/react/component/location.rb +19 -15
  71. data/lib/react/component/match.rb +35 -31
  72. data/lib/react/component/mixin.rb +20 -20
  73. data/lib/react/component/native_component_constructor.rb +69 -95
  74. data/lib/react/component/props.rb +83 -83
  75. data/lib/react/component/resolution.rb +97 -97
  76. data/lib/react/component/state.rb +58 -54
  77. data/lib/react/component/styles.rb +66 -66
  78. data/lib/react/context_wrapper.rb +48 -44
  79. data/lib/react/native_constant_wrapper.rb +29 -29
  80. data/lib/react/ref.rb +16 -12
  81. data/lib/react/synthetic_event.rb +52 -52
  82. data/lib/react/version.rb +3 -3
  83. data/lib/react.rb +296 -262
  84. data/lib/react_dom.rb +41 -41
  85. data/lib/react_dom_server.rb +18 -18
  86. data/lib/react_native/component/elements.rb +203 -0
  87. data/lib/react_native/lucid_app/react_native_component_constructor.rb +51 -0
  88. data/lib/react_native/lucid_component/react_native_component_constructor.rb +37 -0
  89. data/lib/react_native/lucid_func/react_native_component_constructor.rb +82 -0
  90. data/lib/react_native/react.rb +120 -0
  91. metadata +76 -23
@@ -1,48 +1,48 @@
1
- module React
2
- module Component
3
- module Features
4
- def Fragment(*args, &block)
5
- `Opal.React.internal_prepare_args_and_render(Opal.global.React.Fragment, args, block)`
6
- end
7
-
8
- def Portal(element_or_query, &block)
9
- if `(typeof element_or_query === 'string')` || (`(typeof element_or_query.$class === 'function')` && element_or_query.class == String)
10
- element = `document.body.querySelector(element_or_query)`
11
- elsif `(typeof element_or_query.$is_a === 'function')` && element_or_query.is_a?(Browser::Element)
12
- element = element_or_query.to_n
13
- else
14
- element = element_or_query
15
- end
16
- %x{
17
- let operabu = Opal.React.render_buffer;
18
- operabu.push([]);
19
- // console.log("portal pushed", operabu, operabu.toString());
20
- if (block !== nil) {
21
- let block_result = block.$call()
22
- let last_buffer_length = operabu[operabu.length - 1].length;
23
- let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
24
- if (block_result && block_result !== nil) { Opal.React.render_block_result(block_result); }
25
- }
26
- // console.log("portal popping", operabu, operabu.toString());
27
- let result = operabu.pop();
28
- if (result.length === 1) { result = result[0]; }
29
- var react_element = Opal.global.React.createPortal(result, element);
30
- operabu[operabu.length - 1].push(react_element);
31
- // console.log("portal pushed", operabu, operabu.toString());
32
- }
33
- end
34
-
35
- def Profiler(*args, &block)
36
- `Opal.React.internal_prepare_args_and_render(Opal.global.React.Profiler, args, block)`
37
- end
38
-
39
- def StrictMode(*args, &block)
40
- `Opal.React.internal_prepare_args_and_render(Opal.global.React.StrictMode, args, block)`
41
- end
42
-
43
- def Suspense(*args, &block)
44
- `Opal.React.internal_prepare_args_and_render(Opal.global.React.Suspense, args, block)`
45
- end
46
- end
47
- end
48
- end
1
+ module React
2
+ module Component
3
+ module Features
4
+ def Fragment(*args, &block)
5
+ `Opal.React.internal_prepare_args_and_render(Opal.global.React.Fragment, args, block)`
6
+ end
7
+
8
+ def Portal(element_or_query, &block)
9
+ if `(typeof element_or_query === 'string')` || (`(typeof element_or_query.$class === 'function')` && element_or_query.class == String)
10
+ element = `document.body.querySelector(element_or_query)`
11
+ elsif `(typeof element_or_query.$is_a === 'function')` && element_or_query.is_a?(Browser::Element)
12
+ element = element_or_query.to_n
13
+ else
14
+ element = element_or_query
15
+ end
16
+ %x{
17
+ let operabu = Opal.React.render_buffer;
18
+ operabu.push([]);
19
+ // console.log("portal pushed", operabu, operabu.toString());
20
+ if (block !== nil) {
21
+ let block_result = block.$call()
22
+ let last_buffer_length = operabu[operabu.length - 1].length;
23
+ let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
24
+ if (block_result && block_result !== nil) { Opal.React.render_block_result(block_result); }
25
+ }
26
+ // console.log("portal popping", operabu, operabu.toString());
27
+ let result = operabu.pop();
28
+ if (result.length === 1) { result = result[0]; }
29
+ var react_element = Opal.global.React.createPortal(result, element);
30
+ operabu[operabu.length - 1].push(react_element);
31
+ // console.log("portal pushed", operabu, operabu.toString());
32
+ }
33
+ end
34
+
35
+ def Profiler(*args, &block)
36
+ `Opal.React.internal_prepare_args_and_render(Opal.global.React.Profiler, args, block)`
37
+ end
38
+
39
+ def StrictMode(*args, &block)
40
+ `Opal.React.internal_prepare_args_and_render(Opal.global.React.StrictMode, args, block)`
41
+ end
42
+
43
+ def Suspense(*args, &block)
44
+ `Opal.React.internal_prepare_args_and_render(Opal.global.React.Suspense, args, block)`
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,65 +1,69 @@
1
- module React
2
- module Component
3
- class History
4
- include ::Native::Wrapper
5
-
6
- def block(prompt)
7
- @native.JS[:props].JS[:history].JS.block(prompt)
8
- end
9
-
10
- def create_href(location)
11
- @native.JS[:props].JS[:history].JS.createHref(location)
12
- end
13
-
14
- def go(n)
15
- @native.JS[:props].JS[:history].JS.go(n)
16
- end
17
-
18
- def go_back
19
- @native.JS[:props].JS[:history].JS.goBack()
20
- end
21
-
22
- def go_forward
23
- @native.JS[:props].JS[:history].JS.goForward()
24
- end
25
-
26
- def push(*args)
27
- @native.JS[:props].JS[:history].JS.push(*args)
28
- end
29
-
30
- def replace(*args)
31
- @native.JS[:props].JS[:history].JS.replace(*args)
32
- end
33
-
34
- def method_missing(prop, *args, &block)
35
- @native.JS[:props].JS[:history].JS[prop]
36
- end
37
-
38
- def listen(&block)
39
- fun = nil
40
- %x{
41
- fun = function(location, action) {
42
- let ruby_location = #{React::Component::Location.new(`{ props: { location: location }}`)}
43
- block.$call(ruby_location, action);
44
- }
45
- }
46
- unlisten = @native.JS[:props].JS[:history].JS.listen(fun)
47
- -> { unlisten.JS.call() }
48
- end
49
-
50
- def location
51
- return @location if @location
52
- return nil unless @native.JS[:props].JS[:history].JS[:location]
53
- if @native.JS[:props].JS[:history].JS[:location].JS[:pathname]
54
- @location = React::Component::Location.new(@native)
55
- else
56
- @native.JS[:props].JS[:history].JS[:location]
57
- end
58
- end
59
-
60
- def to_n
61
- @native.JS[:props].JS[:history]
62
- end
63
- end
64
- end
65
- end
1
+ module React
2
+ module Component
3
+ class History
4
+ include ::Native::Wrapper
5
+
6
+ def initialize(native)
7
+ @native = native
8
+ end
9
+
10
+ def block(prompt)
11
+ @native.JS[:props].JS[:history].JS.block(prompt)
12
+ end
13
+
14
+ def create_href(location)
15
+ @native.JS[:props].JS[:history].JS.createHref(location)
16
+ end
17
+
18
+ def go(n)
19
+ @native.JS[:props].JS[:history].JS.go(n)
20
+ end
21
+
22
+ def go_back
23
+ @native.JS[:props].JS[:history].JS.goBack()
24
+ end
25
+
26
+ def go_forward
27
+ @native.JS[:props].JS[:history].JS.goForward()
28
+ end
29
+
30
+ def push(*args)
31
+ @native.JS[:props].JS[:history].JS.push(*args)
32
+ end
33
+
34
+ def replace(*args)
35
+ @native.JS[:props].JS[:history].JS.replace(*args)
36
+ end
37
+
38
+ def method_missing(prop, *args, &block)
39
+ @native.JS[:props].JS[:history].JS[prop]
40
+ end
41
+
42
+ def listen(&block)
43
+ fun = nil
44
+ %x{
45
+ fun = function(location, action) {
46
+ let ruby_location = #{React::Component::Location.new(`{ props: { location: location }}`)}
47
+ block.$call(ruby_location, action);
48
+ }
49
+ }
50
+ unlisten = @native.JS[:props].JS[:history].JS.listen(fun)
51
+ -> { unlisten.JS.call() }
52
+ end
53
+
54
+ def location
55
+ return @location if @location
56
+ return nil unless @native.JS[:props].JS[:history].JS[:location]
57
+ if @native.JS[:props].JS[:history].JS[:location].JS[:pathname]
58
+ @location = React::Component::Location.new(@native)
59
+ else
60
+ @native.JS[:props].JS[:history].JS[:location]
61
+ end
62
+ end
63
+
64
+ def to_n
65
+ @native.JS[:props].JS[:history]
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,11 +1,11 @@
1
- module React
2
- module Component
3
- module Initializer
4
- def initialize(native_component)
5
- @native = native_component
6
- @props = `Opal.React.Component.Props.$new(#@native)`
7
- @state = `Opal.React.Component.State.$new(#@native)`
8
- end
9
- end
10
- end
11
- end
1
+ module React
2
+ module Component
3
+ module Initializer
4
+ def initialize(native_component)
5
+ @native = native_component
6
+ @props = `Opal.React.Component.Props.$new(#@native)`
7
+ @state = `Opal.React.Component.State.$new(#@native)`
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,15 +1,19 @@
1
- module React
2
- module Component
3
- class Location
4
- include ::Native::Wrapper
5
-
6
- def method_missing(prop, *args, &block)
7
- @native.JS[:props].JS[:location].JS[prop]
8
- end
9
-
10
- def to_n
11
- @native
12
- end
13
- end
14
- end
15
- end
1
+ module React
2
+ module Component
3
+ class Location
4
+ include ::Native::Wrapper
5
+
6
+ def initialize(native)
7
+ @native = native
8
+ end
9
+
10
+ def method_missing(prop, *args, &block)
11
+ @native.JS[:props].JS[:location].JS[prop]
12
+ end
13
+
14
+ def to_n
15
+ @native
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,31 +1,35 @@
1
- module React
2
- module Component
3
- class Match
4
- include ::Native::Wrapper
5
-
6
- def method_missing(prop, *args, &block)
7
- @native.JS[:props].JS[:match].JS[:params].JS[prop]
8
- end
9
-
10
- def is_exact
11
- @native.JS[:props].JS[:match].JS[:isExact]
12
- end
13
-
14
- def params
15
- self
16
- end
17
-
18
- def path
19
- @native.JS[:props].JS[:match].JS[:path]
20
- end
21
-
22
- def url
23
- @native.JS[:props].JS[:match].JS[:url]
24
- end
25
-
26
- def to_n
27
- @native.JS[:props].JS[:match]
28
- end
29
- end
30
- end
31
- end
1
+ module React
2
+ module Component
3
+ class Match
4
+ include ::Native::Wrapper
5
+
6
+ def initialize(native)
7
+ @native = native
8
+ end
9
+
10
+ def method_missing(prop, *args, &block)
11
+ @native.JS[:props].JS[:match].JS[:params].JS[prop]
12
+ end
13
+
14
+ def is_exact
15
+ @native.JS[:props].JS[:match].JS[:isExact]
16
+ end
17
+
18
+ def params
19
+ self
20
+ end
21
+
22
+ def path
23
+ @native.JS[:props].JS[:match].JS[:path]
24
+ end
25
+
26
+ def url
27
+ @native.JS[:props].JS[:match].JS[:url]
28
+ end
29
+
30
+ def to_n
31
+ @native.JS[:props].JS[:match]
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,20 +1,20 @@
1
- module React
2
- module Component
3
- module Mixin
4
- def self.included(base)
5
- base.include(::Native::Wrapper)
6
- base.extend(::React::Component::NativeComponentConstructor)
7
- base.extend(::LucidPropDeclaration::Mixin)
8
- if on_browser? || on_ssr?
9
- base.include(::React::Component::Elements)
10
- elsif on_mobile?
11
- base.include(::ReactNative::Component::Elements)
12
- end
13
- base.include(::React::Component::Api)
14
- base.include(::React::Component::Callbacks)
15
- base.include(::React::Component::Initializer)
16
- base.include(::React::Component::Features)
17
- end
18
- end
19
- end
20
- end
1
+ module React
2
+ module Component
3
+ module Mixin
4
+ def self.included(base)
5
+ base.include(::Native::Wrapper)
6
+ base.extend(::React::Component::NativeComponentConstructor)
7
+ base.extend(::LucidPropDeclaration::Mixin)
8
+ if on_browser? || on_ssr?
9
+ base.include(::React::Component::Elements)
10
+ elsif on_mobile?
11
+ base.include(::ReactNative::Component::Elements)
12
+ end
13
+ base.include(::React::Component::Api)
14
+ base.include(::React::Component::Callbacks)
15
+ base.include(::React::Component::Initializer)
16
+ base.include(::React::Component::Features)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,95 +1,69 @@
1
- module React
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
- # language=JS
10
- %x{
11
- base.react_component = class extends Opal.global.React.Component {
12
- constructor(props) {
13
- super(props);
14
- if (base.$default_state_defined()) {
15
- this.state = base.$state().$to_n();
16
- } else {
17
- this.state = {};
18
- };
19
- this.__ruby_instance = base.$new(this);
20
- var defined_refs = #{base.defined_refs};
21
- for (var ref in defined_refs) {
22
- if (defined_refs[ref] != null) {
23
- this[ref] = function(element) {
24
- element = Opal.React.native_element_or_component_to_ruby(element);
25
- #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
26
- }
27
- this[ref] = this[ref].bind(this);
28
- } else {
29
- this[ref] = Opal.global.React.createRef();
30
- }
31
- }
32
- }
33
- static get displayName() {
34
- return #{component_name};
35
- }
36
- static set displayName(new_name) {
37
- // dont do anything here except returning the set value
38
- return new_name;
39
- }
40
- render() {
41
- const oper = Opal.React;
42
- oper.render_buffer.push([]);
43
- // console.log("react component pushed", oper.render_buffer, oper.render_buffer.toString());
44
- oper.active_components.push(this);
45
- let block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
46
- if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
47
- // console.log("react component popping", oper.render_buffer, oper.render_buffer.toString());
48
- oper.active_components.pop();
49
- let result = oper.render_buffer.pop();
50
- return (result.length === 1) ? result[0] : result;
51
- }
52
- shouldComponentUpdate(next_props, next_state) {
53
- if (base.should_component_update_block) {
54
- return #{!!`this.__ruby_instance`.instance_exec(React::Component::Props.new(`{props: next_props}`), React::Component::State.new(`{state: next_state }`), &`base.should_component_update_block`)};
55
- }
56
- let counter = 0;
57
- const this_props = this.props;
58
- for (var property in next_props) {
59
- counter++;
60
- if (next_props.hasOwnProperty(property)) {
61
- if (!this_props.hasOwnProperty(property)) { return true; };
62
- if (property === "children") { if (next_props.children !== this_props.children) { return true; }}
63
- else if (typeof next_props[property] === "object" && next_props[property] !== null && typeof next_props[property]['$!='] === "function" &&
64
- typeof this_props[property] !== "undefined" && this_props[property] !== null ) {
65
- if (#{ !! (`next_props[property]` != `this_props[property]`) }) { return true; }
66
- } else if (next_props[property] !== this_props[property]) { return true; }
67
- }
68
- }
69
- if (counter !== Object.keys(this_props).length) { return true; }
70
- counter = 0;
71
- const this_state = this.state;
72
- for (var property in next_state) {
73
- counter++;
74
- if (next_state.hasOwnProperty(property)) {
75
- if (!this_state.hasOwnProperty(property)) { return true; };
76
- if (typeof next_state[property] === "object" && next_state[property] !== null && typeof next_state[property]['$!='] === "function" &&
77
- typeof this_state[property] !== "undefined" && this_state[property] !== null) {
78
- if (#{ !! (`next_state[property]` != `this_state[property]`) }) { return true }
79
- } else if (next_state[property] !== this_state[property]) { return true }
80
- }
81
- }
82
- if (counter !== Object.keys(this_state).length) { return true; }
83
- return false;
84
- }
85
- validateProp(props, propName, componentName) {
86
- try { base.$validate_prop(propName, props[propName]) }
87
- catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
88
- return null;
89
- }
90
- }
91
- }
92
- end
93
- end
94
- end
95
- end
1
+ module React
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.react_component = class extends Opal.global.React.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
+ this[ref] = function(element) {
23
+ element = Opal.React.native_element_or_component_to_ruby(element);
24
+ #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
25
+ }
26
+ this[ref] = this[ref].bind(this);
27
+ } else {
28
+ this[ref] = Opal.global.React.createRef();
29
+ }
30
+ }
31
+ }
32
+ static get displayName() {
33
+ return #{component_name};
34
+ }
35
+ static set displayName(new_name) {
36
+ // dont do anything here except returning the set value
37
+ return new_name;
38
+ }
39
+ render() {
40
+ const oper = Opal.React;
41
+ oper.render_buffer.push([]);
42
+ // console.log("react component pushed", oper.render_buffer, oper.render_buffer.toString());
43
+ oper.active_components.push(this);
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
+ // console.log("react component popping", oper.render_buffer, oper.render_buffer.toString());
47
+ oper.active_components.pop();
48
+ let result = oper.render_buffer.pop();
49
+ return (result.length === 1) ? result[0] : result;
50
+ }
51
+ shouldComponentUpdate(next_props, next_state) {
52
+ if (base.should_component_update_block) {
53
+ return #{!!`this.__ruby_instance`.instance_exec(React::Component::Props.new(`{props: next_props}`), React::Component::State.new(`{state: next_state }`), &`base.should_component_update_block`)};
54
+ }
55
+ if (!Opal.React.props_are_equal(this.props, next_props)) { return true; }
56
+ if (Opal.React.state_is_not_equal(this.state, next_state)) { return true; }
57
+ return false;
58
+ }
59
+ validateProp(props, propName, componentName) {
60
+ try { base.$validate_prop(propName, props[propName]) }
61
+ catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
62
+ return null;
63
+ }
64
+ }
65
+ }
66
+ end
67
+ end
68
+ end
69
+ end