isomorfeus-react 16.13.11 → 16.13.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/lib/isomorfeus/react/config.rb +189 -189
  4. data/lib/isomorfeus/react/memcached_component_cache.rb +19 -19
  5. data/lib/isomorfeus/react/redis_component_cache.rb +19 -19
  6. data/lib/isomorfeus/react/thread_local_component_cache.rb +15 -15
  7. data/lib/isomorfeus/react_view_helper.rb +231 -231
  8. data/lib/isomorfeus/top_level.rb +103 -103
  9. data/lib/isomorfeus/top_level_ssr.rb +42 -42
  10. data/lib/isomorfeus-react-material-ui.rb +4 -4
  11. data/lib/isomorfeus-react-native.rb +5 -5
  12. data/lib/isomorfeus-react-paper.rb +4 -4
  13. data/lib/isomorfeus-react.rb +120 -120
  14. data/lib/isomorfeus_react/lucid_app/api.rb +26 -26
  15. data/lib/isomorfeus_react/lucid_app/base.rb +7 -7
  16. data/lib/isomorfeus_react/lucid_app/mixin.rb +23 -23
  17. data/lib/isomorfeus_react/lucid_app/native_component_constructor.rb +48 -48
  18. data/lib/isomorfeus_react/lucid_app/native_lucid_component_constructor.rb +94 -95
  19. data/lib/isomorfeus_react/lucid_component/api.rb +75 -75
  20. data/lib/isomorfeus_react/lucid_component/app_store_proxy.rb +37 -37
  21. data/lib/isomorfeus_react/lucid_component/base.rb +7 -7
  22. data/lib/isomorfeus_react/lucid_component/class_store_proxy.rb +44 -44
  23. data/lib/isomorfeus_react/lucid_component/initializer.rb +14 -14
  24. data/lib/isomorfeus_react/lucid_component/instance_store_proxy.rb +44 -44
  25. data/lib/isomorfeus_react/lucid_component/mixin.rb +22 -22
  26. data/lib/isomorfeus_react/lucid_component/native_component_constructor.rb +35 -35
  27. data/lib/isomorfeus_react/lucid_component/native_lucid_component_constructor.rb +82 -83
  28. data/lib/isomorfeus_react/lucid_component/styles_api.rb +34 -34
  29. data/lib/isomorfeus_react/lucid_func/base.rb +7 -7
  30. data/lib/isomorfeus_react/lucid_func/initializer.rb +11 -11
  31. data/lib/isomorfeus_react/lucid_func/mixin.rb +18 -18
  32. data/lib/isomorfeus_react/lucid_func/native_component_constructor.rb +81 -81
  33. data/lib/isomorfeus_react/react/function_component/api.rb +105 -105
  34. data/lib/isomorfeus_react/react/function_component/base.rb +8 -8
  35. data/lib/isomorfeus_react/react/function_component/initializer.rb +10 -10
  36. data/lib/isomorfeus_react/react/function_component/mixin.rb +17 -17
  37. data/lib/isomorfeus_react/react/function_component/native_component_constructor.rb +48 -48
  38. data/lib/isomorfeus_react/react/memo_component/base.rb +8 -8
  39. data/lib/isomorfeus_react/react/memo_component/mixin.rb +17 -17
  40. data/lib/isomorfeus_react/react/memo_component/native_component_constructor.rb +49 -49
  41. data/lib/isomorfeus_react_material/lucid_material/app/base.rb +8 -8
  42. data/lib/isomorfeus_react_material/lucid_material/app/mixin.rb +20 -20
  43. data/lib/isomorfeus_react_material/lucid_material/app/native_component_constructor.rb +50 -50
  44. data/lib/isomorfeus_react_material/lucid_material/component/base.rb +9 -9
  45. data/lib/isomorfeus_react_material/lucid_material/component/mixin.rb +19 -19
  46. data/lib/isomorfeus_react_material/lucid_material/component/native_component_constructor.rb +36 -36
  47. data/lib/isomorfeus_react_material/lucid_material/func/base.rb +9 -9
  48. data/lib/isomorfeus_react_material/lucid_material/func/mixin.rb +15 -15
  49. data/lib/isomorfeus_react_material/lucid_material/func/native_component_constructor.rb +83 -83
  50. data/lib/isomorfeus_react_paper/lucid_paper/app/base.rb +9 -9
  51. data/lib/isomorfeus_react_paper/lucid_paper/app/mixin.rb +19 -19
  52. data/lib/isomorfeus_react_paper/lucid_paper/app/native_component_constructor.rb +32 -32
  53. data/lib/isomorfeus_react_paper/lucid_paper/component/base.rb +9 -9
  54. data/lib/isomorfeus_react_paper/lucid_paper/component/mixin.rb +18 -18
  55. data/lib/isomorfeus_react_paper/lucid_paper/component/native_component_constructor.rb +25 -25
  56. data/lib/isomorfeus_react_paper/lucid_paper/func/base.rb +9 -9
  57. data/lib/isomorfeus_react_paper/lucid_paper/func/mixin.rb +14 -14
  58. data/lib/isomorfeus_react_paper/lucid_paper/func/native_component_constructor.rb +71 -71
  59. data/lib/lucid_app/context.rb +7 -7
  60. data/lib/lucid_prop_declaration/mixin.rb +126 -126
  61. data/lib/react/children.rb +34 -34
  62. data/lib/react/component/api.rb +134 -134
  63. data/lib/react/component/base.rb +8 -8
  64. data/lib/react/component/callbacks.rb +115 -115
  65. data/lib/react/component/elements.rb +60 -60
  66. data/lib/react/component/features.rb +48 -48
  67. data/lib/react/component/history.rb +69 -65
  68. data/lib/react/component/initializer.rb +11 -11
  69. data/lib/react/component/location.rb +19 -15
  70. data/lib/react/component/match.rb +35 -31
  71. data/lib/react/component/mixin.rb +20 -20
  72. data/lib/react/component/native_component_constructor.rb +69 -70
  73. data/lib/react/component/props.rb +83 -83
  74. data/lib/react/component/resolution.rb +97 -97
  75. data/lib/react/component/state.rb +58 -54
  76. data/lib/react/component/styles.rb +66 -66
  77. data/lib/react/context_wrapper.rb +48 -44
  78. data/lib/react/native_constant_wrapper.rb +29 -29
  79. data/lib/react/ref.rb +16 -12
  80. data/lib/react/synthetic_event.rb +52 -52
  81. data/lib/react/version.rb +3 -3
  82. data/lib/react.rb +296 -296
  83. data/lib/react_dom.rb +41 -41
  84. data/lib/react_dom_server.rb +18 -18
  85. data/lib/react_native/component/elements.rb +203 -203
  86. data/lib/react_native/lucid_app/react_native_component_constructor.rb +51 -51
  87. data/lib/react_native/lucid_component/react_native_component_constructor.rb +37 -37
  88. data/lib/react_native/lucid_func/react_native_component_constructor.rb +82 -82
  89. data/lib/react_native/react.rb +120 -120
  90. metadata +23 -17
@@ -1,126 +1,126 @@
1
- module LucidPropDeclaration
2
- module Mixin
3
- if RUBY_ENGINE == 'opal'
4
- def self.extended(base)
5
- def prop(prop_name, validate_hash = { required: true })
6
- validate_hash = validate_hash.to_h if validate_hash.class == Isomorfeus::Props::ValidateHashProxy
7
- if validate_hash.key?(:default)
8
- %x{
9
- if (base.lucid_react_component) {
10
- let react_prop_name = Opal.React.lower_camelize(prop_name);
11
- #{value = validate_hash[:default]}
12
- if (!base.lucid_react_component.defaultProps) { base.lucid_react_component.defaultProps = {}; }
13
- base.lucid_react_component.defaultProps[react_prop_name] = value;
14
- if (!base.lucid_react_component.propTypes) { base.lucid_react_component.propTypes = {}; }
15
- base.lucid_react_component.propTypes[react_prop_name] = base.lucid_react_component.prototype.validateProp;
16
- } else if (base.react_component) {
17
- let react_prop_name = Opal.React.lower_camelize(prop_name);
18
- #{value = validate_hash[:default]}
19
- if (!base.react_component.defaultProps) { base.react_component.defaultProps = {}; }
20
- base.react_component.defaultProps[react_prop_name] = value;
21
- if (!base.react_component.propTypes) { base.react_component.propTypes = {}; }
22
- base.react_component.propTypes[react_prop_name] = base.react_component.prototype.validateProp;
23
- }
24
- }
25
- end
26
- declared_props[prop_name.to_sym] = validate_hash
27
- end
28
- end
29
-
30
- def validate_function
31
- %x{
32
- if (typeof self.validate_function === 'undefined') {
33
- self.validate_function = function(props_object) {
34
- try { self.$validate_props(Opal.Hash.$new(props_object)) }
35
- catch (e) { return e.message; }
36
- }
37
- }
38
- return self.validate_function;
39
- }
40
- end
41
-
42
- def validate_prop_function(prop)
43
- function_name = "validate_#{prop}_function"
44
- %x{
45
- if (typeof self[function_name] === 'undefined') {
46
- self[function_name] = function(value) {
47
- try { self.$validate_prop(prop, value); }
48
- catch (e) { return e.message; }
49
- }
50
- }
51
- return self[function_name];
52
- }
53
- end
54
- else
55
- def prop(prop_name, validate_hash = { required: true })
56
- validate_hash = validate_hash.to_h if validate_hash.class == Isomorfeus::Props::ValidateHashProxy
57
- declared_props[prop_name.to_sym] = validate_hash
58
- end
59
- end
60
-
61
- def declared_props
62
- @declared_props ||= {}
63
- end
64
-
65
- def valid_prop?(prop, value)
66
- validate_prop(prop, value)
67
- rescue
68
- false
69
- end
70
-
71
- def valid_props?(props)
72
- validate_props(props)
73
- rescue
74
- false
75
- end
76
-
77
- def validate
78
- Isomorfeus::Props::ValidateHashProxy.new
79
- end
80
-
81
- def validate_prop(prop, value)
82
- return false unless declared_props.key?(prop)
83
- validator = Isomorfeus::Props::Validator.new(self, prop, value, declared_props[prop])
84
- validator.validate!
85
- true
86
- end
87
-
88
- def validate_props(props)
89
- props = {} unless props
90
- declared_props.each_key do |prop|
91
- if declared_props[prop].key?(:required) && declared_props[prop][:required] && !props.key?(prop)
92
- Isomorfeus.raise_error(message: "Required prop #{prop} not given!")
93
- end
94
- end
95
- result = true
96
- props.each do |p, v|
97
- r = validate_prop(p, v)
98
- result = false unless r
99
- end
100
- result
101
- end
102
-
103
- def validated_prop(prop, value)
104
- Isomorfeus.raise_error(message: "No such prop #{prop} declared!") unless declared_props.key?(prop)
105
- validator = Isomorfeus::Props::Validator.new(self, prop, value, declared_props[prop])
106
- validator.validated_value
107
- end
108
-
109
- def validated_props(props)
110
- props = {} unless props
111
-
112
- declared_props.each_key do |prop|
113
- if declared_props[prop].key?(:required) && declared_props[prop][:required] && !props.key?(prop)
114
- Isomorfeus.raise_error(message: "Required prop #{prop} not given!")
115
- end
116
- props[prop] = nil unless props.key?(prop) # let validator handle value
117
- end
118
-
119
- result = {}
120
- props.each do |p, v|
121
- result[p] = validated_prop(p, v)
122
- end
123
- result
124
- end
125
- end
126
- end
1
+ module LucidPropDeclaration
2
+ module Mixin
3
+ if RUBY_ENGINE == 'opal'
4
+ def self.extended(base)
5
+ def prop(prop_name, validate_hash = { required: true })
6
+ validate_hash = validate_hash.to_h if validate_hash.class == Isomorfeus::Props::ValidateHashProxy
7
+ if validate_hash.key?(:default)
8
+ %x{
9
+ if (base.lucid_react_component) {
10
+ let react_prop_name = Opal.React.lower_camelize(prop_name);
11
+ #{value = validate_hash[:default]}
12
+ if (!base.lucid_react_component.defaultProps) { base.lucid_react_component.defaultProps = {}; }
13
+ base.lucid_react_component.defaultProps[react_prop_name] = value;
14
+ if (!base.lucid_react_component.propTypes) { base.lucid_react_component.propTypes = {}; }
15
+ base.lucid_react_component.propTypes[react_prop_name] = base.lucid_react_component.prototype.validateProp;
16
+ } else if (base.react_component) {
17
+ let react_prop_name = Opal.React.lower_camelize(prop_name);
18
+ #{value = validate_hash[:default]}
19
+ if (!base.react_component.defaultProps) { base.react_component.defaultProps = {}; }
20
+ base.react_component.defaultProps[react_prop_name] = value;
21
+ if (!base.react_component.propTypes) { base.react_component.propTypes = {}; }
22
+ base.react_component.propTypes[react_prop_name] = base.react_component.prototype.validateProp;
23
+ }
24
+ }
25
+ end
26
+ declared_props[prop_name.to_sym] = validate_hash
27
+ end
28
+ end
29
+
30
+ def validate_function
31
+ %x{
32
+ if (typeof self.validate_function === 'undefined') {
33
+ self.validate_function = function(props_object) {
34
+ try { self.$validate_props(Opal.Hash.$new(props_object)) }
35
+ catch (e) { return e.message; }
36
+ }
37
+ }
38
+ return self.validate_function;
39
+ }
40
+ end
41
+
42
+ def validate_prop_function(prop)
43
+ function_name = "validate_#{prop}_function"
44
+ %x{
45
+ if (typeof self[function_name] === 'undefined') {
46
+ self[function_name] = function(value) {
47
+ try { self.$validate_prop(prop, value); }
48
+ catch (e) { return e.message; }
49
+ }
50
+ }
51
+ return self[function_name];
52
+ }
53
+ end
54
+ else
55
+ def prop(prop_name, validate_hash = { required: true })
56
+ validate_hash = validate_hash.to_h if validate_hash.class == Isomorfeus::Props::ValidateHashProxy
57
+ declared_props[prop_name.to_sym] = validate_hash
58
+ end
59
+ end
60
+
61
+ def declared_props
62
+ @declared_props ||= {}
63
+ end
64
+
65
+ def valid_prop?(prop, value)
66
+ validate_prop(prop, value)
67
+ rescue
68
+ false
69
+ end
70
+
71
+ def valid_props?(props)
72
+ validate_props(props)
73
+ rescue
74
+ false
75
+ end
76
+
77
+ def validate
78
+ Isomorfeus::Props::ValidateHashProxy.new
79
+ end
80
+
81
+ def validate_prop(prop, value)
82
+ return false unless declared_props.key?(prop)
83
+ validator = Isomorfeus::Props::Validator.new(self, prop, value, declared_props[prop])
84
+ validator.validate!
85
+ true
86
+ end
87
+
88
+ def validate_props(props)
89
+ props = {} unless props
90
+ declared_props.each_key do |prop|
91
+ if declared_props[prop].key?(:required) && declared_props[prop][:required] && !props.key?(prop)
92
+ Isomorfeus.raise_error(message: "Required prop #{prop} not given!")
93
+ end
94
+ end
95
+ result = true
96
+ props.each do |p, v|
97
+ r = validate_prop(p, v)
98
+ result = false unless r
99
+ end
100
+ result
101
+ end
102
+
103
+ def validated_prop(prop, value)
104
+ Isomorfeus.raise_error(message: "No such prop #{prop} declared!") unless declared_props.key?(prop)
105
+ validator = Isomorfeus::Props::Validator.new(self, prop, value, declared_props[prop])
106
+ validator.validated_value
107
+ end
108
+
109
+ def validated_props(props)
110
+ props = {} unless props
111
+
112
+ declared_props.each_key do |prop|
113
+ if declared_props[prop].key?(:required) && declared_props[prop][:required] && !props.key?(prop)
114
+ Isomorfeus.raise_error(message: "Required prop #{prop} not given!")
115
+ end
116
+ props[prop] = nil unless props.key?(prop) # let validator handle value
117
+ end
118
+
119
+ result = {}
120
+ props.each do |p, v|
121
+ result[p] = validated_prop(p, v)
122
+ end
123
+ result
124
+ end
125
+ end
126
+ end
@@ -1,35 +1,35 @@
1
- module React
2
- module Children
3
- class << self
4
- def count(children)
5
- `Opal.global.React.Children.count(children)`
6
- end
7
-
8
- def for_each(children, &block)
9
- %x{
10
- var fun = function(child) {
11
- #{block.call(child)};
12
- }
13
- Opal.global.React.Children.forEach(children, fun);
14
- }
15
- end
16
-
17
- def map(children, &block)
18
- %x{
19
- var fun = function(child) {
20
- return #{block.call(child)};
21
- }
22
- return Opal.global.React.Children.map(children, fun);
23
- }
24
- end
25
-
26
- def only(children)
27
- `Opal.global.React.Children.only(children)`
28
- end
29
-
30
- def to_array(children)
31
- `Opal.global.React.Children.toArray(children)`
32
- end
33
- end
34
- end
1
+ module React
2
+ module Children
3
+ class << self
4
+ def count(children)
5
+ `Opal.global.React.Children.count(children)`
6
+ end
7
+
8
+ def for_each(children, &block)
9
+ %x{
10
+ var fun = function(child) {
11
+ #{block.call(child)};
12
+ }
13
+ Opal.global.React.Children.forEach(children, fun);
14
+ }
15
+ end
16
+
17
+ def map(children, &block)
18
+ %x{
19
+ var fun = function(child) {
20
+ return #{block.call(child)};
21
+ }
22
+ return Opal.global.React.Children.map(children, fun);
23
+ }
24
+ end
25
+
26
+ def only(children)
27
+ `Opal.global.React.Children.only(children)`
28
+ end
29
+
30
+ def to_array(children)
31
+ `Opal.global.React.Children.toArray(children)`
32
+ end
33
+ end
34
+ end
35
35
  end
@@ -1,134 +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, *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
+ 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