isomorfeus-react 16.13.11 → 16.13.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/isomorfeus/react/config.rb +189 -189
- data/lib/isomorfeus/react/memcached_component_cache.rb +19 -19
- data/lib/isomorfeus/react/redis_component_cache.rb +19 -19
- data/lib/isomorfeus/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 -5
- data/lib/isomorfeus-react-paper.rb +4 -4
- data/lib/isomorfeus-react.rb +120 -120
- 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 -23
- data/lib/isomorfeus_react/lucid_app/native_component_constructor.rb +48 -48
- data/lib/isomorfeus_react/lucid_app/native_lucid_component_constructor.rb +94 -95
- data/lib/isomorfeus_react/lucid_component/api.rb +75 -75
- 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 -22
- data/lib/isomorfeus_react/lucid_component/native_component_constructor.rb +35 -35
- data/lib/isomorfeus_react/lucid_component/native_lucid_component_constructor.rb +82 -83
- data/lib/isomorfeus_react/lucid_component/styles_api.rb +34 -34
- 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 -18
- data/lib/isomorfeus_react/lucid_func/native_component_constructor.rb +81 -81
- data/lib/isomorfeus_react/react/function_component/api.rb +105 -105
- 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 -20
- data/lib/isomorfeus_react_material/lucid_material/app/native_component_constructor.rb +50 -50
- data/lib/isomorfeus_react_material/lucid_material/component/base.rb +9 -9
- data/lib/isomorfeus_react_material/lucid_material/component/mixin.rb +19 -19
- 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 -15
- 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 -9
- data/lib/isomorfeus_react_paper/lucid_paper/app/mixin.rb +19 -19
- data/lib/isomorfeus_react_paper/lucid_paper/app/native_component_constructor.rb +32 -32
- data/lib/isomorfeus_react_paper/lucid_paper/component/base.rb +9 -9
- data/lib/isomorfeus_react_paper/lucid_paper/component/mixin.rb +18 -18
- data/lib/isomorfeus_react_paper/lucid_paper/component/native_component_constructor.rb +25 -25
- data/lib/isomorfeus_react_paper/lucid_paper/func/base.rb +9 -9
- data/lib/isomorfeus_react_paper/lucid_paper/func/mixin.rb +14 -14
- data/lib/isomorfeus_react_paper/lucid_paper/func/native_component_constructor.rb +71 -71
- 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 -134
- 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 -70
- 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 -296
- data/lib/react_dom.rb +41 -41
- data/lib/react_dom_server.rb +18 -18
- data/lib/react_native/component/elements.rb +203 -203
- data/lib/react_native/lucid_app/react_native_component_constructor.rb +51 -51
- data/lib/react_native/lucid_component/react_native_component_constructor.rb +37 -37
- data/lib/react_native/lucid_func/react_native_component_constructor.rb +82 -82
- data/lib/react_native/react.rb +120 -120
- metadata +23 -17
|
@@ -1,31 +1,35 @@
|
|
|
1
|
-
module React
|
|
2
|
-
module Component
|
|
3
|
-
class Match
|
|
4
|
-
include ::Native::Wrapper
|
|
5
|
-
|
|
6
|
-
def
|
|
7
|
-
@native
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def
|
|
11
|
-
@native.JS[:props].JS[:match].JS[:
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def
|
|
15
|
-
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def
|
|
19
|
-
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def
|
|
23
|
-
@native.JS[:props].JS[:match].JS[:
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def
|
|
27
|
-
@native.JS[:props].JS[:match]
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
module React
|
|
2
|
+
module Component
|
|
3
|
+
class Match
|
|
4
|
+
include ::Native::Wrapper
|
|
5
|
+
|
|
6
|
+
def initialize(native)
|
|
7
|
+
@native = native
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def method_missing(prop, *args, &block)
|
|
11
|
+
@native.JS[:props].JS[:match].JS[:params].JS[prop]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def is_exact
|
|
15
|
+
@native.JS[:props].JS[:match].JS[:isExact]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def params
|
|
19
|
+
self
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def path
|
|
23
|
+
@native.JS[:props].JS[:match].JS[:path]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def url
|
|
27
|
+
@native.JS[:props].JS[:match].JS[:url]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def to_n
|
|
31
|
+
@native.JS[:props].JS[:match]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
module React
|
|
2
|
-
module Component
|
|
3
|
-
module Mixin
|
|
4
|
-
def self.included(base)
|
|
5
|
-
base.include(::Native::Wrapper)
|
|
6
|
-
base.extend(::React::Component::NativeComponentConstructor)
|
|
7
|
-
base.extend(::LucidPropDeclaration::Mixin)
|
|
8
|
-
if on_browser? || on_ssr?
|
|
9
|
-
base.include(::React::Component::Elements)
|
|
10
|
-
elsif on_mobile?
|
|
11
|
-
base.include(::ReactNative::Component::Elements)
|
|
12
|
-
end
|
|
13
|
-
base.include(::React::Component::Api)
|
|
14
|
-
base.include(::React::Component::Callbacks)
|
|
15
|
-
base.include(::React::Component::Initializer)
|
|
16
|
-
base.include(::React::Component::Features)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
1
|
+
module React
|
|
2
|
+
module Component
|
|
3
|
+
module Mixin
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.include(::Native::Wrapper)
|
|
6
|
+
base.extend(::React::Component::NativeComponentConstructor)
|
|
7
|
+
base.extend(::LucidPropDeclaration::Mixin)
|
|
8
|
+
if on_browser? || on_ssr?
|
|
9
|
+
base.include(::React::Component::Elements)
|
|
10
|
+
elsif on_mobile?
|
|
11
|
+
base.include(::ReactNative::Component::Elements)
|
|
12
|
+
end
|
|
13
|
+
base.include(::React::Component::Api)
|
|
14
|
+
base.include(::React::Component::Callbacks)
|
|
15
|
+
base.include(::React::Component::Initializer)
|
|
16
|
+
base.include(::React::Component::Features)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -1,70 +1,69 @@
|
|
|
1
|
-
module React
|
|
2
|
-
module Component
|
|
3
|
-
module NativeComponentConstructor
|
|
4
|
-
# for should_component_update we apply ruby semantics for comparing props
|
|
5
|
-
# to do so, we convert the props to ruby hashes and then compare
|
|
6
|
-
# this makes sure, that for example rubys Nil object gets handled properly
|
|
7
|
-
def self.extended(base)
|
|
8
|
-
component_name = base.to_s
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var defined_refs
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
oper.render_buffer.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
oper.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
end
|
|
1
|
+
module React
|
|
2
|
+
module Component
|
|
3
|
+
module NativeComponentConstructor
|
|
4
|
+
# for should_component_update we apply ruby semantics for comparing props
|
|
5
|
+
# to do so, we convert the props to ruby hashes and then compare
|
|
6
|
+
# this makes sure, that for example rubys Nil object gets handled properly
|
|
7
|
+
def self.extended(base)
|
|
8
|
+
component_name = base.to_s
|
|
9
|
+
%x{
|
|
10
|
+
base.react_component = class extends Opal.global.React.Component {
|
|
11
|
+
constructor(props) {
|
|
12
|
+
super(props);
|
|
13
|
+
if (base.$default_state_defined()) {
|
|
14
|
+
this.state = base.$state().$to_n();
|
|
15
|
+
} else {
|
|
16
|
+
this.state = {};
|
|
17
|
+
};
|
|
18
|
+
this.__ruby_instance = base.$new(this);
|
|
19
|
+
var defined_refs = #{base.defined_refs};
|
|
20
|
+
for (var ref in defined_refs) {
|
|
21
|
+
if (defined_refs[ref] != null) {
|
|
22
|
+
this[ref] = function(element) {
|
|
23
|
+
element = Opal.React.native_element_or_component_to_ruby(element);
|
|
24
|
+
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
|
|
25
|
+
}
|
|
26
|
+
this[ref] = this[ref].bind(this);
|
|
27
|
+
} else {
|
|
28
|
+
this[ref] = Opal.global.React.createRef();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
static get displayName() {
|
|
33
|
+
return #{component_name};
|
|
34
|
+
}
|
|
35
|
+
static set displayName(new_name) {
|
|
36
|
+
// dont do anything here except returning the set value
|
|
37
|
+
return new_name;
|
|
38
|
+
}
|
|
39
|
+
render() {
|
|
40
|
+
const oper = Opal.React;
|
|
41
|
+
oper.render_buffer.push([]);
|
|
42
|
+
// console.log("react component pushed", oper.render_buffer, oper.render_buffer.toString());
|
|
43
|
+
oper.active_components.push(this);
|
|
44
|
+
let block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
|
|
45
|
+
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
|
46
|
+
// console.log("react component popping", oper.render_buffer, oper.render_buffer.toString());
|
|
47
|
+
oper.active_components.pop();
|
|
48
|
+
let result = oper.render_buffer.pop();
|
|
49
|
+
return (result.length === 1) ? result[0] : result;
|
|
50
|
+
}
|
|
51
|
+
shouldComponentUpdate(next_props, next_state) {
|
|
52
|
+
if (base.should_component_update_block) {
|
|
53
|
+
return #{!!`this.__ruby_instance`.instance_exec(React::Component::Props.new(`{props: next_props}`), React::Component::State.new(`{state: next_state }`), &`base.should_component_update_block`)};
|
|
54
|
+
}
|
|
55
|
+
if (!Opal.React.props_are_equal(this.props, next_props)) { return true; }
|
|
56
|
+
if (Opal.React.state_is_not_equal(this.state, next_state)) { return true; }
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
validateProp(props, propName, componentName) {
|
|
60
|
+
try { base.$validate_prop(propName, props[propName]) }
|
|
61
|
+
catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
module React
|
|
2
|
-
module Component
|
|
3
|
-
class Props
|
|
4
|
-
def initialize(native)
|
|
5
|
-
@native = native
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def method_missing(prop, *args, &block)
|
|
9
|
-
%x{
|
|
10
|
-
const p = #@native.props;
|
|
11
|
-
if (typeof p[prop] === 'undefined') {
|
|
12
|
-
prop = Opal.React.lower_camelize(prop);
|
|
13
|
-
if (typeof p[prop] === 'undefined') { return nil; }
|
|
14
|
-
}
|
|
15
|
-
return p[prop];
|
|
16
|
-
}
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def classes
|
|
20
|
-
@classes ||= React::Component::Styles.new(@native, 'classes')
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def children
|
|
24
|
-
@native.JS[:props].JS[:children]
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def theme
|
|
28
|
-
@theme ||= React::Component::Styles.new(@native, 'theme')
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def isomorfeus_store
|
|
32
|
-
@native.JS[:props].JS[:isomorfeus_store]
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# for router convenience
|
|
36
|
-
def history
|
|
37
|
-
return @history if @history
|
|
38
|
-
return nil if `typeof #@native.props.history === 'undefined'`
|
|
39
|
-
if `typeof #@native.props.history.action !== 'undefined'`
|
|
40
|
-
@history = React::Component::History.new(@native)
|
|
41
|
-
else
|
|
42
|
-
@native.JS[:props].JS[:history]
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def location
|
|
47
|
-
return @location if @location
|
|
48
|
-
return nil if `typeof #@native.props.location === 'undefined'`
|
|
49
|
-
if `typeof #@native.props.location.pathname !== 'undefined'`
|
|
50
|
-
@location = React::Component::Location.new(@native)
|
|
51
|
-
else
|
|
52
|
-
@native.JS[:props].JS[:location]
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def match
|
|
57
|
-
return @match if @match
|
|
58
|
-
return nil if `typeof #@native.props.match === 'undefined'`
|
|
59
|
-
if `typeof #@native.props.match.path !== 'undefined'`
|
|
60
|
-
@match = React::Component::Match.new(@native)
|
|
61
|
-
else
|
|
62
|
-
@native.JS[:props].JS[:match]
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def to_h
|
|
67
|
-
`Opal.Hash.$new(#@native.props)`.transform_keys!(&:underscore)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def to_json
|
|
71
|
-
JSON.dump(to_transport)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def to_n
|
|
75
|
-
@native.JS[:props]
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def to_transport
|
|
79
|
-
{}.merge(to_h)
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
1
|
+
module React
|
|
2
|
+
module Component
|
|
3
|
+
class Props
|
|
4
|
+
def initialize(native)
|
|
5
|
+
@native = native
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def method_missing(prop, *args, &block)
|
|
9
|
+
%x{
|
|
10
|
+
const p = #@native.props;
|
|
11
|
+
if (typeof p[prop] === 'undefined') {
|
|
12
|
+
prop = Opal.React.lower_camelize(prop);
|
|
13
|
+
if (typeof p[prop] === 'undefined') { return nil; }
|
|
14
|
+
}
|
|
15
|
+
return p[prop];
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def classes
|
|
20
|
+
@classes ||= React::Component::Styles.new(@native, 'classes')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def children
|
|
24
|
+
@native.JS[:props].JS[:children]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def theme
|
|
28
|
+
@theme ||= React::Component::Styles.new(@native, 'theme')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def isomorfeus_store
|
|
32
|
+
@native.JS[:props].JS[:isomorfeus_store]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# for router convenience
|
|
36
|
+
def history
|
|
37
|
+
return @history if @history
|
|
38
|
+
return nil if `typeof #@native.props.history === 'undefined'`
|
|
39
|
+
if `typeof #@native.props.history.action !== 'undefined'`
|
|
40
|
+
@history = React::Component::History.new(@native)
|
|
41
|
+
else
|
|
42
|
+
@native.JS[:props].JS[:history]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def location
|
|
47
|
+
return @location if @location
|
|
48
|
+
return nil if `typeof #@native.props.location === 'undefined'`
|
|
49
|
+
if `typeof #@native.props.location.pathname !== 'undefined'`
|
|
50
|
+
@location = React::Component::Location.new(@native)
|
|
51
|
+
else
|
|
52
|
+
@native.JS[:props].JS[:location]
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def match
|
|
57
|
+
return @match if @match
|
|
58
|
+
return nil if `typeof #@native.props.match === 'undefined'`
|
|
59
|
+
if `typeof #@native.props.match.path !== 'undefined'`
|
|
60
|
+
@match = React::Component::Match.new(@native)
|
|
61
|
+
else
|
|
62
|
+
@native.JS[:props].JS[:match]
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def to_h
|
|
67
|
+
`Opal.Hash.$new(#@native.props)`.transform_keys!(&:underscore)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def to_json
|
|
71
|
+
JSON.dump(to_transport)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def to_n
|
|
75
|
+
@native.JS[:props]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def to_transport
|
|
79
|
+
{}.merge(to_h)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
module React
|
|
2
|
-
module Component
|
|
3
|
-
module Resolution
|
|
4
|
-
def self.included(base)
|
|
5
|
-
base.instance_exec do
|
|
6
|
-
unless method_defined?(:_react_component_class_resolution_original_const_missing)
|
|
7
|
-
alias _react_component_class_resolution_original_const_missing const_missing
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def const_missing(const_name)
|
|
11
|
-
%x{
|
|
12
|
-
if (typeof Opal.global[const_name] !== "undefined" && (const_name[0] === const_name[0].toUpperCase())) {
|
|
13
|
-
var new_const = #{React::NativeConstantWrapper.new(`Opal.global[const_name]`, const_name)};
|
|
14
|
-
new_const.react_component = Opal.global[const_name];
|
|
15
|
-
#{Object.const_set(const_name, `new_const`)};
|
|
16
|
-
return new_const;
|
|
17
|
-
} else {
|
|
18
|
-
return #{_react_component_class_resolution_original_const_missing(const_name)};
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# this is required for autoloading support, as the component may not be loaded and so its method is not registered.
|
|
24
|
-
# must load it first, done by const_get, and next time the method will be there.
|
|
25
|
-
unless method_defined?(:_react_component_class_resolution_original_method_missing)
|
|
26
|
-
alias _react_component_class_resolution_original_method_missing method_missing
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def method_missing(component_name, *args, &block)
|
|
30
|
-
# check for ruby component and render it
|
|
31
|
-
# otherwise pass on method missing
|
|
32
|
-
%x{
|
|
33
|
-
var constant;
|
|
34
|
-
if (typeof self.iso_react_const_cache === 'undefined') { self.iso_react_const_cache = {}; }
|
|
35
|
-
try {
|
|
36
|
-
if (typeof self.iso_react_const_cache[component_name] !== 'undefined') {
|
|
37
|
-
constant = self.iso_react_const_cache[component_name]
|
|
38
|
-
} else {
|
|
39
|
-
constant = self.$const_get(component_name);
|
|
40
|
-
self.iso_react_const_cache[component_name] = constant;
|
|
41
|
-
}
|
|
42
|
-
if (typeof constant.react_component !== 'undefined') {
|
|
43
|
-
return Opal.React.internal_prepare_args_and_render(constant.react_component, args, block);
|
|
44
|
-
}
|
|
45
|
-
} catch(err) { }
|
|
46
|
-
return #{_react_component_class_resolution_original_method_missing(component_name, *args, block)};
|
|
47
|
-
}
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
unless method_defined?(:_react_component_resolution_original_method_missing)
|
|
53
|
-
alias _react_component_resolution_original_method_missing method_missing
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def method_missing(component_name, *args, &block)
|
|
57
|
-
# Further on it must check for modules, because $const_get does not take
|
|
58
|
-
# the full nesting into account, as usually its called via $$ with the
|
|
59
|
-
# nesting provided by the compiler.
|
|
60
|
-
%x{
|
|
61
|
-
var constant;
|
|
62
|
-
if (typeof self.iso_react_const_cache === 'undefined') { self.iso_react_const_cache = {}; }
|
|
63
|
-
|
|
64
|
-
if (typeof self.iso_react_const_cache[component_name] !== 'undefined') {
|
|
65
|
-
constant = self.iso_react_const_cache[component_name]
|
|
66
|
-
} else if (typeof self.$$is_a_module !== 'undefined') {
|
|
67
|
-
try {
|
|
68
|
-
constant = self.$const_get(component_name);
|
|
69
|
-
self.iso_react_const_cache[component_name] = constant;
|
|
70
|
-
} catch(err) { }
|
|
71
|
-
} else {
|
|
72
|
-
let sc = self.$class();
|
|
73
|
-
try {
|
|
74
|
-
constant = sc.$const_get(component_name);
|
|
75
|
-
self.iso_react_const_cache[component_name] = constant;
|
|
76
|
-
} catch(err) {
|
|
77
|
-
var module_names = sc.$to_s().split("::");
|
|
78
|
-
var module_name;
|
|
79
|
-
for (var i = module_names.length - 1; i > 0; i--) {
|
|
80
|
-
module_name = module_names.slice(0, i).join('::');
|
|
81
|
-
try {
|
|
82
|
-
constant = sc.$const_get(module_name).$const_get(component_name, false);
|
|
83
|
-
self.iso_react_const_cache[component_name] = constant;
|
|
84
|
-
break;
|
|
85
|
-
} catch(err) { }
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (constant && typeof constant.react_component !== 'undefined') {
|
|
90
|
-
return Opal.React.internal_prepare_args_and_render(constant.react_component, args, block);
|
|
91
|
-
}
|
|
92
|
-
return #{_react_component_resolution_original_method_missing(component_name, *args, block)};
|
|
93
|
-
}
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
1
|
+
module React
|
|
2
|
+
module Component
|
|
3
|
+
module Resolution
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.instance_exec do
|
|
6
|
+
unless method_defined?(:_react_component_class_resolution_original_const_missing)
|
|
7
|
+
alias _react_component_class_resolution_original_const_missing const_missing
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def const_missing(const_name)
|
|
11
|
+
%x{
|
|
12
|
+
if (typeof Opal.global[const_name] !== "undefined" && (const_name[0] === const_name[0].toUpperCase())) {
|
|
13
|
+
var new_const = #{React::NativeConstantWrapper.new(`Opal.global[const_name]`, const_name)};
|
|
14
|
+
new_const.react_component = Opal.global[const_name];
|
|
15
|
+
#{Object.const_set(const_name, `new_const`)};
|
|
16
|
+
return new_const;
|
|
17
|
+
} else {
|
|
18
|
+
return #{_react_component_class_resolution_original_const_missing(const_name)};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# this is required for autoloading support, as the component may not be loaded and so its method is not registered.
|
|
24
|
+
# must load it first, done by const_get, and next time the method will be there.
|
|
25
|
+
unless method_defined?(:_react_component_class_resolution_original_method_missing)
|
|
26
|
+
alias _react_component_class_resolution_original_method_missing method_missing
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def method_missing(component_name, *args, &block)
|
|
30
|
+
# check for ruby component and render it
|
|
31
|
+
# otherwise pass on method missing
|
|
32
|
+
%x{
|
|
33
|
+
var constant;
|
|
34
|
+
if (typeof self.iso_react_const_cache === 'undefined') { self.iso_react_const_cache = {}; }
|
|
35
|
+
try {
|
|
36
|
+
if (typeof self.iso_react_const_cache[component_name] !== 'undefined') {
|
|
37
|
+
constant = self.iso_react_const_cache[component_name]
|
|
38
|
+
} else {
|
|
39
|
+
constant = self.$const_get(component_name);
|
|
40
|
+
self.iso_react_const_cache[component_name] = constant;
|
|
41
|
+
}
|
|
42
|
+
if (typeof constant.react_component !== 'undefined') {
|
|
43
|
+
return Opal.React.internal_prepare_args_and_render(constant.react_component, args, block);
|
|
44
|
+
}
|
|
45
|
+
} catch(err) { }
|
|
46
|
+
return #{_react_component_class_resolution_original_method_missing(component_name, *args, block)};
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
unless method_defined?(:_react_component_resolution_original_method_missing)
|
|
53
|
+
alias _react_component_resolution_original_method_missing method_missing
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def method_missing(component_name, *args, &block)
|
|
57
|
+
# Further on it must check for modules, because $const_get does not take
|
|
58
|
+
# the full nesting into account, as usually its called via $$ with the
|
|
59
|
+
# nesting provided by the compiler.
|
|
60
|
+
%x{
|
|
61
|
+
var constant;
|
|
62
|
+
if (typeof self.iso_react_const_cache === 'undefined') { self.iso_react_const_cache = {}; }
|
|
63
|
+
|
|
64
|
+
if (typeof self.iso_react_const_cache[component_name] !== 'undefined') {
|
|
65
|
+
constant = self.iso_react_const_cache[component_name]
|
|
66
|
+
} else if (typeof self.$$is_a_module !== 'undefined') {
|
|
67
|
+
try {
|
|
68
|
+
constant = self.$const_get(component_name);
|
|
69
|
+
self.iso_react_const_cache[component_name] = constant;
|
|
70
|
+
} catch(err) { }
|
|
71
|
+
} else {
|
|
72
|
+
let sc = self.$class();
|
|
73
|
+
try {
|
|
74
|
+
constant = sc.$const_get(component_name);
|
|
75
|
+
self.iso_react_const_cache[component_name] = constant;
|
|
76
|
+
} catch(err) {
|
|
77
|
+
var module_names = sc.$to_s().split("::");
|
|
78
|
+
var module_name;
|
|
79
|
+
for (var i = module_names.length - 1; i > 0; i--) {
|
|
80
|
+
module_name = module_names.slice(0, i).join('::');
|
|
81
|
+
try {
|
|
82
|
+
constant = sc.$const_get(module_name).$const_get(component_name, false);
|
|
83
|
+
self.iso_react_const_cache[component_name] = constant;
|
|
84
|
+
break;
|
|
85
|
+
} catch(err) { }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (constant && typeof constant.react_component !== 'undefined') {
|
|
90
|
+
return Opal.React.internal_prepare_args_and_render(constant.react_component, args, block);
|
|
91
|
+
}
|
|
92
|
+
return #{_react_component_resolution_original_method_missing(component_name, *args, block)};
|
|
93
|
+
}
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|