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,48 +1,48 @@
|
|
1
|
-
module React
|
2
|
-
module Component
|
3
|
-
module Features
|
4
|
-
def Fragment(*args, &block)
|
5
|
-
`Opal.React.internal_prepare_args_and_render(Opal.global.React.Fragment, args, block)`
|
6
|
-
end
|
7
|
-
|
8
|
-
def Portal(element_or_query, &block)
|
9
|
-
if `(typeof element_or_query === 'string')` || (`(typeof element_or_query.$class === 'function')` && element_or_query.class == String)
|
10
|
-
element = `document.body.querySelector(element_or_query)`
|
11
|
-
elsif `(typeof element_or_query.$is_a === 'function')` && element_or_query.is_a?(Browser::Element)
|
12
|
-
element = element_or_query.to_n
|
13
|
-
else
|
14
|
-
element = element_or_query
|
15
|
-
end
|
16
|
-
%x{
|
17
|
-
let operabu = Opal.React.render_buffer;
|
18
|
-
operabu.push([]);
|
19
|
-
// console.log("portal pushed", operabu, operabu.toString());
|
20
|
-
if (block !== nil) {
|
21
|
-
let block_result = block.$call()
|
22
|
-
let last_buffer_length = operabu[operabu.length - 1].length;
|
23
|
-
let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
|
24
|
-
if (block_result && block_result !== nil) { Opal.React.render_block_result(block_result); }
|
25
|
-
}
|
26
|
-
// console.log("portal popping", operabu, operabu.toString());
|
27
|
-
let result = operabu.pop();
|
28
|
-
if (result.length === 1) { result = result[0]; }
|
29
|
-
var react_element = Opal.global.React.createPortal(result, element);
|
30
|
-
operabu[operabu.length - 1].push(react_element);
|
31
|
-
// console.log("portal pushed", operabu, operabu.toString());
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
def Profiler(*args, &block)
|
36
|
-
`Opal.React.internal_prepare_args_and_render(Opal.global.React.Profiler, args, block)`
|
37
|
-
end
|
38
|
-
|
39
|
-
def StrictMode(*args, &block)
|
40
|
-
`Opal.React.internal_prepare_args_and_render(Opal.global.React.StrictMode, args, block)`
|
41
|
-
end
|
42
|
-
|
43
|
-
def Suspense(*args, &block)
|
44
|
-
`Opal.React.internal_prepare_args_and_render(Opal.global.React.Suspense, args, block)`
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
1
|
+
module React
|
2
|
+
module Component
|
3
|
+
module Features
|
4
|
+
def Fragment(*args, &block)
|
5
|
+
`Opal.React.internal_prepare_args_and_render(Opal.global.React.Fragment, args, block)`
|
6
|
+
end
|
7
|
+
|
8
|
+
def Portal(element_or_query, &block)
|
9
|
+
if `(typeof element_or_query === 'string')` || (`(typeof element_or_query.$class === 'function')` && element_or_query.class == String)
|
10
|
+
element = `document.body.querySelector(element_or_query)`
|
11
|
+
elsif `(typeof element_or_query.$is_a === 'function')` && element_or_query.is_a?(Browser::Element)
|
12
|
+
element = element_or_query.to_n
|
13
|
+
else
|
14
|
+
element = element_or_query
|
15
|
+
end
|
16
|
+
%x{
|
17
|
+
let operabu = Opal.React.render_buffer;
|
18
|
+
operabu.push([]);
|
19
|
+
// console.log("portal pushed", operabu, operabu.toString());
|
20
|
+
if (block !== nil) {
|
21
|
+
let block_result = block.$call()
|
22
|
+
let last_buffer_length = operabu[operabu.length - 1].length;
|
23
|
+
let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
|
24
|
+
if (block_result && block_result !== nil) { Opal.React.render_block_result(block_result); }
|
25
|
+
}
|
26
|
+
// console.log("portal popping", operabu, operabu.toString());
|
27
|
+
let result = operabu.pop();
|
28
|
+
if (result.length === 1) { result = result[0]; }
|
29
|
+
var react_element = Opal.global.React.createPortal(result, element);
|
30
|
+
operabu[operabu.length - 1].push(react_element);
|
31
|
+
// console.log("portal pushed", operabu, operabu.toString());
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def Profiler(*args, &block)
|
36
|
+
`Opal.React.internal_prepare_args_and_render(Opal.global.React.Profiler, args, block)`
|
37
|
+
end
|
38
|
+
|
39
|
+
def StrictMode(*args, &block)
|
40
|
+
`Opal.React.internal_prepare_args_and_render(Opal.global.React.StrictMode, args, block)`
|
41
|
+
end
|
42
|
+
|
43
|
+
def Suspense(*args, &block)
|
44
|
+
`Opal.React.internal_prepare_args_and_render(Opal.global.React.Suspense, args, block)`
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,65 +1,69 @@
|
|
1
|
-
module React
|
2
|
-
module Component
|
3
|
-
class History
|
4
|
-
include ::Native::Wrapper
|
5
|
-
|
6
|
-
def
|
7
|
-
@native
|
8
|
-
end
|
9
|
-
|
10
|
-
def
|
11
|
-
@native.JS[:props].JS[:history].JS.
|
12
|
-
end
|
13
|
-
|
14
|
-
def
|
15
|
-
@native.JS[:props].JS[:history].JS.
|
16
|
-
end
|
17
|
-
|
18
|
-
def
|
19
|
-
@native.JS[:props].JS[:history].JS.
|
20
|
-
end
|
21
|
-
|
22
|
-
def
|
23
|
-
@native.JS[:props].JS[:history].JS.
|
24
|
-
end
|
25
|
-
|
26
|
-
def
|
27
|
-
@native.JS[:props].JS[:history].JS.
|
28
|
-
end
|
29
|
-
|
30
|
-
def
|
31
|
-
@native.JS[:props].JS[:history].JS.
|
32
|
-
end
|
33
|
-
|
34
|
-
def
|
35
|
-
@native.JS[:props].JS[:history].JS
|
36
|
-
end
|
37
|
-
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
|
1
|
+
module React
|
2
|
+
module Component
|
3
|
+
class History
|
4
|
+
include ::Native::Wrapper
|
5
|
+
|
6
|
+
def initialize(native)
|
7
|
+
@native = native
|
8
|
+
end
|
9
|
+
|
10
|
+
def block(prompt)
|
11
|
+
@native.JS[:props].JS[:history].JS.block(prompt)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_href(location)
|
15
|
+
@native.JS[:props].JS[:history].JS.createHref(location)
|
16
|
+
end
|
17
|
+
|
18
|
+
def go(n)
|
19
|
+
@native.JS[:props].JS[:history].JS.go(n)
|
20
|
+
end
|
21
|
+
|
22
|
+
def go_back
|
23
|
+
@native.JS[:props].JS[:history].JS.goBack()
|
24
|
+
end
|
25
|
+
|
26
|
+
def go_forward
|
27
|
+
@native.JS[:props].JS[:history].JS.goForward()
|
28
|
+
end
|
29
|
+
|
30
|
+
def push(*args)
|
31
|
+
@native.JS[:props].JS[:history].JS.push(*args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def replace(*args)
|
35
|
+
@native.JS[:props].JS[:history].JS.replace(*args)
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing(prop, *args, &block)
|
39
|
+
@native.JS[:props].JS[:history].JS[prop]
|
40
|
+
end
|
41
|
+
|
42
|
+
def listen(&block)
|
43
|
+
fun = nil
|
44
|
+
%x{
|
45
|
+
fun = function(location, action) {
|
46
|
+
let ruby_location = #{React::Component::Location.new(`{ props: { location: location }}`)}
|
47
|
+
block.$call(ruby_location, action);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
unlisten = @native.JS[:props].JS[:history].JS.listen(fun)
|
51
|
+
-> { unlisten.JS.call() }
|
52
|
+
end
|
53
|
+
|
54
|
+
def location
|
55
|
+
return @location if @location
|
56
|
+
return nil unless @native.JS[:props].JS[:history].JS[:location]
|
57
|
+
if @native.JS[:props].JS[:history].JS[:location].JS[:pathname]
|
58
|
+
@location = React::Component::Location.new(@native)
|
59
|
+
else
|
60
|
+
@native.JS[:props].JS[:history].JS[:location]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_n
|
65
|
+
@native.JS[:props].JS[:history]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module React
|
2
|
-
module Component
|
3
|
-
module Initializer
|
4
|
-
def initialize(native_component)
|
5
|
-
@native = native_component
|
6
|
-
@props = `Opal.React.Component.Props.$new(#@native)`
|
7
|
-
@state = `Opal.React.Component.State.$new(#@native)`
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module React
|
2
|
+
module Component
|
3
|
+
module Initializer
|
4
|
+
def initialize(native_component)
|
5
|
+
@native = native_component
|
6
|
+
@props = `Opal.React.Component.Props.$new(#@native)`
|
7
|
+
@state = `Opal.React.Component.State.$new(#@native)`
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,15 +1,19 @@
|
|
1
|
-
module React
|
2
|
-
module Component
|
3
|
-
class Location
|
4
|
-
include ::Native::Wrapper
|
5
|
-
|
6
|
-
def
|
7
|
-
@native
|
8
|
-
end
|
9
|
-
|
10
|
-
def
|
11
|
-
@native
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
module React
|
2
|
+
module Component
|
3
|
+
class Location
|
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[:location].JS[prop]
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_n
|
15
|
+
@native
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -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,95 +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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
counter = 0;
|
71
|
-
const this_state = this.state;
|
72
|
-
for (var property in next_state) {
|
73
|
-
counter++;
|
74
|
-
if (next_state.hasOwnProperty(property)) {
|
75
|
-
if (!this_state.hasOwnProperty(property)) { return true; };
|
76
|
-
if (typeof next_state[property] === "object" && next_state[property] !== null && typeof next_state[property]['$!='] === "function" &&
|
77
|
-
typeof this_state[property] !== "undefined" && this_state[property] !== null) {
|
78
|
-
if (#{ !! (`next_state[property]` != `this_state[property]`) }) { return true }
|
79
|
-
} else if (next_state[property] !== this_state[property]) { return true }
|
80
|
-
}
|
81
|
-
}
|
82
|
-
if (counter !== Object.keys(this_state).length) { return true; }
|
83
|
-
return false;
|
84
|
-
}
|
85
|
-
validateProp(props, propName, componentName) {
|
86
|
-
try { base.$validate_prop(propName, props[propName]) }
|
87
|
-
catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
|
88
|
-
return null;
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
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
|