isomorfeus-react 16.9.24 → 16.10.0
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
- metadata +3 -85
- data/README.md +0 -64
- data/lib/browser/delegate_native.rb +0 -70
- data/lib/browser/element.rb +0 -176
- data/lib/browser/element/canvas.rb +0 -17
- data/lib/browser/element/media.rb +0 -78
- data/lib/browser/event.rb +0 -92
- data/lib/browser/event_target.rb +0 -39
- data/lib/browser/file_list.rb +0 -125
- data/lib/browser/iterable.rb +0 -15
- data/lib/isomorfeus-react-material-ui.rb +0 -10
- data/lib/isomorfeus-react.rb +0 -145
- data/lib/isomorfeus/config.rb +0 -130
- data/lib/isomorfeus/props/validate_hash_proxy.rb +0 -178
- data/lib/isomorfeus/props/validator.rb +0 -131
- data/lib/isomorfeus/react_view_helper.rb +0 -130
- data/lib/isomorfeus/top_level.rb +0 -86
- data/lib/isomorfeus/top_level_ssr.rb +0 -28
- data/lib/lucid_app/api.rb +0 -30
- data/lib/lucid_app/base.rb +0 -7
- data/lib/lucid_app/context.rb +0 -7
- data/lib/lucid_app/mixin.rb +0 -20
- data/lib/lucid_app/native_component_constructor.rb +0 -105
- data/lib/lucid_component/app_store_defaults.rb +0 -36
- data/lib/lucid_component/app_store_proxy.rb +0 -38
- data/lib/lucid_component/base.rb +0 -7
- data/lib/lucid_component/class_store_proxy.rb +0 -41
- data/lib/lucid_component/component_class_store_defaults.rb +0 -38
- data/lib/lucid_component/component_instance_store_defaults.rb +0 -35
- data/lib/lucid_component/event_handler.rb +0 -17
- data/lib/lucid_component/initializer.rb +0 -12
- data/lib/lucid_component/instance_store_proxy.rb +0 -45
- data/lib/lucid_component/mixin.rb +0 -18
- data/lib/lucid_component/native_component_constructor.rb +0 -116
- data/lib/lucid_component/reducers.rb +0 -48
- data/lib/lucid_component/store_api.rb +0 -38
- data/lib/lucid_component/styles_support.rb +0 -37
- data/lib/lucid_material/app/base.rb +0 -9
- data/lib/lucid_material/app/mixin.rb +0 -22
- data/lib/lucid_material/app/native_component_constructor.rb +0 -107
- data/lib/lucid_material/component/base.rb +0 -9
- data/lib/lucid_material/component/mixin.rb +0 -20
- data/lib/lucid_material/component/native_component_constructor.rb +0 -118
- data/lib/lucid_prop_declaration/mixin.rb +0 -91
- data/lib/react.rb +0 -195
- data/lib/react/active_support_support.rb +0 -13
- data/lib/react/children.rb +0 -35
- data/lib/react/component/api.rb +0 -80
- data/lib/react/component/base.rb +0 -9
- data/lib/react/component/callbacks.rb +0 -106
- data/lib/react/component/elements.rb +0 -60
- data/lib/react/component/event_handler.rb +0 -19
- data/lib/react/component/features.rb +0 -47
- data/lib/react/component/history.rb +0 -36
- data/lib/react/component/initializer.rb +0 -11
- data/lib/react/component/location.rb +0 -15
- data/lib/react/component/match.rb +0 -31
- data/lib/react/component/mixin.rb +0 -19
- data/lib/react/component/native_component_constructor.rb +0 -93
- data/lib/react/component/props.rb +0 -59
- data/lib/react/component/resolution.rb +0 -70
- data/lib/react/component/should_component_update.rb +0 -14
- data/lib/react/component/state.rb +0 -52
- data/lib/react/component/styles.rb +0 -27
- data/lib/react/component/unsafe_api.rb +0 -33
- data/lib/react/context_wrapper.rb +0 -46
- data/lib/react/function_component/api.rb +0 -63
- data/lib/react/function_component/base.rb +0 -9
- data/lib/react/function_component/creator.rb +0 -32
- data/lib/react/function_component/event_handler.rb +0 -13
- data/lib/react/function_component/mixin.rb +0 -14
- data/lib/react/function_component/resolution.rb +0 -62
- data/lib/react/memo_component/base.rb +0 -9
- data/lib/react/memo_component/creator.rb +0 -32
- data/lib/react/memo_component/mixin.rb +0 -14
- data/lib/react/native_constant_wrapper.rb +0 -26
- data/lib/react/pure_component/base.rb +0 -9
- data/lib/react/pure_component/mixin.rb +0 -18
- data/lib/react/ref.rb +0 -13
- data/lib/react/synthetic_event.rb +0 -53
- data/lib/react/version.rb +0 -3
- data/lib/react_dom.rb +0 -47
- data/lib/react_dom_server.rb +0 -19
@@ -1,20 +0,0 @@
|
|
1
|
-
module LucidMaterial
|
2
|
-
module Component
|
3
|
-
module Mixin
|
4
|
-
def self.included(base)
|
5
|
-
base.include(::Native::Wrapper)
|
6
|
-
base.extend(::LucidMaterial::Component::NativeComponentConstructor)
|
7
|
-
base.extend(::LucidPropDeclaration::Mixin)
|
8
|
-
base.extend(::LucidComponent::EventHandler)
|
9
|
-
base.include(::React::Component::Elements)
|
10
|
-
base.include(::React::Component::API)
|
11
|
-
base.include(::React::Component::Callbacks)
|
12
|
-
base.include(::LucidComponent::StoreAPI)
|
13
|
-
base.include(::LucidComponent::StylesSupport)
|
14
|
-
base.include(::LucidComponent::Initializer)
|
15
|
-
base.include(::React::Component::Features)
|
16
|
-
base.include(::React::Component::Resolution)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
module LucidMaterial
|
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
|
-
# language=JS
|
10
|
-
%x{
|
11
|
-
base.lucid_react_component = class extends Opal.global.React.Component {
|
12
|
-
constructor(props) {
|
13
|
-
super(props);
|
14
|
-
if (base.$default_state_defined()) {
|
15
|
-
this.state = base.$state().$to_n();
|
16
|
-
} else {
|
17
|
-
this.state = {};
|
18
|
-
};
|
19
|
-
this.__ruby_instance = base.$new(this);
|
20
|
-
this.__object_id = this.__ruby_instance.$object_id().$to_s();
|
21
|
-
if (!this.state.component_state) {
|
22
|
-
this.state.component_state = {};
|
23
|
-
this.state.component_state[this.__object_id] = {};
|
24
|
-
};
|
25
|
-
var event_handlers = #{base.event_handlers};
|
26
|
-
for (var i = 0; i < event_handlers.length; i++) {
|
27
|
-
this[event_handlers[i]] = this[event_handlers[i]].bind(this);
|
28
|
-
}
|
29
|
-
var defined_refs = #{base.defined_refs};
|
30
|
-
for (var ref in defined_refs) {
|
31
|
-
if (defined_refs[ref] != null) {
|
32
|
-
this[ref] = function(element) {
|
33
|
-
element = Opal.React.native_element_or_component_to_ruby(element);
|
34
|
-
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
|
35
|
-
}
|
36
|
-
this[ref] = this[ref].bind(this);
|
37
|
-
} else {
|
38
|
-
this[ref] = Opal.global.React.createRef();
|
39
|
-
}
|
40
|
-
}
|
41
|
-
}
|
42
|
-
static get displayName() {
|
43
|
-
return #{component_name};
|
44
|
-
}
|
45
|
-
render() {
|
46
|
-
Opal.React.render_buffer.push([]);
|
47
|
-
Opal.React.active_components.push(this);
|
48
|
-
Opal.React.active_redux_components.push(this);
|
49
|
-
#{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
|
50
|
-
Opal.React.active_redux_components.pop();
|
51
|
-
Opal.React.active_components.pop();
|
52
|
-
return Opal.React.render_buffer.pop();
|
53
|
-
}
|
54
|
-
data_access() {
|
55
|
-
return this.context;
|
56
|
-
}
|
57
|
-
shouldComponentUpdate(next_props, next_state) {
|
58
|
-
var next_props_keys = Object.keys(next_props);
|
59
|
-
var this_props_keys = Object.keys(this.props);
|
60
|
-
if (next_props_keys.length !== this_props_keys.length) { return true; }
|
61
|
-
|
62
|
-
var next_state_keys = Object.keys(next_state);
|
63
|
-
var this_state_keys = Object.keys(this.state);
|
64
|
-
if (next_state_keys.length !== this_state_keys.length) { return true; }
|
65
|
-
|
66
|
-
for (var property in next_props) {
|
67
|
-
if (next_props.hasOwnProperty(property)) {
|
68
|
-
if (!this.props.hasOwnProperty(property)) { return true; };
|
69
|
-
if (property == "children") { if (next_props.children !== this.props.children) { return true; }}
|
70
|
-
else if (typeof next_props[property] !== "undefined" && next_props[property] !== null &&
|
71
|
-
typeof next_props[property]['$!='] !== "undefined" &&
|
72
|
-
typeof this.props[property] !== "undefined" && this.props[property] !== null &&
|
73
|
-
typeof this.props[property]['$!='] !== "undefined") {
|
74
|
-
if (#{ !! (`next_props[property]` != `this.props[property]`) }) { return true; };
|
75
|
-
} else if (next_props[property] !== this.props[property]) { return true; };
|
76
|
-
}
|
77
|
-
}
|
78
|
-
for (var property in next_state) {
|
79
|
-
if (next_state.hasOwnProperty(property)) {
|
80
|
-
if (!this.state.hasOwnProperty(property)) { return true; };
|
81
|
-
if (next_state[property] !== null && typeof next_state[property]['$!='] !== "undefined" &&
|
82
|
-
this.state[property] !== null && typeof this.state[property]['$!='] !== "undefined") {
|
83
|
-
if (#{ !! (`next_state[property]` != `this.state[property]`) }) { return true };
|
84
|
-
} else if (next_state[property] !== this.state[property]) { return true };
|
85
|
-
}
|
86
|
-
}
|
87
|
-
return false;
|
88
|
-
}
|
89
|
-
validateProp(props, propName, componentName) {
|
90
|
-
try { base.$validate_prop(propName, props[propName]) }
|
91
|
-
catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
|
92
|
-
return null;
|
93
|
-
}
|
94
|
-
};
|
95
|
-
base.lucid_react_component.contextType = Opal.global.LucidApplicationContext;
|
96
|
-
base.jss_styles = null;
|
97
|
-
base.jss_styles_used = null;
|
98
|
-
base.use_styles = null;
|
99
|
-
base.react_component = function(props) {
|
100
|
-
let classes = null;
|
101
|
-
let theme = Opal.global.MuiStyles.useTheme();
|
102
|
-
if (base.jss_styles) {
|
103
|
-
if (!base.use_styles || (Opal.Isomorfeus["$development?"]() && !Object.is(base.jss_styles, base.jss_styles_used))) {
|
104
|
-
base.jss_styles_used = base.jss_styles;
|
105
|
-
let styles = base.jss_styles
|
106
|
-
if (typeof styles === 'function') { styles = styles(theme); }
|
107
|
-
base.use_styles = Opal.global.MuiStyles.makeStyles(styles);
|
108
|
-
}
|
109
|
-
classes = base.use_styles();
|
110
|
-
}
|
111
|
-
let themed_classes_props = Object.assign({}, props, { classes: classes, theme: theme });
|
112
|
-
return Opal.global.React.createElement(base.lucid_react_component, themed_classes_props);
|
113
|
-
}
|
114
|
-
}
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
module LucidPropDeclaration
|
2
|
-
module Mixin
|
3
|
-
if RUBY_ENGINE == 'opal'
|
4
|
-
def self.extended(base)
|
5
|
-
|
6
|
-
def prop(prop_name, validate_hash = { required: true })
|
7
|
-
validate_hash = validate_hash.to_h if validate_hash.class == Isomorfeus::Props::ValidateHashProxy
|
8
|
-
if validate_hash.key?(:default)
|
9
|
-
%x{
|
10
|
-
if (base.lucid_react_component) {
|
11
|
-
let react_prop_name = Opal.React.lower_camelize(prop_name);
|
12
|
-
#{value = validate_hash[:default]}
|
13
|
-
if (!base.lucid_react_component.defaultProps) { base.lucid_react_component.defaultProps = {}; }
|
14
|
-
base.lucid_react_component.defaultProps[react_prop_name] = value;
|
15
|
-
if (!base.lucid_react_component.propTypes) { base.lucid_react_component.propTypes = {}; }
|
16
|
-
base.lucid_react_component.propTypes[react_prop_name] = base.lucid_react_component.prototype.validateProp;
|
17
|
-
} else if (base.react_component) {
|
18
|
-
let react_prop_name = Opal.React.lower_camelize(prop_name);
|
19
|
-
#{value = validate_hash[:default]}
|
20
|
-
if (!base.react_component.defaultProps) { base.react_component.defaultProps = {}; }
|
21
|
-
base.react_component.defaultProps[react_prop_name] = value;
|
22
|
-
if (!base.react_component.propTypes) { base.react_component.propTypes = {}; }
|
23
|
-
base.react_component.propTypes[react_prop_name] = base.react_component.prototype.validateProp;
|
24
|
-
}
|
25
|
-
}
|
26
|
-
end
|
27
|
-
declared_props[prop_name.to_sym] = validate_hash
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def validate_function
|
32
|
-
%x{
|
33
|
-
if (typeof self.validate_function === 'undefined') {
|
34
|
-
self.validate_function = function(props_object) {
|
35
|
-
try { self.$validate_props(Opal.Hash.$new(props_object)) }
|
36
|
-
catch (e) { return e.message; }
|
37
|
-
}
|
38
|
-
}
|
39
|
-
return self.validate_function;
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
def validate_prop_function(prop)
|
44
|
-
function_name = "validate_#{prop}_function"
|
45
|
-
%x{
|
46
|
-
if (typeof self[function_name] === 'undefined') {
|
47
|
-
self[function_name] = function(value) {
|
48
|
-
try { self.$validate_prop(prop, value); }
|
49
|
-
catch (e) { return e.message; }
|
50
|
-
}
|
51
|
-
}
|
52
|
-
return self[function_name];
|
53
|
-
}
|
54
|
-
end
|
55
|
-
else
|
56
|
-
def prop(prop_name, validate_hash = { required: true })
|
57
|
-
validate_hash = validate_hash.to_h if validate_hash.class == Isomorfeus::Props::ValidateHashProxy
|
58
|
-
declared_props[prop_name.to_sym] = validate_hash
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def declared_props
|
63
|
-
@declared_props ||= {}
|
64
|
-
end
|
65
|
-
|
66
|
-
def validate
|
67
|
-
Isomorfeus::Props::ValidateHashProxy.new
|
68
|
-
end
|
69
|
-
|
70
|
-
def validate_prop(prop, value)
|
71
|
-
return false unless declared_props.key?(prop)
|
72
|
-
validator = Isomorfeus::Props::Validator.new(self, prop, value, declared_props[prop])
|
73
|
-
validator.validate!
|
74
|
-
true
|
75
|
-
end
|
76
|
-
|
77
|
-
def validate_props(props)
|
78
|
-
declared_props.each_key do |prop|
|
79
|
-
if declared_props[prop].key?(:required) && declared_props[prop][:required] && !props.key?(prop)
|
80
|
-
raise "Required prop #{prop} not given!"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
result = true
|
84
|
-
props.each do |p, v|
|
85
|
-
r = validate_prop(p, v)
|
86
|
-
result = false unless r
|
87
|
-
end
|
88
|
-
result
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
data/lib/react.rb
DELETED
@@ -1,195 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
# to_native_react_props: the native_component params is used for event handlers, it keeps the event handlers
|
3
|
-
# it does not need to be compone nt, can be a object with the event handlers
|
4
|
-
# language=JS
|
5
|
-
%x{
|
6
|
-
self.render_buffer = [];
|
7
|
-
|
8
|
-
self.set_validate_prop = function(component, prop_name) {
|
9
|
-
if (typeof component.react_component.propTypes == "undefined") {
|
10
|
-
component.react_component.propTypes = {};
|
11
|
-
component.react_component.propValidations = {};
|
12
|
-
component.react_component.propValidations[prop_name] = {};
|
13
|
-
}
|
14
|
-
component.react_component.propTypes[prop_name] = component.react_component.prototype.validateProp;
|
15
|
-
};
|
16
|
-
|
17
|
-
self.lower_camelize = function(snake_cased_word) {
|
18
|
-
var parts = snake_cased_word.split('_');
|
19
|
-
var res = parts[0];
|
20
|
-
|
21
|
-
for (var i = 1; i < parts.length; i++) {
|
22
|
-
res += parts[i][0].toUpperCase() + parts[i].slice(1);
|
23
|
-
}
|
24
|
-
return res;
|
25
|
-
};
|
26
|
-
|
27
|
-
self.native_element_or_component_to_ruby = function (element) {
|
28
|
-
if (typeof element.__ruby_instance !== 'undefined') { return element.__ruby_instance }
|
29
|
-
if (element instanceof Element || element instanceof Node) { return #{Browser::Element.new(`element`)} }
|
30
|
-
return element;
|
31
|
-
};
|
32
|
-
|
33
|
-
self.to_native_react_props = function(ruby_style_props) {
|
34
|
-
var result = {};
|
35
|
-
var keys = ruby_style_props.$keys();
|
36
|
-
var keys_length = keys.length;
|
37
|
-
for (var i = 0; i < keys_length; i++) {
|
38
|
-
if (keys[i].startsWith("on_")) {
|
39
|
-
var handler = ruby_style_props['$[]'](keys[i]);
|
40
|
-
if (typeof handler === "function") {
|
41
|
-
result[Opal.React.lower_camelize(keys[i])] = handler;
|
42
|
-
} else {
|
43
|
-
var active_component = Opal.React.active_component();
|
44
|
-
result[Opal.React.lower_camelize(keys[i])] = active_component[handler];
|
45
|
-
}
|
46
|
-
} else if (keys[i].startsWith("aria_")) {
|
47
|
-
result[keys[i].replace("_", "-")] = ruby_style_props['$[]'](keys[i]);
|
48
|
-
} else if (keys[i] === "style") {
|
49
|
-
var val = ruby_style_props['$[]'](keys[i]);
|
50
|
-
if (typeof val.$$is_hash !== "undefined") { val = val.$to_n() }
|
51
|
-
result["style"] = val;
|
52
|
-
} else {
|
53
|
-
result[Opal.React.lower_camelize(keys[i])] = ruby_style_props['$[]'](keys[i]);
|
54
|
-
}
|
55
|
-
}
|
56
|
-
return result;
|
57
|
-
};
|
58
|
-
|
59
|
-
self.internal_prepare_args_and_render = function(component, args, block) {
|
60
|
-
if (args.length > 0) {
|
61
|
-
var last_arg = args[args.length - 1];
|
62
|
-
if (typeof last_arg === 'string' || last_arg instanceof String) {
|
63
|
-
if (args.length === 1) { return Opal.React.internal_render(component, null, last_arg, null); }
|
64
|
-
else { return Opal.React.internal_render(component, args[0], last_arg, null); }
|
65
|
-
} else { return Opal.React.internal_render(component, args[0], null, block); }
|
66
|
-
} else { return Opal.React.internal_render(component, null, null, block); }
|
67
|
-
};
|
68
|
-
|
69
|
-
self.internal_render = function(component, props, string_child, block) {
|
70
|
-
let children;
|
71
|
-
let react_element;
|
72
|
-
let native_props = null;
|
73
|
-
|
74
|
-
if (string_child) {
|
75
|
-
children = string_child;
|
76
|
-
} else if (block && block !== nil) {
|
77
|
-
Opal.React.render_buffer.push([]);
|
78
|
-
let block_result = block.$call();
|
79
|
-
let last_buffer_length = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].length;
|
80
|
-
let last_buffer_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1][last_buffer_length - 1];
|
81
|
-
if (block_result && block_result !== last_buffer_element && (block_result !== nil && (typeof block_result === "string" || typeof block_result.$$typeof === "symbol" ||
|
82
|
-
(typeof block_result.constructor !== "undefined" && block_result.constructor === Array && block_result[0] && typeof block_result[0].$$typeof === "symbol")
|
83
|
-
))) {
|
84
|
-
Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(block_result);
|
85
|
-
}
|
86
|
-
children = Opal.React.render_buffer.pop();
|
87
|
-
if (children.length == 1) { children = children[0]; }
|
88
|
-
else if (children.length == 0) { children = null; }
|
89
|
-
}
|
90
|
-
if (props && props !== nil) { native_props = Opal.React.to_native_react_props(props); }
|
91
|
-
react_element = Opal.global.React.createElement(component, native_props, children);
|
92
|
-
Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(react_element);
|
93
|
-
return react_element;
|
94
|
-
};
|
95
|
-
|
96
|
-
self.active_components = [];
|
97
|
-
|
98
|
-
self.active_component = function() {
|
99
|
-
var length = Opal.React.active_components.length;
|
100
|
-
if (length === 0) { return null; };
|
101
|
-
return Opal.React.active_components[length-1];
|
102
|
-
};
|
103
|
-
|
104
|
-
self.active_redux_components = [];
|
105
|
-
|
106
|
-
self.active_redux_component = function() {
|
107
|
-
var length = Opal.React.active_redux_components.length;
|
108
|
-
if (length === 0) { return null; };
|
109
|
-
return Opal.React.active_redux_components[length-1];
|
110
|
-
};
|
111
|
-
}
|
112
|
-
|
113
|
-
def self.clone_element(ruby_react_element, props = nil, children = nil, &block)
|
114
|
-
block_result = `null`
|
115
|
-
if block_given?
|
116
|
-
block_result = block.call
|
117
|
-
block_result = `null` unless block_result
|
118
|
-
end
|
119
|
-
native_props = props ? `Opal.React.to_native_react_props(props)` : `null`
|
120
|
-
`Opal.global.React.cloneElement(ruby_react_element.$to_n(), native_props, block_result)`
|
121
|
-
end
|
122
|
-
|
123
|
-
def self.create_context(const_name, default_value)
|
124
|
-
%x{
|
125
|
-
Opal.global[const_name] = Opal.global.React.createContext(default_value);
|
126
|
-
var new_const = #{React::ContextWrapper.new(`Opal.global[const_name]`)};
|
127
|
-
#{Object.const_set(const_name, `new_const`)};
|
128
|
-
return new_const;
|
129
|
-
}
|
130
|
-
end
|
131
|
-
|
132
|
-
def self.create_element(type, props = nil, children = nil, &block)
|
133
|
-
%x{
|
134
|
-
let component = null;
|
135
|
-
let native_props = null;
|
136
|
-
if (typeof type.react_component !== 'undefined') {
|
137
|
-
component = type.react_component;
|
138
|
-
} else {
|
139
|
-
component = type;
|
140
|
-
}
|
141
|
-
|
142
|
-
Opal.React.render_buffer.push([]);
|
143
|
-
if (block !== nil) {
|
144
|
-
let block_result = block.$call()
|
145
|
-
let last_buffer_length = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].length;
|
146
|
-
let last_buffer_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1][last_buffer_length - 1];
|
147
|
-
if (block_result && block_result !== last_buffer_element && (block_result !== nil && (typeof block_result === "string" || typeof block_result.$$typeof === "symbol" ||
|
148
|
-
(typeof block_result.constructor !== "undefined" && block_result.constructor === Array && block_result[0] && typeof block_result[0].$$typeof === "symbol")
|
149
|
-
))) {
|
150
|
-
Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(block_result);
|
151
|
-
}
|
152
|
-
children = Opal.React.render_buffer.pop()
|
153
|
-
if (children.length == 1) { children = children[0]; }
|
154
|
-
else if (children.length == 0) { children = null; }
|
155
|
-
}
|
156
|
-
if (props && props !== nil) { native_props = Opal.React.to_native_react_props(props); }
|
157
|
-
return Opal.global.React.createElement(component, native_props, children);
|
158
|
-
}
|
159
|
-
end
|
160
|
-
|
161
|
-
def self.create_factory(type)
|
162
|
-
native_function = `Opal.global.React.createFactory(type)`
|
163
|
-
proc { `native_function.call()` }
|
164
|
-
end
|
165
|
-
|
166
|
-
def self.create_ref
|
167
|
-
React::Ref.new(`Opal.global.React.createRef()`)
|
168
|
-
end
|
169
|
-
|
170
|
-
def self.forwardRef(&block)
|
171
|
-
# TODO whats the return here? A React:Element?, doc says a React node, whats that?
|
172
|
-
`Opal.global.React.forwardRef( function(props, ref) { return block.$call().$to_n(); })`
|
173
|
-
end
|
174
|
-
|
175
|
-
def self.is_valid_element(react_element)
|
176
|
-
`Opal.global.React.isValidElement(react_element)`
|
177
|
-
end
|
178
|
-
|
179
|
-
def self.lazy(import_statement_function)
|
180
|
-
`Opal.global.React.lazy(import_statement_function)`
|
181
|
-
end
|
182
|
-
|
183
|
-
def self.memo(function_component, &block)
|
184
|
-
if block_given?
|
185
|
-
%x{
|
186
|
-
var fun = function(prev_props, next_props) {
|
187
|
-
return #{block.call(::React::Component::Props.new(`{props: prev_props}`), ::React::Component::Props.new(`{props: next_props}`))};
|
188
|
-
}
|
189
|
-
return Opal.global.React.memo(function_component, fun);
|
190
|
-
}
|
191
|
-
else
|
192
|
-
`Opal.global.React.memo(function_component)`
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|