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,133 +1,134 @@
1
- module React
2
- module Component
3
- module Api
4
- def self.included(base)
5
- base.instance_exec do
6
- base_module = base.to_s.deconstantize
7
- if base_module != ''
8
- base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
9
- `Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
10
- end
11
- else
12
- Object.define_method(base.to_s) do |*args, &block|
13
- `Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
14
- end
15
- end
16
-
17
- attr_accessor :props
18
- attr_accessor :state
19
-
20
- def ref(ref_name, &block)
21
- defined_refs.JS[ref_name] = block_given? ? block : `null`
22
- end
23
-
24
- def defined_refs
25
- @defined_ref ||= `{}`
26
- end
27
-
28
- def default_state_defined
29
- @default_state_defined
30
- end
31
-
32
- def state
33
- return @default_state if @default_state
34
- @default_state_defined = true
35
- %x{
36
- var native_state = {state: {}};
37
- native_state.setState = function(new_state, callback) {
38
- for (var key in new_state) {
39
- this.state[key] = new_state[key];
40
- }
41
- if (callback) { callback.call(); }
42
- }
43
- }
44
- @default_state = React::Component::State.new(`native_state`)
45
- end
46
-
47
- def render(&block)
48
- `base.render_block = block`
49
- end
50
-
51
- def should_component_update?(&block)
52
- `base.should_component_update_block = block`
53
- end
54
- end
55
- end
56
-
57
- def display_name
58
- @native.JS[:displayName]
59
- end
60
-
61
- def force_update(&block)
62
- if block_given?
63
- # this maybe needs instance_exec too
64
- @native.JS.forceUpdate(`function() { block.$call(); }`)
65
- else
66
- @native.JS.forceUpdate
67
- end
68
- end
69
-
70
- def component_fun(class_name, **ruby_props)
71
- %x{
72
- return function(props) {
73
- let outer_props = Opal.React.to_native_react_props(#{ruby_props});
74
- let new_props = Object.assign({}, props, outer_props);
75
- return Opal.global.React.createElement(#{class_name.constantize}.react_component, new_props)
76
- }
77
- }
78
- end
79
-
80
- def get_react_element(arg, &block)
81
- if block_given?
82
- # execute block, fetch last element from buffer
83
- %x{
84
- let last_buffer_length = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].length;
85
- let last_buffer_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1][last_buffer_length - 1];
86
- block.$call();
87
- // console.log("get_react_element popping", Opal.React.render_buffer, Opal.React.render_buffer.toString())
88
- let new_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].pop();
89
- if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any React element!")} }
90
- return new_element;
91
- }
92
- else
93
- # element was rendered before being passed as arg
94
- # fetch last element from buffer
95
- # `console.log("get_react_element popping", Opal.React.render_buffer, Opal.React.render_buffer.toString())`
96
- `Opal.React.render_buffer[Opal.React.render_buffer.length - 1].pop()`
97
- end
98
- end
99
- alias gre get_react_element
100
-
101
- def method_ref(method_symbol)
102
- %x{
103
- if (#@native.method_refs && #@native.method_refs[#{method_symbol}]) { return #@native.method_refs[#{method_symbol}]; }
104
- if (!#@native.method_refs) { #@native.method_refs = {}; }
105
- #@native.method_refs[#{method_symbol}] = #{method(method_symbol)};
106
- return #@native.method_refs[#{method_symbol}];
107
- }
108
- end
109
- alias m_ref method_ref
110
-
111
- def render_react_element(el)
112
- # push el to buffer
113
- `Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(el)`
114
- # `console.log("render_react_element pushed", Opal.React.render_buffer, Opal.React.render_buffer.toString())`
115
- nil
116
- end
117
- alias rre render_react_element
118
-
119
- def ref(name)
120
- `#@native[name]`
121
- end
122
-
123
- def ruby_ref(name)
124
- return `#@native[name]` if `(typeof #@native[name] === 'function')`
125
- React::Ref::new(`#@native[name]`)
126
- end
127
-
128
- def set_state(updater, &callback)
129
- @state.set_state(updater, &callback)
130
- end
131
- end
132
- end
133
- end
1
+ module React
2
+ module Component
3
+ module Api
4
+ def self.included(base)
5
+ base.instance_exec do
6
+ base_module = base.to_s.deconstantize
7
+ if base_module != ''
8
+ base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
9
+ `Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
10
+ end
11
+ else
12
+ Object.define_method(base.to_s) do |*args, &block|
13
+ `Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
14
+ end
15
+ end
16
+
17
+ attr_accessor :props
18
+ attr_accessor :state
19
+
20
+ def ref(ref_name, &block)
21
+ defined_refs.JS[ref_name] = block_given? ? block : `null`
22
+ end
23
+
24
+ def defined_refs
25
+ @defined_ref ||= `{}`
26
+ end
27
+
28
+ def default_state_defined
29
+ @default_state_defined
30
+ end
31
+
32
+ def state
33
+ return @default_state if @default_state
34
+ @default_state_defined = true
35
+ %x{
36
+ var native_state = {state: {}};
37
+ native_state.setState = function(new_state, callback) {
38
+ for (var key in new_state) {
39
+ this.state[key] = new_state[key];
40
+ }
41
+ if (callback) { callback.call(); }
42
+ }
43
+ }
44
+ @default_state = React::Component::State.new(`native_state`)
45
+ end
46
+
47
+ def render(&block)
48
+ `base.render_block = #{block}`
49
+ end
50
+
51
+ def should_component_update?(&block)
52
+ `base.should_component_update_block = block`
53
+ end
54
+ end
55
+ end
56
+
57
+ def display_name
58
+ @native.JS[:displayName]
59
+ end
60
+
61
+ def force_update(&block)
62
+ if block_given?
63
+ # this maybe needs instance_exec too
64
+ @native.JS.forceUpdate(`function() { block.$call(); }`)
65
+ else
66
+ @native.JS.forceUpdate
67
+ end
68
+ end
69
+
70
+ def component_fun(class_name, **ruby_props)
71
+ %x{
72
+ return function(props) {
73
+ let outer_props = Opal.React.to_native_react_props(#{ruby_props});
74
+ let new_props = Object.assign({}, props, outer_props);
75
+ return Opal.global.React.createElement(#{class_name.constantize}.react_component, new_props)
76
+ }
77
+ }
78
+ end
79
+
80
+ def get_react_element(arg, &block)
81
+ if block_given?
82
+ # execute block, fetch last element from buffer
83
+ %x{
84
+ let last_buffer_length = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].length;
85
+ let last_buffer_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1][last_buffer_length - 1];
86
+ block.$call();
87
+ // console.log("get_react_element popping", Opal.React.render_buffer, Opal.React.render_buffer.toString())
88
+ let new_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].pop();
89
+ if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any React element!")} }
90
+ return new_element;
91
+ }
92
+ else
93
+ # element was rendered before being passed as arg
94
+ # fetch last element from buffer
95
+ # `console.log("get_react_element popping", Opal.React.render_buffer, Opal.React.render_buffer.toString())`
96
+ `Opal.React.render_buffer[Opal.React.render_buffer.length - 1].pop()`
97
+ end
98
+ end
99
+ alias gre get_react_element
100
+
101
+ def method_ref(method_symbol, *args)
102
+ method_key = "#{method_symbol}#{args}"
103
+ %x{
104
+ if (#@native.method_refs && #@native.method_refs[#{method_key}]) { return #@native.method_refs[#{method_key}]; }
105
+ if (!#@native.method_refs) { #@native.method_refs = {}; }
106
+ #@native.method_refs[#{method_key}] = { m: #{method(method_symbol)}, a: args };
107
+ return #@native.method_refs[#{method_key}];
108
+ }
109
+ end
110
+ alias m_ref method_ref
111
+
112
+ def render_react_element(el)
113
+ # push el to buffer
114
+ `Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(el)`
115
+ # `console.log("render_react_element pushed", Opal.React.render_buffer, Opal.React.render_buffer.toString())`
116
+ nil
117
+ end
118
+ alias rre render_react_element
119
+
120
+ def ref(name)
121
+ `#@native[name]`
122
+ end
123
+
124
+ def ruby_ref(name)
125
+ return `#@native[name]` if `(typeof #@native[name] === 'function')`
126
+ React::Ref::new(`#@native[name]`)
127
+ end
128
+
129
+ def set_state(updater, &callback)
130
+ @state.set_state(updater, &callback)
131
+ end
132
+ end
133
+ end
134
+ end
@@ -1,9 +1,9 @@
1
- module React
2
- module Component
3
- class Base
4
- def self.inherited(base)
5
- base.include(::React::Component::Mixin)
6
- end
7
- end
8
- end
1
+ module React
2
+ module Component
3
+ class Base
4
+ def self.inherited(base)
5
+ base.include(::React::Component::Mixin)
6
+ end
7
+ end
8
+ end
9
9
  end
@@ -1,115 +1,115 @@
1
- module React
2
- module Component
3
- module Callbacks
4
- def self.included(base)
5
- base.instance_exec do
6
- def component_did_catch(&block)
7
- # TODO convert error and info
8
- %x{
9
- var fun = function(error, info) {
10
- Opal.React.active_redux_components.push(this);
11
- #{`this.__ruby_instance`.instance_exec(`error`, `info`, &block)};
12
- Opal.React.active_redux_components.pop();
13
- }
14
- if (self.lucid_react_component) { self.lucid_react_component.prototype.componentDidCatch = fun; }
15
- else { self.react_component.prototype.componentDidCatch = fun; }
16
- }
17
- end
18
-
19
- def component_did_mount(&block)
20
- %x{
21
- let fun = function() {
22
- Opal.React.active_redux_components.push(this);
23
- #{`this.__ruby_instance`.instance_exec(&block)};
24
- Opal.React.active_redux_components.pop();
25
- }
26
- if (self.lucid_react_component) {
27
- if (self.lucid_react_component.prototype.componentDidMount) {
28
- let fun_one = self.lucid_react_component.prototype.componentDidMount;
29
- let fun_two = fun;
30
- fun = function() {
31
- fun_one();
32
- fun_two();
33
- }
34
- }
35
- self.lucid_react_component.prototype.componentDidMount = fun;
36
- } else { self.react_component.prototype.componentDidMount = fun; }
37
- }
38
- end
39
-
40
- def component_did_update(&block)
41
- %x{
42
- var fun = function(prev_props, prev_state, snapshot) {
43
- Opal.React.active_redux_components.push(this);
44
- #{`this.__ruby_instance`.instance_exec(`Opal.React.Component.Props.$new({props: prev_props})`,
45
- `Opal.React.Component.State.$new({state: prev_state})`,
46
- `snapshot`, &block)};
47
- Opal.React.active_redux_components.pop();
48
- }
49
- if (self.lucid_react_component) { self.lucid_react_component.prototype.componentDidUpdate = fun; }
50
- else { self.react_component.prototype.componentDidUpdate = fun; }
51
- }
52
- end
53
-
54
- def component_will_unmount(&block)
55
- %x{
56
- var fun = function() {
57
- if (typeof this.unsubscriber === "function") { this.unsubscriber(); };
58
- Opal.React.active_redux_components.push(this);
59
- #{`this.__ruby_instance`.instance_exec(&block)};
60
- Opal.React.active_redux_components.pop();
61
- }
62
- if (self.lucid_react_component) { self.lucid_react_component.prototype.componentWillUnmount = fun; }
63
- else { self.react_component.prototype.componentWillUnmount = fun; }
64
- }
65
- end
66
-
67
- def get_derived_state_from_error(&block)
68
- # TODO convert error
69
- %x{
70
- var fun = function(error) {
71
- var result = #{`this.__ruby_instance`.instance_exec(`error`, &block)};
72
- if (typeof result.$to_n === 'function') { result = result.$to_n() }
73
- if (result === Opal.nil) { return null; }
74
- return result;
75
- }
76
- if (self.lucid_react_component) { self.lucid_react_component.prototype.getDerivedStateFromError = fun; }
77
- else { self.react_component.prototype.getDerivedStateFromError = fun; }
78
- }
79
- end
80
-
81
- def get_derived_state_from_props(&block)
82
- %x{
83
- var fun = function(props, state) {
84
- Opal.React.active_redux_components.push(this);
85
- var result = #{`this.__ruby_instance`.instance_exec(`Opal.React.Component.Props.$new({props: props})`,
86
- `Opal.React.Component.State.$new({state: state})`, &block)};
87
- Opal.React.active_redux_components.pop();
88
- if (typeof result.$to_n === 'function') { result = result.$to_n() }
89
- if (result === Opal.nil) { return null; }
90
- return result;
91
- }
92
- if (self.lucid_react_component) { self.lucid_react_component.prototype.getDerivedStateFromProps = fun; }
93
- else { self.react_component.prototype.getDerivedStateFromProps = fun; }
94
- }
95
- end
96
-
97
- def get_snapshot_before_update(&block)
98
- %x{
99
- var fun = function(prev_props, prev_state) {
100
- Opal.React.active_redux_components.push(this);
101
- var result = #{`this.__ruby_instance`.instance_exec(`Opal.React.Component.Props.$new({props: prev_props})`,
102
- `Opal.React.Component.State.$new({state: prev_state})`, &block)};
103
- Opal.React.active_redux_components.pop();
104
- if (result === Opal.nil) { return null; }
105
- return result;
106
- }
107
- if (self.lucid_react_component) { self.lucid_react_component.prototype.getSnapshotBeforeUpdate = fun; }
108
- else { self.react_component.prototype.getSnapshotBeforeUpdate = fun; }
109
- }
110
- end
111
- end
112
- end
113
- end
114
- end
115
- end
1
+ module React
2
+ module Component
3
+ module Callbacks
4
+ def self.included(base)
5
+ base.instance_exec do
6
+ def component_did_catch(&block)
7
+ # TODO convert error and info
8
+ %x{
9
+ var fun = function(error, info) {
10
+ Opal.React.active_redux_components.push(this);
11
+ #{`this.__ruby_instance`.instance_exec(`error`, `info`, &block)};
12
+ Opal.React.active_redux_components.pop();
13
+ }
14
+ if (self.lucid_react_component) { self.lucid_react_component.prototype.componentDidCatch = fun; }
15
+ else { self.react_component.prototype.componentDidCatch = fun; }
16
+ }
17
+ end
18
+
19
+ def component_did_mount(&block)
20
+ %x{
21
+ let fun = function() {
22
+ Opal.React.active_redux_components.push(this);
23
+ #{`this.__ruby_instance`.instance_exec(&block)};
24
+ Opal.React.active_redux_components.pop();
25
+ }
26
+ if (self.lucid_react_component) {
27
+ if (self.lucid_react_component.prototype.componentDidMount) {
28
+ let fun_one = self.lucid_react_component.prototype.componentDidMount;
29
+ let fun_two = fun;
30
+ fun = function() {
31
+ fun_one();
32
+ fun_two();
33
+ }
34
+ }
35
+ self.lucid_react_component.prototype.componentDidMount = fun;
36
+ } else { self.react_component.prototype.componentDidMount = fun; }
37
+ }
38
+ end
39
+
40
+ def component_did_update(&block)
41
+ %x{
42
+ var fun = function(prev_props, prev_state, snapshot) {
43
+ Opal.React.active_redux_components.push(this);
44
+ #{`this.__ruby_instance`.instance_exec(`Opal.React.Component.Props.$new({props: prev_props})`,
45
+ `Opal.React.Component.State.$new({state: prev_state})`,
46
+ `snapshot`, &block)};
47
+ Opal.React.active_redux_components.pop();
48
+ }
49
+ if (self.lucid_react_component) { self.lucid_react_component.prototype.componentDidUpdate = fun; }
50
+ else { self.react_component.prototype.componentDidUpdate = fun; }
51
+ }
52
+ end
53
+
54
+ def component_will_unmount(&block)
55
+ %x{
56
+ var fun = function() {
57
+ if (typeof this.unsubscriber === "function") { this.unsubscriber(); };
58
+ Opal.React.active_redux_components.push(this);
59
+ #{`this.__ruby_instance`.instance_exec(&block)};
60
+ Opal.React.active_redux_components.pop();
61
+ }
62
+ if (self.lucid_react_component) { self.lucid_react_component.prototype.componentWillUnmount = fun; }
63
+ else { self.react_component.prototype.componentWillUnmount = fun; }
64
+ }
65
+ end
66
+
67
+ def get_derived_state_from_error(&block)
68
+ # TODO convert error
69
+ %x{
70
+ var fun = function(error) {
71
+ var result = #{`this.__ruby_instance`.instance_exec(`error`, &block)};
72
+ if (typeof result.$to_n === 'function') { result = result.$to_n() }
73
+ if (result === Opal.nil) { return null; }
74
+ return result;
75
+ }
76
+ if (self.lucid_react_component) { self.lucid_react_component.prototype.getDerivedStateFromError = fun; }
77
+ else { self.react_component.prototype.getDerivedStateFromError = fun; }
78
+ }
79
+ end
80
+
81
+ def get_derived_state_from_props(&block)
82
+ %x{
83
+ var fun = function(props, state) {
84
+ Opal.React.active_redux_components.push(this);
85
+ var result = #{`this.__ruby_instance`.instance_exec(`Opal.React.Component.Props.$new({props: props})`,
86
+ `Opal.React.Component.State.$new({state: state})`, &block)};
87
+ Opal.React.active_redux_components.pop();
88
+ if (typeof result.$to_n === 'function') { result = result.$to_n() }
89
+ if (result === Opal.nil) { return null; }
90
+ return result;
91
+ }
92
+ if (self.lucid_react_component) { self.lucid_react_component.prototype.getDerivedStateFromProps = fun; }
93
+ else { self.react_component.prototype.getDerivedStateFromProps = fun; }
94
+ }
95
+ end
96
+
97
+ def get_snapshot_before_update(&block)
98
+ %x{
99
+ var fun = function(prev_props, prev_state) {
100
+ Opal.React.active_redux_components.push(this);
101
+ var result = #{`this.__ruby_instance`.instance_exec(`Opal.React.Component.Props.$new({props: prev_props})`,
102
+ `Opal.React.Component.State.$new({state: prev_state})`, &block)};
103
+ Opal.React.active_redux_components.pop();
104
+ if (result === Opal.nil) { return null; }
105
+ return result;
106
+ }
107
+ if (self.lucid_react_component) { self.lucid_react_component.prototype.getSnapshotBeforeUpdate = fun; }
108
+ else { self.react_component.prototype.getSnapshotBeforeUpdate = fun; }
109
+ }
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -1,60 +1,60 @@
1
- module React
2
- module Component
3
- module Elements
4
- # https://www.w3.org/TR/html52/fullindex.html#index-elements
5
- # https://www.w3.org/TR/SVG11/eltindex.html
6
- SUPPORTED_HTML_AND_SVG_ELEMENTS = %w[
7
- a abbr address area article aside audio
8
- b base bdi bdo blockquote body br button
9
- canvas caption cite code col colgroup
10
- data datalist dd del details dfn dialog div dl dt
11
- em embed
12
- fieldset figcaption figure footer form
13
- h1 h2 h3 h4 h5 h6 head header hr html
14
- i iframe img input ins
15
- kbd
16
- label legend li link
17
- main map mark meta meter
18
- nav noscript
19
- object ol optgroup option output
20
- p param picture pre progress
21
- q
22
- rp rt rtc ruby
23
- s samp script section select small source span strong style sub summary sup
24
- table tbody td template textarea tfoot th thead time title tr track
25
- u ul
26
- var video
27
- wbr
28
- altGlyph altGlyphDef altGlyphItem animate animateColor animateMotion animateTransform
29
- circle clipPath color-profile cursor
30
- defs desc
31
- ellipse
32
- feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting
33
- feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur
34
- feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting
35
- feSpotLight feTile feTurbulence
36
- filter font font-face font-face-format font-face-name font-face-src font-face-uri foreignObject
37
- g glyph glyphRef
38
- hkern
39
- image
40
- line linearGradient
41
- marker mask metadata missing-glyph mpath
42
- path pattern polygon polyline
43
- radialGradient rect
44
- script set stop style svg switch symbol
45
- text textPath tref tspan
46
- use
47
- view vkern
48
- ]
49
-
50
- SUPPORTED_HTML_AND_SVG_ELEMENTS.each do |element|
51
- define_method(element) do |*args, &block|
52
- `Opal.React.internal_prepare_args_and_render(element, args, block)`
53
- end
54
- define_method(`element.toUpperCase()`) do |*args, &block|
55
- `Opal.React.internal_prepare_args_and_render(element, args, block)`
56
- end
57
- end
58
- end
59
- end
60
- end
1
+ module React
2
+ module Component
3
+ module Elements
4
+ # https://www.w3.org/TR/html52/fullindex.html#index-elements
5
+ # https://www.w3.org/TR/SVG11/eltindex.html
6
+ SUPPORTED_HTML_AND_SVG_ELEMENTS = %w[
7
+ a abbr address area article aside audio
8
+ b base bdi bdo blockquote body br button
9
+ canvas caption cite code col colgroup
10
+ data datalist dd del details dfn dialog div dl dt
11
+ em embed
12
+ fieldset figcaption figure footer form
13
+ h1 h2 h3 h4 h5 h6 head header hr html
14
+ i iframe img input ins
15
+ kbd
16
+ label legend li link
17
+ main map mark meta meter
18
+ nav noscript
19
+ object ol optgroup option output
20
+ p param picture pre progress
21
+ q
22
+ rp rt rtc ruby
23
+ s samp script section select small source span strong style sub summary sup
24
+ table tbody td template textarea tfoot th thead time title tr track
25
+ u ul
26
+ var video
27
+ wbr
28
+ altGlyph altGlyphDef altGlyphItem animate animateColor animateMotion animateTransform
29
+ circle clipPath color-profile cursor
30
+ defs desc
31
+ ellipse
32
+ feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting
33
+ feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur
34
+ feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting
35
+ feSpotLight feTile feTurbulence
36
+ filter font font-face font-face-format font-face-name font-face-src font-face-uri foreignObject
37
+ g glyph glyphRef
38
+ hkern
39
+ image
40
+ line linearGradient
41
+ marker mask metadata missing-glyph mpath
42
+ path pattern polygon polyline
43
+ radialGradient rect
44
+ script set stop style svg switch symbol
45
+ text textPath tref tspan
46
+ use
47
+ view vkern
48
+ ]
49
+
50
+ SUPPORTED_HTML_AND_SVG_ELEMENTS.each do |element|
51
+ define_method(element) do |*args, &block|
52
+ `Opal.React.internal_prepare_args_and_render(element, args, block)`
53
+ end
54
+ define_method(`element.toUpperCase()`) do |*args, &block|
55
+ `Opal.React.internal_prepare_args_and_render(element, args, block)`
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end