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
@@ -0,0 +1,32 @@
1
+ module LucidPaper
2
+ module App
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
+ %x{
9
+ base.jss_theme = Opal.global.Paper.DefaultTheme;
10
+ base.themed_component = Opal.global.Paper.withTheme(base.lucid_react_component);
11
+ base.react_component = class extends Opal.global.React.Component {
12
+ constructor(props) {
13
+ super(props);
14
+ if (Opal.Isomorfeus.$top_component() == nil) { Opal.Isomorfeus['$top_component='](this); }
15
+ }
16
+ static get displayName() {
17
+ return "IsomorfeusTopLevelComponent";
18
+ }
19
+ static set displayName(new_name) {
20
+ // dont do anything here except returning the set value
21
+ return new_name;
22
+ }
23
+ render() {
24
+ let themed_component = Opal.global.React.createElement(base.themed_component, this.props);
25
+ return Opal.global.React.createElement(Opal.global.Paper.Provider, { theme: base.jss_theme }, themed_component);
26
+ }
27
+ }
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ module LucidPaper
2
+ module Component
3
+ class Base
4
+ def self.inherited(base)
5
+ base.include(::LucidPaper::Component::Mixin)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module LucidPaper
2
+ module Component
3
+ module Mixin
4
+ def self.included(base)
5
+ base.include(::Native::Wrapper)
6
+ base.extend(::LucidComponent::NativeLucidComponentConstructor)
7
+ base.extend(::LucidPaper::Component::NativeComponentConstructor)
8
+ base.extend(::LucidPropDeclaration::Mixin)
9
+ base.include(::React::Component::Elements)
10
+ base.include(::React::Component::Api)
11
+ base.include(::React::Component::Callbacks)
12
+ base.include(::LucidComponent::Api)
13
+ base.include(::LucidComponent::Initializer)
14
+ base.include(::React::Component::Features)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ module LucidPaper
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 + 'Wrapper'
9
+ # language=JS
10
+ %x{
11
+ base.react_component = Opal.global.React.memo(function(props) {
12
+ let classes = null;
13
+ let store;
14
+ if (base.store_updates) { store = Opal.global.React.useContext(Opal.global.LucidApplicationContext); }
15
+ let new_props = Object.assign({}, props)
16
+ new_props.store = store;
17
+ new_props.theme = Opal.global.Paper.useTheme();
18
+ return Opal.global.React.createElement(base.lucid_react_component, new_props);
19
+ }, Opal.React.props_are_equal);
20
+ base.react_component.displayName = #{component_name};
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module LucidPaper
2
+ module Func
3
+ class Base
4
+ def self.inherited(base)
5
+ base.include(::LucidPaper::Func::Mixin)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module LucidPaper
2
+ module Func
3
+ module Mixin
4
+ def self.included(base)
5
+ base.include(::React::Component::Elements)
6
+ base.include(::React::Component::Features)
7
+ base.include(::LucidFunc::Initializer)
8
+ base.include(::React::FunctionComponent::Api)
9
+ base.extend(::LucidPaper::Func::NativeComponentConstructor)
10
+ base.include(::LucidComponent::Api)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,71 @@
1
+ module LucidPaper
2
+ module Func
3
+ module NativeComponentConstructor
4
+ def self.extended(base)
5
+ component_name = "#{base.to_s}Wrapper"
6
+ %x{
7
+ base.store_updates = true;
8
+ base.equality_checker = null;
9
+ base.instance_init = function(initial) {
10
+ let ruby_state = { instance: #{base.new(`{}`)} };
11
+ ruby_state.instance.__ruby_instance = ruby_state.instance;
12
+ ruby_state.instance.data_access = function() { return this.props.store; }
13
+ ruby_state.instance.data_access.bind(ruby_state.instance);
14
+ return ruby_state;
15
+ }
16
+ base.instance_reducer = function(state, action) { return state; }
17
+ base.react_component = Opal.global.React.memo(function(props) {
18
+ const og = Opal.global;
19
+ const oper = Opal.React;
20
+ oper.render_buffer.push([]);
21
+ // console.log("function pushed", oper.render_buffer, oper.render_buffer.toString());
22
+ // Lucid functionality
23
+ let store;
24
+ if (base.store_updates) { store = og.React.useContext(og.LucidApplicationContext); }
25
+ // prepare Ruby instance
26
+ const [__ruby_state, __ruby_dispatch] = og.React.useReducer(base.instance_reducer, null, base.instance_init);
27
+ const __ruby_instance = __ruby_state.instance;
28
+ __ruby_instance.props = Object.assign({}, props);
29
+ __ruby_instance.props.store = store;
30
+ __ruby_instance.props.theme = Opal.global.Paper.useTheme();
31
+ oper.active_components.push(__ruby_instance);
32
+ oper.active_redux_components.push(__ruby_instance);
33
+ let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
34
+ if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
35
+ oper.active_redux_components.pop();
36
+ oper.active_components.pop();
37
+ // console.log("function popping", oper.render_buffer, oper.render_buffer.toString());
38
+ let result = oper.render_buffer.pop();
39
+ return (result.length === 1) ? result[0] : result;
40
+ }, base.equality_checker);
41
+ base.react_component.displayName = #{component_name};
42
+ }
43
+
44
+ base_module = base.to_s.deconstantize
45
+ if base_module != ''
46
+ base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
47
+ `Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
48
+ end
49
+ else
50
+ Object.define_method(base.to_s) do |*args, &block|
51
+ `Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
52
+ end
53
+ end
54
+
55
+ def props_are_equal?(&block)
56
+ %x{
57
+ base.equality_checker = function (prev_props, next_props) {
58
+ var prev_ruby_props = Opal.React.Component.Props.$new({props: prev_props});
59
+ var next_ruby_props = Opal.React.Component.Props.$new({props: next_props});
60
+ return #{block.call(`prev_ruby_props`, `next_ruby_props`)};
61
+ }
62
+ }
63
+ end
64
+
65
+ def render(&block)
66
+ `base.render_block = #{block}`
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,7 +1,7 @@
1
- module LucidApp
2
- module Context
3
- def self.create_application_context
4
- React.create_context('LucidApplicationContext', Isomorfeus.store)
5
- end
6
- end
7
- end
1
+ module LucidApp
2
+ module Context
3
+ def self.create_application_context
4
+ React.create_context('LucidApplicationContext', Isomorfeus.store)
5
+ end
6
+ end
7
+ end
@@ -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