isomorfeus-react 16.9.24 → 16.10.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,19 +0,0 @@
|
|
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
|
-
base.extend(::React::Component::ShouldComponentUpdate)
|
9
|
-
base.extend(::React::Component::EventHandler)
|
10
|
-
base.include(::React::Component::Elements)
|
11
|
-
base.include(::React::Component::API)
|
12
|
-
base.include(::React::Component::Callbacks)
|
13
|
-
base.include(::React::Component::Initializer)
|
14
|
-
base.include(::React::Component::Features)
|
15
|
-
base.include(::React::Component::Resolution)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,93 +0,0 @@
|
|
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
|
-
# language=JS
|
10
|
-
%x{
|
11
|
-
base.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
|
-
var event_handlers = #{base.event_handlers};
|
21
|
-
for (var i = 0; i < event_handlers.length; i++) {
|
22
|
-
this[event_handlers[i]] = this[event_handlers[i]].bind(this);
|
23
|
-
}
|
24
|
-
var defined_refs = #{base.defined_refs};
|
25
|
-
for (var ref in defined_refs) {
|
26
|
-
if (defined_refs[ref] != null) {
|
27
|
-
this[ref] = function(element) {
|
28
|
-
element = Opal.React.native_element_or_component_to_ruby(element);
|
29
|
-
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
|
30
|
-
}
|
31
|
-
this[ref] = this[ref].bind(this);
|
32
|
-
} else {
|
33
|
-
this[ref] = Opal.global.React.createRef();
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
static get displayName() {
|
38
|
-
return #{component_name};
|
39
|
-
}
|
40
|
-
render() {
|
41
|
-
Opal.React.render_buffer.push([]);
|
42
|
-
Opal.React.active_components.push(this);
|
43
|
-
#{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
|
44
|
-
Opal.React.active_components.pop();
|
45
|
-
return Opal.React.render_buffer.pop();
|
46
|
-
}
|
47
|
-
shouldComponentUpdate(next_props, next_state) {
|
48
|
-
if (base.has_custom_should_component_update) {
|
49
|
-
return this.__ruby_instance["$should_component_update"](#{(Hash.new(next_props))}, #{Hash.new(next_state)});
|
50
|
-
} else {
|
51
|
-
var next_props_keys = Object.keys(next_props);
|
52
|
-
var this_props_keys = Object.keys(this.props);
|
53
|
-
if (next_props_keys.length !== this_props_keys.length) { return true; }
|
54
|
-
|
55
|
-
var next_state_keys = Object.keys(next_state);
|
56
|
-
var this_state_keys = Object.keys(this.state);
|
57
|
-
if (next_state_keys.length !== this_state_keys.length) { return true; }
|
58
|
-
|
59
|
-
for (var property in next_props) {
|
60
|
-
if (next_props.hasOwnProperty(property)) {
|
61
|
-
if (!this.props.hasOwnProperty(property)) { return true; };
|
62
|
-
if (property == "children") { if (next_props.children !== this.props.children) { return true; }}
|
63
|
-
else if (typeof next_props[property] !== "undefined" && next_props[property] !== null &&
|
64
|
-
typeof next_props[property]['$!='] !== "undefined" &&
|
65
|
-
typeof this.props[property] !== "undefined" && this.props[property] !== null &&
|
66
|
-
typeof this.props[property]['$!='] !== "undefined") {
|
67
|
-
if (#{ !! (`next_props[property]` != `this.props[property]`) }) { return true; };
|
68
|
-
} else if (next_props[property] !== this.props[property]) { return true; };
|
69
|
-
}
|
70
|
-
}
|
71
|
-
for (var property in next_state) {
|
72
|
-
if (next_state.hasOwnProperty(property)) {
|
73
|
-
if (!this.state.hasOwnProperty(property)) { return true; };
|
74
|
-
if (next_state[property] !== null && typeof next_state[property]['$!='] !== "undefined" &&
|
75
|
-
this.state[property] !== null && typeof this.state[property]['$!='] !== "undefined") {
|
76
|
-
if (#{ !! (`next_state[property]` != `this.state[property]`) }) { return true };
|
77
|
-
} else if (next_state[property] !== this.state[property]) { return true };
|
78
|
-
}
|
79
|
-
}
|
80
|
-
return false;
|
81
|
-
}
|
82
|
-
}
|
83
|
-
validateProp(props, propName, componentName) {
|
84
|
-
try { base.$validate_prop(propName, props[propName]) }
|
85
|
-
catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
|
86
|
-
return null;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
}
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module Component
|
3
|
-
class Props
|
4
|
-
include ::Native::Wrapper
|
5
|
-
|
6
|
-
def method_missing(prop, *args, &block)
|
7
|
-
%x{
|
8
|
-
var prop_name = Opal.React.lower_camelize(prop);
|
9
|
-
if (typeof #@native.props[prop_name] === 'undefined') { return #{nil}; }
|
10
|
-
return #@native.props[prop_name];
|
11
|
-
}
|
12
|
-
end
|
13
|
-
|
14
|
-
def classes
|
15
|
-
@classes ||= `Opal.React.Component.Styles.$new(#@native.props.classes)`
|
16
|
-
end
|
17
|
-
|
18
|
-
def theme
|
19
|
-
@theme ||= `Opal.React.Component.Styles.$new(#@native.props.theme)`
|
20
|
-
end
|
21
|
-
|
22
|
-
def isomorfeus_store
|
23
|
-
@native.JS[:props].JS[:isomorfeus_store]
|
24
|
-
end
|
25
|
-
|
26
|
-
# for router convenience
|
27
|
-
def history
|
28
|
-
return nil unless @native.JS[:props].JS[:history]
|
29
|
-
if @native.JS[:props].JS[:history].JS[:pathname]
|
30
|
-
React::Component::History.new(@native.JS[:props].JS[:history])
|
31
|
-
else
|
32
|
-
@native.JS[:props].JS[:history]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def location
|
37
|
-
return nil unless @native.JS[:props].JS[:location]
|
38
|
-
if @native.JS[:props].JS[:location].JS[:pathname]
|
39
|
-
React::Component::Location.new(@native.JS[:props].JS[:location])
|
40
|
-
else
|
41
|
-
@native.JS[:props].JS[:location]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def match
|
46
|
-
return nil unless @native.JS[:props].JS[:match]
|
47
|
-
if @native.JS[:props].JS[:match].JS[:path]
|
48
|
-
React::Component::Match.new(@native.JS[:props].JS[:match])
|
49
|
-
else
|
50
|
-
@native.JS[:props].JS[:match]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def to_n
|
55
|
-
@native.JS[:props]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module Component
|
3
|
-
module Resolution
|
4
|
-
def self.included(base)
|
5
|
-
base.instance_exec do
|
6
|
-
alias _react_component_resolution_original_const_missing const_missing
|
7
|
-
|
8
|
-
def const_missing(const_name)
|
9
|
-
# language=JS
|
10
|
-
%x{
|
11
|
-
if (typeof Opal.global[const_name] === "object") {
|
12
|
-
var new_const = #{React::NativeConstantWrapper.new(`Opal.global[const_name]`, const_name)};
|
13
|
-
#{Object.const_set(const_name, `new_const`)};
|
14
|
-
return new_const;
|
15
|
-
} else {
|
16
|
-
return #{_react_component_resolution_original_const_missing(const_name)};
|
17
|
-
}
|
18
|
-
}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
alias _react_component_resolution_original_method_missing method_missing
|
25
|
-
|
26
|
-
def method_missing(component_name, *args, &block)
|
27
|
-
# html tags are defined as methods, so they will not end up here.
|
28
|
-
# first check for native component and render it, we want to be fast for native components
|
29
|
-
# second check for ruby component and render it, they are a bit slower anyway
|
30
|
-
# third pass on method missing
|
31
|
-
# language=JS
|
32
|
-
%x{
|
33
|
-
var component = null;
|
34
|
-
var component_type = typeof Opal.global[component_name];
|
35
|
-
if (component_type === "function" || component_type === "object") {
|
36
|
-
component = Opal.global[component_name];
|
37
|
-
} else {
|
38
|
-
var modules = self.$class().$to_s().split("::");
|
39
|
-
var modules_length = modules.length - 1;
|
40
|
-
var module;
|
41
|
-
var constant;
|
42
|
-
for (var i = modules_length; i > 0; i--) {
|
43
|
-
try {
|
44
|
-
module = modules.slice(0, i).join('::')
|
45
|
-
constant = self.$class().$const_get(module).$const_get(component_name, false);
|
46
|
-
if (typeof constant.react_component !== 'undefined') {
|
47
|
-
component = constant.react_component;
|
48
|
-
break;
|
49
|
-
}
|
50
|
-
} catch(err) { component = null; }
|
51
|
-
}
|
52
|
-
if (!component) {
|
53
|
-
try {
|
54
|
-
constant = Opal.Object.$const_get(component_name);
|
55
|
-
if (typeof constant.react_component !== 'undefined') {
|
56
|
-
component = constant.react_component;
|
57
|
-
}
|
58
|
-
} catch(err) { component = null; }
|
59
|
-
}
|
60
|
-
}
|
61
|
-
if (component) {
|
62
|
-
return Opal.React.internal_prepare_args_and_render(component, args, block);
|
63
|
-
} else {
|
64
|
-
return #{_react_component_resolution_original_method_missing(component_name, *args, block)};
|
65
|
-
}
|
66
|
-
}
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module Component
|
3
|
-
module ShouldComponentUpdate
|
4
|
-
def self.extended(base)
|
5
|
-
base.define_singleton_method(:should_component_update?) do |&block|
|
6
|
-
`base.has_custom_should_component_update = true`
|
7
|
-
define_method(:should_component_update) do |next_props, next_state|
|
8
|
-
!!block.call(Hash.new(next_props), Hash.new(next_state))
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module Component
|
3
|
-
class State
|
4
|
-
include ::Native::Wrapper
|
5
|
-
|
6
|
-
def method_missing(key, *args, &block)
|
7
|
-
if `args.length > 0`
|
8
|
-
new_state = `{}`
|
9
|
-
new_state.JS[(`key.endsWith('=')` ? key.chop : key)] = args[0]
|
10
|
-
if block_given?
|
11
|
-
@native.JS.setState(new_state, `function() { block.$call(); }`)
|
12
|
-
else
|
13
|
-
@native.JS.setState(new_state, `null`)
|
14
|
-
end
|
15
|
-
else
|
16
|
-
return nil if `typeof #@native.state[key] == "undefined"`
|
17
|
-
@native.JS[:state].JS[key]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def set_state(updater, &block)
|
22
|
-
new_state = `{}`
|
23
|
-
updater.keys.each do |key|
|
24
|
-
new_state.JS[key] = updater[key]
|
25
|
-
end
|
26
|
-
if block_given?
|
27
|
-
@native.JS.setState(new_state, `function() { block.$call(); }`)
|
28
|
-
else
|
29
|
-
@native.JS.setState(new_state, `null`)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def size
|
34
|
-
`Object.keys(#@native.state).length`;
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_n
|
38
|
-
%x{
|
39
|
-
var new_native = {};
|
40
|
-
for (var key in #@native.state) {
|
41
|
-
if (typeof #@native.state[key].$to_n !== "undefined") {
|
42
|
-
new_native[key] = #@native.state[key].$to_n();
|
43
|
-
} else {
|
44
|
-
new_native[key] = #@native.state[key];
|
45
|
-
}
|
46
|
-
}
|
47
|
-
return new_native;
|
48
|
-
}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module Component
|
3
|
-
class Styles
|
4
|
-
def initialize(native)
|
5
|
-
@native = native
|
6
|
-
end
|
7
|
-
|
8
|
-
def method_missing(prop, *args, &block)
|
9
|
-
%x{
|
10
|
-
if (!#@native || typeof #@native[prop] === 'undefined') { return #{nil}; }
|
11
|
-
let value = #@native[prop];
|
12
|
-
if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value)) { return value; }
|
13
|
-
if (typeof value === 'function') { return #{Proc.new { `value()` }} }
|
14
|
-
return Opal.React.Component.Styles.$new(value);
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_h
|
19
|
-
`Opal.Hash.$new(#@native)`
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_n
|
23
|
-
@native
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module Component
|
3
|
-
module UnsafeAPI
|
4
|
-
def self.included(base)
|
5
|
-
base.instance_exec do
|
6
|
-
def unsafe_component_will_mount(&block)
|
7
|
-
%x{
|
8
|
-
self.react_component.prototype.UNSAFE_componentWillMount = function() {
|
9
|
-
return #{`this.__ruby_instance`.instance_exec(&block)};
|
10
|
-
}
|
11
|
-
}
|
12
|
-
end
|
13
|
-
|
14
|
-
def unsafe_component_will_receive_props(&block)
|
15
|
-
%x{
|
16
|
-
self.react_component.prototype.UNSAFE_componentWillReceiveProps = function(next_props) {
|
17
|
-
return #{`this.__ruby_instance`.instance_exec(React::Component::Props.new(`{props: next_props}`), &block)};
|
18
|
-
}
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
def unsafe_component_will_update(&block)
|
23
|
-
%x{
|
24
|
-
self.react_component.prototype.UNSAFE_componentWillUpdate = function(next_props, next_state) {
|
25
|
-
return #{`this.__ruby_instance`.instance_exec(React::Component::Props.new(`{props: next_props}`), `Opal.Hash.$new(next_state)`, &block)};
|
26
|
-
}
|
27
|
-
}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
class ContextWrapper
|
3
|
-
include ::Native::Wrapper
|
4
|
-
|
5
|
-
def is_wrapped_context
|
6
|
-
true
|
7
|
-
end
|
8
|
-
|
9
|
-
def Consumer(*args, &block)
|
10
|
-
%x{
|
11
|
-
let children = null;
|
12
|
-
let props = null;
|
13
|
-
|
14
|
-
if (args.length > 0) { props = Opal.React.to_native_react_props(args[0]); }
|
15
|
-
|
16
|
-
let react_element = Opal.global.React.createElement(this.native.Consumer, props, function(value) {
|
17
|
-
if (block !== nil) {
|
18
|
-
Opal.React.render_buffer.push([]);
|
19
|
-
let block_result = block.$call();
|
20
|
-
let last_buffer_length = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].length;
|
21
|
-
let last_buffer_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1][last_buffer_length - 1];
|
22
|
-
if (block_result && block_result !== last_buffer_element && (block_result !== nil && (typeof block_result === "string" || typeof block_result.$$typeof === "symbol" ||
|
23
|
-
(typeof block_result.constructor !== "undefined" && block_result.constructor === Array && block_result[0] && typeof block_result[0].$$typeof === "symbol")
|
24
|
-
))) {
|
25
|
-
Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(block_result);
|
26
|
-
}
|
27
|
-
children = Opal.React.render_buffer.pop();
|
28
|
-
if (children.length == 1) { children = children[0]; }
|
29
|
-
else if (children.length == 0) { children = null; }
|
30
|
-
}
|
31
|
-
return Opal.React.render_buffer.pop();
|
32
|
-
});
|
33
|
-
Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(react_element);
|
34
|
-
return null;
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def Provider(*args, &block)
|
39
|
-
%x{
|
40
|
-
var props = null;
|
41
|
-
if (args.length > 0) { props = Opal.React.to_native_react_props(args[0]); }
|
42
|
-
Opal.React.internal_render(this.native.Provider, props, null, block);
|
43
|
-
}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module FunctionComponent
|
3
|
-
module API
|
4
|
-
attr_accessor :props
|
5
|
-
|
6
|
-
def initialize(props)
|
7
|
-
@props = ::React::Component::Props.new(`{props: props}`)
|
8
|
-
end
|
9
|
-
|
10
|
-
def use_callback(deps, &block)
|
11
|
-
`Opal.global.React.useCallback(function() { #{block.call} }, deps)`
|
12
|
-
end
|
13
|
-
|
14
|
-
def use_context(context)
|
15
|
-
`(typeof context.$is_wrapped_context !== 'undefined')` ? context.to_n : context
|
16
|
-
`Opal.global.React.useContext(native_context)`
|
17
|
-
end
|
18
|
-
|
19
|
-
def use_debug_value(value)
|
20
|
-
`Opal.global.React.useDebugValue(value)`
|
21
|
-
end
|
22
|
-
|
23
|
-
def use_effect(&block)
|
24
|
-
`Opal.global.React.useEffect(function() { #{block.call} })`
|
25
|
-
end
|
26
|
-
|
27
|
-
def use_imperative_handle(ref, *deps, &block)
|
28
|
-
native_ref = `(typeof ref.$is_wrapped_ref !== 'undefined')` ? ref.to_n : ref
|
29
|
-
`Opal.global.React.useImperativeHandle(native_ref, function() { #{block.call} }, deps)`
|
30
|
-
end
|
31
|
-
|
32
|
-
def use_layout_effect(&block)
|
33
|
-
`Opal.global.React.useLayoutEffect(function() { #{block.call} })`
|
34
|
-
end
|
35
|
-
|
36
|
-
def use_memo(*deps, &block)
|
37
|
-
`Opal.global.React.useMemo(function() { #{block.call} }, deps)`
|
38
|
-
end
|
39
|
-
|
40
|
-
def use_reducer(inital_state, &block)
|
41
|
-
state = nil
|
42
|
-
dispatcher = nil
|
43
|
-
%x{
|
44
|
-
[state, dispatcher] = Opal.global.React.useReducer(function(state, action) {
|
45
|
-
#{block.call(state, action)}
|
46
|
-
}, initial_state);
|
47
|
-
}
|
48
|
-
[state, proc { |arg| `dispatcher(arg)` }]
|
49
|
-
end
|
50
|
-
|
51
|
-
def use_ref(initial_value)
|
52
|
-
React::Ref.new(`Opal.global.React.useRef(initial_value)`)
|
53
|
-
end
|
54
|
-
|
55
|
-
def use_state(initial_value)
|
56
|
-
initial = nil
|
57
|
-
setter = nil
|
58
|
-
`[initial, setter] = Opal.global.React.useState(initial_value);`
|
59
|
-
[initial, proc { |arg| `setter(arg)` }]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|