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.
- checksums.yaml +4 -4
- data/README.md +4 -10
- data/lib/isomorfeus/props/validator.rb +2 -2
- data/lib/isomorfeus/{react_config.rb → react/config.rb} +189 -189
- data/lib/isomorfeus/react/memcached_component_cache.rb +19 -0
- data/lib/isomorfeus/react/redis_component_cache.rb +19 -0
- data/lib/isomorfeus/{thread_local_component_cache.rb → react/thread_local_component_cache.rb} +15 -15
- data/lib/isomorfeus/react_view_helper.rb +231 -231
- data/lib/isomorfeus/top_level.rb +103 -103
- data/lib/isomorfeus/top_level_ssr.rb +42 -42
- data/lib/isomorfeus-react-material-ui.rb +4 -4
- data/lib/isomorfeus-react-native.rb +5 -0
- data/lib/isomorfeus-react-paper.rb +4 -0
- data/lib/isomorfeus-react.rb +120 -118
- data/lib/isomorfeus_react/lucid_app/api.rb +26 -26
- data/lib/isomorfeus_react/lucid_app/base.rb +7 -7
- data/lib/isomorfeus_react/lucid_app/mixin.rb +23 -22
- data/lib/isomorfeus_react/lucid_app/native_component_constructor.rb +48 -49
- data/lib/isomorfeus_react/lucid_app/native_lucid_component_constructor.rb +94 -95
- data/lib/isomorfeus_react/lucid_component/api.rb +75 -102
- data/lib/isomorfeus_react/lucid_component/app_store_proxy.rb +37 -37
- data/lib/isomorfeus_react/lucid_component/base.rb +7 -7
- data/lib/isomorfeus_react/lucid_component/class_store_proxy.rb +44 -44
- data/lib/isomorfeus_react/lucid_component/initializer.rb +14 -14
- data/lib/isomorfeus_react/lucid_component/instance_store_proxy.rb +44 -44
- data/lib/isomorfeus_react/lucid_component/mixin.rb +22 -21
- data/lib/isomorfeus_react/lucid_component/native_component_constructor.rb +35 -35
- data/lib/isomorfeus_react/lucid_component/native_lucid_component_constructor.rb +82 -108
- data/lib/isomorfeus_react/lucid_component/styles_api.rb +34 -0
- data/lib/isomorfeus_react/lucid_func/base.rb +7 -7
- data/lib/isomorfeus_react/lucid_func/initializer.rb +11 -11
- data/lib/isomorfeus_react/lucid_func/mixin.rb +18 -17
- data/lib/isomorfeus_react/lucid_func/native_component_constructor.rb +81 -81
- data/lib/isomorfeus_react/react/function_component/api.rb +105 -104
- data/lib/isomorfeus_react/react/function_component/base.rb +8 -8
- data/lib/isomorfeus_react/react/function_component/initializer.rb +10 -10
- data/lib/isomorfeus_react/react/function_component/mixin.rb +17 -17
- data/lib/isomorfeus_react/react/function_component/native_component_constructor.rb +48 -48
- data/lib/isomorfeus_react/react/memo_component/base.rb +8 -8
- data/lib/isomorfeus_react/react/memo_component/mixin.rb +17 -17
- data/lib/isomorfeus_react/react/memo_component/native_component_constructor.rb +49 -49
- data/lib/isomorfeus_react_material/lucid_material/app/base.rb +8 -8
- data/lib/isomorfeus_react_material/lucid_material/app/mixin.rb +20 -19
- data/lib/isomorfeus_react_material/lucid_material/app/native_component_constructor.rb +50 -51
- data/lib/isomorfeus_react_material/lucid_material/component/base.rb +9 -9
- data/lib/isomorfeus_react_material/lucid_material/component/mixin.rb +19 -18
- data/lib/isomorfeus_react_material/lucid_material/component/native_component_constructor.rb +36 -36
- data/lib/isomorfeus_react_material/lucid_material/func/base.rb +9 -9
- data/lib/isomorfeus_react_material/lucid_material/func/mixin.rb +15 -14
- data/lib/isomorfeus_react_material/lucid_material/func/native_component_constructor.rb +83 -83
- data/lib/isomorfeus_react_paper/lucid_paper/app/base.rb +9 -0
- data/lib/isomorfeus_react_paper/lucid_paper/app/mixin.rb +19 -0
- data/lib/isomorfeus_react_paper/lucid_paper/app/native_component_constructor.rb +32 -0
- data/lib/isomorfeus_react_paper/lucid_paper/component/base.rb +9 -0
- data/lib/isomorfeus_react_paper/lucid_paper/component/mixin.rb +18 -0
- data/lib/isomorfeus_react_paper/lucid_paper/component/native_component_constructor.rb +25 -0
- data/lib/isomorfeus_react_paper/lucid_paper/func/base.rb +9 -0
- data/lib/isomorfeus_react_paper/lucid_paper/func/mixin.rb +14 -0
- data/lib/isomorfeus_react_paper/lucid_paper/func/native_component_constructor.rb +71 -0
- data/lib/lucid_app/context.rb +7 -7
- data/lib/lucid_prop_declaration/mixin.rb +126 -126
- data/lib/react/children.rb +34 -34
- data/lib/react/component/api.rb +134 -133
- data/lib/react/component/base.rb +8 -8
- data/lib/react/component/callbacks.rb +115 -115
- data/lib/react/component/elements.rb +60 -60
- data/lib/react/component/features.rb +48 -48
- data/lib/react/component/history.rb +69 -65
- data/lib/react/component/initializer.rb +11 -11
- data/lib/react/component/location.rb +19 -15
- data/lib/react/component/match.rb +35 -31
- data/lib/react/component/mixin.rb +20 -20
- data/lib/react/component/native_component_constructor.rb +69 -95
- data/lib/react/component/props.rb +83 -83
- data/lib/react/component/resolution.rb +97 -97
- data/lib/react/component/state.rb +58 -54
- data/lib/react/component/styles.rb +66 -66
- data/lib/react/context_wrapper.rb +48 -44
- data/lib/react/native_constant_wrapper.rb +29 -29
- data/lib/react/ref.rb +16 -12
- data/lib/react/synthetic_event.rb +52 -52
- data/lib/react/version.rb +3 -3
- data/lib/react.rb +296 -262
- data/lib/react_dom.rb +41 -41
- data/lib/react_dom_server.rb +18 -18
- data/lib/react_native/component/elements.rb +203 -0
- data/lib/react_native/lucid_app/react_native_component_constructor.rb +51 -0
- data/lib/react_native/lucid_component/react_native_component_constructor.rb +37 -0
- data/lib/react_native/lucid_func/react_native_component_constructor.rb +82 -0
- data/lib/react_native/react.rb +120 -0
- metadata +76 -23
@@ -1,81 +1,81 @@
|
|
1
|
-
module LucidFunc
|
2
|
-
module NativeComponentConstructor
|
3
|
-
def self.extended(base)
|
4
|
-
component_name = base.to_s
|
5
|
-
%x{
|
6
|
-
base.store_updates = true;
|
7
|
-
base.equality_checker = null;
|
8
|
-
base.instance_init = function(initial) {
|
9
|
-
let ruby_state = { instance: #{base.new(`{}`)} };
|
10
|
-
ruby_state.instance.__ruby_instance = ruby_state.instance;
|
11
|
-
ruby_state.instance.data_access = function() { return this.props.store; }
|
12
|
-
ruby_state.instance.data_access.bind(ruby_state.instance);
|
13
|
-
return ruby_state;
|
14
|
-
}
|
15
|
-
base.instance_reducer = function(state, action) { return state; }
|
16
|
-
base.react_component = Opal.global.React.memo(function(props) {
|
17
|
-
const og = Opal.global;
|
18
|
-
const oper = Opal.React;
|
19
|
-
oper.render_buffer.push([]);
|
20
|
-
// console.log("function pushed", oper.render_buffer, oper.render_buffer.toString());
|
21
|
-
// Lucid functionality
|
22
|
-
let classes = null;
|
23
|
-
let store;
|
24
|
-
if (base.store_updates) { store = og.React.useContext(og.LucidApplicationContext); }
|
25
|
-
let theme = og.ReactJSS.useTheme();
|
26
|
-
if (base.jss_styles) {
|
27
|
-
if (!base.use_styles || (Opal.Isomorfeus.development === true)) {
|
28
|
-
let styles;
|
29
|
-
if (typeof base.jss_styles === 'function') { styles = base.jss_styles(theme); }
|
30
|
-
else { styles = base.jss_styles; }
|
31
|
-
base.use_styles = og.ReactJSS.createUseStyles(styles);
|
32
|
-
}
|
33
|
-
classes = base.use_styles();
|
34
|
-
}
|
35
|
-
// prepare Ruby instance
|
36
|
-
const [__ruby_state, __ruby_dispatch] = og.React.useReducer(base.instance_reducer, null, base.instance_init);
|
37
|
-
const __ruby_instance = __ruby_state.instance;
|
38
|
-
__ruby_instance.props = Object.assign({}, props);
|
39
|
-
__ruby_instance.props.store = store;
|
40
|
-
__ruby_instance.props.theme = theme;
|
41
|
-
__ruby_instance.props.classes = classes;
|
42
|
-
oper.active_components.push(__ruby_instance);
|
43
|
-
oper.active_redux_components.push(__ruby_instance);
|
44
|
-
let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
|
45
|
-
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
46
|
-
oper.active_redux_components.pop();
|
47
|
-
oper.active_components.pop();
|
48
|
-
// console.log("function popping", oper.render_buffer, oper.render_buffer.toString());
|
49
|
-
let result = oper.render_buffer.pop();
|
50
|
-
return (result.length === 1) ? result[0] : result;
|
51
|
-
}, base.equality_checker);
|
52
|
-
base.react_component.displayName = #{component_name};
|
53
|
-
}
|
54
|
-
|
55
|
-
base_module = base.to_s.deconstantize
|
56
|
-
if base_module != ''
|
57
|
-
base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
|
58
|
-
`Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
|
59
|
-
end
|
60
|
-
else
|
61
|
-
Object.define_method(base.to_s) do |*args, &block|
|
62
|
-
`Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def props_are_equal?(&block)
|
67
|
-
%x{
|
68
|
-
base.equality_checker = function (prev_props, next_props) {
|
69
|
-
var prev_ruby_props = Opal.React.Component.Props.$new({props: prev_props});
|
70
|
-
var next_ruby_props = Opal.React.Component.Props.$new({props: next_props});
|
71
|
-
return #{block.call(`prev_ruby_props`, `next_ruby_props`)};
|
72
|
-
}
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
def render(&block)
|
77
|
-
`base.render_block = #{block}`
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
1
|
+
module LucidFunc
|
2
|
+
module NativeComponentConstructor
|
3
|
+
def self.extended(base)
|
4
|
+
component_name = base.to_s
|
5
|
+
%x{
|
6
|
+
base.store_updates = true;
|
7
|
+
base.equality_checker = null;
|
8
|
+
base.instance_init = function(initial) {
|
9
|
+
let ruby_state = { instance: #{base.new(`{}`)} };
|
10
|
+
ruby_state.instance.__ruby_instance = ruby_state.instance;
|
11
|
+
ruby_state.instance.data_access = function() { return this.props.store; }
|
12
|
+
ruby_state.instance.data_access.bind(ruby_state.instance);
|
13
|
+
return ruby_state;
|
14
|
+
}
|
15
|
+
base.instance_reducer = function(state, action) { return state; }
|
16
|
+
base.react_component = Opal.global.React.memo(function(props) {
|
17
|
+
const og = Opal.global;
|
18
|
+
const oper = Opal.React;
|
19
|
+
oper.render_buffer.push([]);
|
20
|
+
// console.log("function pushed", oper.render_buffer, oper.render_buffer.toString());
|
21
|
+
// Lucid functionality
|
22
|
+
let classes = null;
|
23
|
+
let store;
|
24
|
+
if (base.store_updates) { store = og.React.useContext(og.LucidApplicationContext); }
|
25
|
+
let theme = og.ReactJSS.useTheme();
|
26
|
+
if (base.jss_styles) {
|
27
|
+
if (!base.use_styles || (Opal.Isomorfeus.development === true)) {
|
28
|
+
let styles;
|
29
|
+
if (typeof base.jss_styles === 'function') { styles = base.jss_styles(theme); }
|
30
|
+
else { styles = base.jss_styles; }
|
31
|
+
base.use_styles = og.ReactJSS.createUseStyles(styles);
|
32
|
+
}
|
33
|
+
classes = base.use_styles();
|
34
|
+
}
|
35
|
+
// prepare Ruby instance
|
36
|
+
const [__ruby_state, __ruby_dispatch] = og.React.useReducer(base.instance_reducer, null, base.instance_init);
|
37
|
+
const __ruby_instance = __ruby_state.instance;
|
38
|
+
__ruby_instance.props = Object.assign({}, props);
|
39
|
+
__ruby_instance.props.store = store;
|
40
|
+
__ruby_instance.props.theme = theme;
|
41
|
+
__ruby_instance.props.classes = classes;
|
42
|
+
oper.active_components.push(__ruby_instance);
|
43
|
+
oper.active_redux_components.push(__ruby_instance);
|
44
|
+
let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
|
45
|
+
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
46
|
+
oper.active_redux_components.pop();
|
47
|
+
oper.active_components.pop();
|
48
|
+
// console.log("function popping", oper.render_buffer, oper.render_buffer.toString());
|
49
|
+
let result = oper.render_buffer.pop();
|
50
|
+
return (result.length === 1) ? result[0] : result;
|
51
|
+
}, base.equality_checker);
|
52
|
+
base.react_component.displayName = #{component_name};
|
53
|
+
}
|
54
|
+
|
55
|
+
base_module = base.to_s.deconstantize
|
56
|
+
if base_module != ''
|
57
|
+
base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
|
58
|
+
`Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
|
59
|
+
end
|
60
|
+
else
|
61
|
+
Object.define_method(base.to_s) do |*args, &block|
|
62
|
+
`Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def props_are_equal?(&block)
|
67
|
+
%x{
|
68
|
+
base.equality_checker = function (prev_props, next_props) {
|
69
|
+
var prev_ruby_props = Opal.React.Component.Props.$new({props: prev_props});
|
70
|
+
var next_ruby_props = Opal.React.Component.Props.$new({props: next_props});
|
71
|
+
return #{block.call(`prev_ruby_props`, `next_ruby_props`)};
|
72
|
+
}
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def render(&block)
|
77
|
+
`base.render_block = #{block}`
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -1,104 +1,105 @@
|
|
1
|
-
module React
|
2
|
-
module FunctionComponent
|
3
|
-
module Api
|
4
|
-
def props
|
5
|
-
@native_props
|
6
|
-
end
|
7
|
-
|
8
|
-
def use_callback(deps, &block)
|
9
|
-
`Opal.global.React.useCallback(function() { #{block.call} }, deps)`
|
10
|
-
end
|
11
|
-
|
12
|
-
def use_context(context)
|
13
|
-
`(typeof context.$is_wrapped_context !== 'undefined')` ? context.to_n : context
|
14
|
-
`Opal.global.React.useContext(native_context)`
|
15
|
-
end
|
16
|
-
|
17
|
-
def use_debug_value(value)
|
18
|
-
`Opal.global.React.useDebugValue(value)`
|
19
|
-
end
|
20
|
-
|
21
|
-
def use_effect(&block)
|
22
|
-
`Opal.global.React.useEffect(function() { #{block.call} })`
|
23
|
-
end
|
24
|
-
|
25
|
-
def use_imperative_handle(ref, *deps, &block)
|
26
|
-
native_ref = `(typeof ref.$is_wrapped_ref !== 'undefined')` ? ref.to_n : ref
|
27
|
-
`Opal.global.React.useImperativeHandle(native_ref, function() { #{block.call} }, deps)`
|
28
|
-
end
|
29
|
-
|
30
|
-
def use_layout_effect(&block)
|
31
|
-
`Opal.global.React.useLayoutEffect(function() { #{block.call} })`
|
32
|
-
end
|
33
|
-
|
34
|
-
def use_memo(*deps, &block)
|
35
|
-
`Opal.global.React.useMemo(function() { #{block.call} }, deps)`
|
36
|
-
end
|
37
|
-
|
38
|
-
def use_reducer(inital_state, &block)
|
39
|
-
state = nil
|
40
|
-
dispatcher = nil
|
41
|
-
%x{
|
42
|
-
[state, dispatcher] = Opal.global.React.useReducer(function(state, action) {
|
43
|
-
#{block.call(state, action)}
|
44
|
-
}, initial_state);
|
45
|
-
}
|
46
|
-
[state, proc { |arg| `dispatcher(arg)` }]
|
47
|
-
end
|
48
|
-
|
49
|
-
def use_ref(native_ref)
|
50
|
-
React::Ref.new(`Opal.global.React.useRef(native_ref)`)
|
51
|
-
end
|
52
|
-
|
53
|
-
def use_state(initial_value)
|
54
|
-
initial = nil
|
55
|
-
setter = nil
|
56
|
-
`[initial, setter] = Opal.global.React.useState(initial_value);`
|
57
|
-
[initial, proc { |arg| `setter(arg)` }]
|
58
|
-
end
|
59
|
-
|
60
|
-
def get_react_element(arg, &block)
|
61
|
-
if block_given?
|
62
|
-
# execute block, fetch last element from buffer
|
63
|
-
%x{
|
64
|
-
let last_buffer_length = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].length;
|
65
|
-
let last_buffer_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1][last_buffer_length - 1];
|
66
|
-
block.$call();
|
67
|
-
// console.log("get_react_element popping", Opal.React.render_buffer, Opal.React.render_buffer.toString())
|
68
|
-
let new_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].pop();
|
69
|
-
if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any React element!")} }
|
70
|
-
return new_element;
|
71
|
-
}
|
72
|
-
else
|
73
|
-
# element was rendered before being passed as arg
|
74
|
-
# fetch last element from buffer
|
75
|
-
# `console.log("get_react_element popping", Opal.React.render_buffer, Opal.React.render_buffer.toString())`
|
76
|
-
`Opal.React.render_buffer[Opal.React.render_buffer.length - 1].pop()`
|
77
|
-
end
|
78
|
-
end
|
79
|
-
alias gre get_react_element
|
80
|
-
|
81
|
-
def render_react_element(el)
|
82
|
-
# push el to buffer
|
83
|
-
`Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(el)`
|
84
|
-
# `console.log("render_react_element pushed", Opal.React.render_buffer, Opal.React.render_buffer.toString())`
|
85
|
-
nil
|
86
|
-
end
|
87
|
-
alias rre render_react_element
|
88
|
-
|
89
|
-
def method_ref(method_symbol)
|
90
|
-
|
91
|
-
|
92
|
-
if (
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
1
|
+
module React
|
2
|
+
module FunctionComponent
|
3
|
+
module Api
|
4
|
+
def props
|
5
|
+
@native_props
|
6
|
+
end
|
7
|
+
|
8
|
+
def use_callback(deps, &block)
|
9
|
+
`Opal.global.React.useCallback(function() { #{block.call} }, deps)`
|
10
|
+
end
|
11
|
+
|
12
|
+
def use_context(context)
|
13
|
+
`(typeof context.$is_wrapped_context !== 'undefined')` ? context.to_n : context
|
14
|
+
`Opal.global.React.useContext(native_context)`
|
15
|
+
end
|
16
|
+
|
17
|
+
def use_debug_value(value)
|
18
|
+
`Opal.global.React.useDebugValue(value)`
|
19
|
+
end
|
20
|
+
|
21
|
+
def use_effect(*args, &block)
|
22
|
+
`Opal.global.React.useEffect(function() { #{block.call} }, args)`
|
23
|
+
end
|
24
|
+
|
25
|
+
def use_imperative_handle(ref, *deps, &block)
|
26
|
+
native_ref = `(typeof ref.$is_wrapped_ref !== 'undefined')` ? ref.to_n : ref
|
27
|
+
`Opal.global.React.useImperativeHandle(native_ref, function() { #{block.call} }, deps)`
|
28
|
+
end
|
29
|
+
|
30
|
+
def use_layout_effect(&block)
|
31
|
+
`Opal.global.React.useLayoutEffect(function() { #{block.call} })`
|
32
|
+
end
|
33
|
+
|
34
|
+
def use_memo(*deps, &block)
|
35
|
+
`Opal.global.React.useMemo(function() { #{block.call} }, deps)`
|
36
|
+
end
|
37
|
+
|
38
|
+
def use_reducer(inital_state, &block)
|
39
|
+
state = nil
|
40
|
+
dispatcher = nil
|
41
|
+
%x{
|
42
|
+
[state, dispatcher] = Opal.global.React.useReducer(function(state, action) {
|
43
|
+
#{block.call(state, action)}
|
44
|
+
}, initial_state);
|
45
|
+
}
|
46
|
+
[state, proc { |arg| `dispatcher(arg)` }]
|
47
|
+
end
|
48
|
+
|
49
|
+
def use_ref(native_ref)
|
50
|
+
React::Ref.new(`Opal.global.React.useRef(native_ref)`)
|
51
|
+
end
|
52
|
+
|
53
|
+
def use_state(initial_value)
|
54
|
+
initial = nil
|
55
|
+
setter = nil
|
56
|
+
`[initial, setter] = Opal.global.React.useState(initial_value);`
|
57
|
+
[initial, proc { |arg| `setter(arg)` }]
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_react_element(arg, &block)
|
61
|
+
if block_given?
|
62
|
+
# execute block, fetch last element from buffer
|
63
|
+
%x{
|
64
|
+
let last_buffer_length = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].length;
|
65
|
+
let last_buffer_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1][last_buffer_length - 1];
|
66
|
+
block.$call();
|
67
|
+
// console.log("get_react_element popping", Opal.React.render_buffer, Opal.React.render_buffer.toString())
|
68
|
+
let new_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].pop();
|
69
|
+
if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any React element!")} }
|
70
|
+
return new_element;
|
71
|
+
}
|
72
|
+
else
|
73
|
+
# element was rendered before being passed as arg
|
74
|
+
# fetch last element from buffer
|
75
|
+
# `console.log("get_react_element popping", Opal.React.render_buffer, Opal.React.render_buffer.toString())`
|
76
|
+
`Opal.React.render_buffer[Opal.React.render_buffer.length - 1].pop()`
|
77
|
+
end
|
78
|
+
end
|
79
|
+
alias gre get_react_element
|
80
|
+
|
81
|
+
def render_react_element(el)
|
82
|
+
# push el to buffer
|
83
|
+
`Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(el)`
|
84
|
+
# `console.log("render_react_element pushed", Opal.React.render_buffer, Opal.React.render_buffer.toString())`
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
alias rre render_react_element
|
88
|
+
|
89
|
+
def method_ref(method_symbol, *args)
|
90
|
+
method_key = "#{method_symbol}#{args}"
|
91
|
+
%x{
|
92
|
+
if (#{self}.method_refs && #{self}.method_refs[#{method_key}]) { return #{self}.method_refs[#{method_key}]; }
|
93
|
+
if (!#{self}.method_refs) { #{self}.method_refs = {}; }
|
94
|
+
#{self}.method_refs[#{method_key}] = { m: #{method(method_symbol)}, a: args };
|
95
|
+
return #{self}.method_refs[#{method_key}];
|
96
|
+
}
|
97
|
+
end
|
98
|
+
alias m_ref method_ref
|
99
|
+
|
100
|
+
def to_n
|
101
|
+
self
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module React
|
2
|
-
module FunctionComponent
|
3
|
-
class Base
|
4
|
-
def self.inherited(base)
|
5
|
-
base.include(::React::FunctionComponent::Mixin)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
1
|
+
module React
|
2
|
+
module FunctionComponent
|
3
|
+
class Base
|
4
|
+
def self.inherited(base)
|
5
|
+
base.include(::React::FunctionComponent::Mixin)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module React
|
2
|
-
module FunctionComponent
|
3
|
-
module Initializer
|
4
|
-
def initialize
|
5
|
-
self.JS[:native_props] = `{ props: null }`
|
6
|
-
@native_props = ::React::Component::Props.new(self)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
module React
|
2
|
+
module FunctionComponent
|
3
|
+
module Initializer
|
4
|
+
def initialize
|
5
|
+
self.JS[:native_props] = `{ props: null }`
|
6
|
+
@native_props = ::React::Component::Props.new(self)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
module React
|
2
|
-
module FunctionComponent
|
3
|
-
module Mixin
|
4
|
-
def self.included(base)
|
5
|
-
if on_browser? || on_ssr?
|
6
|
-
base.include(::React::Component::Elements)
|
7
|
-
elsif on_mobile?
|
8
|
-
base.include(::ReactNative::Component::Elements)
|
9
|
-
end
|
10
|
-
base.include(::React::Component::Features)
|
11
|
-
base.include(::React::FunctionComponent::Initializer)
|
12
|
-
base.include(::React::FunctionComponent::Api)
|
13
|
-
base.extend(::React::FunctionComponent::NativeComponentConstructor)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
module React
|
2
|
+
module FunctionComponent
|
3
|
+
module Mixin
|
4
|
+
def self.included(base)
|
5
|
+
if on_browser? || on_ssr?
|
6
|
+
base.include(::React::Component::Elements)
|
7
|
+
elsif on_mobile?
|
8
|
+
base.include(::ReactNative::Component::Elements)
|
9
|
+
end
|
10
|
+
base.include(::React::Component::Features)
|
11
|
+
base.include(::React::FunctionComponent::Initializer)
|
12
|
+
base.include(::React::FunctionComponent::Api)
|
13
|
+
base.extend(::React::FunctionComponent::NativeComponentConstructor)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,48 +1,48 @@
|
|
1
|
-
module React
|
2
|
-
module FunctionComponent
|
3
|
-
module NativeComponentConstructor
|
4
|
-
def self.extended(base)
|
5
|
-
component_name = base.to_s
|
6
|
-
%x{
|
7
|
-
base.instance_init = function(initial) {
|
8
|
-
let ruby_state = { instance: #{base.new(`{}`)} };
|
9
|
-
ruby_state.instance.__ruby_instance = ruby_state.instance;
|
10
|
-
return ruby_state;
|
11
|
-
}
|
12
|
-
base.instance_reducer = function(state, action) { return state; }
|
13
|
-
base.react_component = function(props) {
|
14
|
-
const oper = Opal.React;
|
15
|
-
oper.render_buffer.push([]);
|
16
|
-
// console.log("function pushed", oper.render_buffer, oper.render_buffer.toString());
|
17
|
-
const [__ruby_state, __ruby_dispatch] = Opal.global.React.useReducer(base.instance_reducer, null, base.instance_init);
|
18
|
-
const __ruby_instance = __ruby_state.instance;
|
19
|
-
__ruby_instance.props = props;
|
20
|
-
oper.active_components.push(__ruby_instance);
|
21
|
-
let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
|
22
|
-
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
23
|
-
oper.active_components.pop();
|
24
|
-
// console.log("function popping", oper.render_buffer, oper.render_buffer.toString());
|
25
|
-
let result = oper.render_buffer.pop();
|
26
|
-
return (result.length === 1) ? result[0] : result;
|
27
|
-
}
|
28
|
-
base.react_component.displayName = #{component_name};
|
29
|
-
}
|
30
|
-
|
31
|
-
base_module = base.to_s.deconstantize
|
32
|
-
if base_module != ''
|
33
|
-
base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
|
34
|
-
`Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
|
35
|
-
end
|
36
|
-
else
|
37
|
-
Object.define_method(base.to_s) do |*args, &block|
|
38
|
-
`Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def render(&block)
|
43
|
-
`base.render_block = #{block}`
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
1
|
+
module React
|
2
|
+
module FunctionComponent
|
3
|
+
module NativeComponentConstructor
|
4
|
+
def self.extended(base)
|
5
|
+
component_name = base.to_s
|
6
|
+
%x{
|
7
|
+
base.instance_init = function(initial) {
|
8
|
+
let ruby_state = { instance: #{base.new(`{}`)} };
|
9
|
+
ruby_state.instance.__ruby_instance = ruby_state.instance;
|
10
|
+
return ruby_state;
|
11
|
+
}
|
12
|
+
base.instance_reducer = function(state, action) { return state; }
|
13
|
+
base.react_component = function(props) {
|
14
|
+
const oper = Opal.React;
|
15
|
+
oper.render_buffer.push([]);
|
16
|
+
// console.log("function pushed", oper.render_buffer, oper.render_buffer.toString());
|
17
|
+
const [__ruby_state, __ruby_dispatch] = Opal.global.React.useReducer(base.instance_reducer, null, base.instance_init);
|
18
|
+
const __ruby_instance = __ruby_state.instance;
|
19
|
+
__ruby_instance.props = props;
|
20
|
+
oper.active_components.push(__ruby_instance);
|
21
|
+
let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
|
22
|
+
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
23
|
+
oper.active_components.pop();
|
24
|
+
// console.log("function popping", oper.render_buffer, oper.render_buffer.toString());
|
25
|
+
let result = oper.render_buffer.pop();
|
26
|
+
return (result.length === 1) ? result[0] : result;
|
27
|
+
}
|
28
|
+
base.react_component.displayName = #{component_name};
|
29
|
+
}
|
30
|
+
|
31
|
+
base_module = base.to_s.deconstantize
|
32
|
+
if base_module != ''
|
33
|
+
base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
|
34
|
+
`Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
|
35
|
+
end
|
36
|
+
else
|
37
|
+
Object.define_method(base.to_s) do |*args, &block|
|
38
|
+
`Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def render(&block)
|
43
|
+
`base.render_block = #{block}`
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module React
|
2
|
-
module MemoComponent
|
3
|
-
class Base
|
4
|
-
def self.inherited(base)
|
5
|
-
base.include(::React::MemoComponent::Mixin)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
1
|
+
module React
|
2
|
+
module MemoComponent
|
3
|
+
class Base
|
4
|
+
def self.inherited(base)
|
5
|
+
base.include(::React::MemoComponent::Mixin)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
module React
|
2
|
-
module MemoComponent
|
3
|
-
module Mixin
|
4
|
-
def self.included(base)
|
5
|
-
if on_browser? || on_ssr?
|
6
|
-
base.include(::React::Component::Elements)
|
7
|
-
elsif on_mobile?
|
8
|
-
base.include(::ReactNative::Component::Elements)
|
9
|
-
end
|
10
|
-
base.include(::React::Component::Features)
|
11
|
-
base.include(::React::FunctionComponent::Initializer)
|
12
|
-
base.include(::React::FunctionComponent::Api)
|
13
|
-
base.extend(::React::MemoComponent::NativeComponentConstructor)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
module React
|
2
|
+
module MemoComponent
|
3
|
+
module Mixin
|
4
|
+
def self.included(base)
|
5
|
+
if on_browser? || on_ssr?
|
6
|
+
base.include(::React::Component::Elements)
|
7
|
+
elsif on_mobile?
|
8
|
+
base.include(::ReactNative::Component::Elements)
|
9
|
+
end
|
10
|
+
base.include(::React::Component::Features)
|
11
|
+
base.include(::React::FunctionComponent::Initializer)
|
12
|
+
base.include(::React::FunctionComponent::Api)
|
13
|
+
base.extend(::React::MemoComponent::NativeComponentConstructor)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|