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,44 +1,44 @@
|
|
|
1
|
-
module LucidComponent
|
|
2
|
-
class ClassStoreProxy
|
|
3
|
-
def initialize(component_name, component_instance = nil, native = nil)
|
|
4
|
-
@component_name = component_name
|
|
5
|
-
if component_instance
|
|
6
|
-
@native = native
|
|
7
|
-
@component_instance = component_instance
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def [](key)
|
|
12
|
-
method_missing(key)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def []=(key, value)
|
|
16
|
-
method_missing(key, value)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def method_missing(key, *args, &block)
|
|
20
|
-
if `args.length > 0`
|
|
21
|
-
# set class state, simply a dispatch
|
|
22
|
-
action = { type: 'CLASS_STATE', class: @component_name, name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
|
|
23
|
-
Isomorfeus.store.collect_and_defer_dispatch(action)
|
|
24
|
-
else
|
|
25
|
-
# get class state
|
|
26
|
-
# check if we have a component local state value
|
|
27
|
-
if @native && @native.JS[:props].JS[:store]
|
|
28
|
-
if @native.JS[:props].JS[:store].JS[:class_state] &&
|
|
29
|
-
@native.JS[:props].JS[:store].JS[:class_state].JS[@component_name] &&
|
|
30
|
-
@native.JS[:props].JS[:store].JS[:class_state].JS[@component_name].JS.hasOwnProperty(key)
|
|
31
|
-
return @native.JS[:props].JS[:store].JS[:class_state].JS[@component_name].JS[key]
|
|
32
|
-
end
|
|
33
|
-
else
|
|
34
|
-
a_state = Isomorfeus.store.get_state
|
|
35
|
-
if a_state.key?(:class_state) && a_state[:class_state].key?(@component_name) && a_state[:class_state][@component_name].key?(key)
|
|
36
|
-
return a_state[:class_state][@component_name][key]
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
# otherwise return nil
|
|
40
|
-
return nil
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
1
|
+
module LucidComponent
|
|
2
|
+
class ClassStoreProxy
|
|
3
|
+
def initialize(component_name, component_instance = nil, native = nil)
|
|
4
|
+
@component_name = component_name
|
|
5
|
+
if component_instance
|
|
6
|
+
@native = native
|
|
7
|
+
@component_instance = component_instance
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def [](key)
|
|
12
|
+
method_missing(key)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def []=(key, value)
|
|
16
|
+
method_missing(key, value)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def method_missing(key, *args, &block)
|
|
20
|
+
if `args.length > 0`
|
|
21
|
+
# set class state, simply a dispatch
|
|
22
|
+
action = { type: 'CLASS_STATE', class: @component_name, name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
|
|
23
|
+
Isomorfeus.store.collect_and_defer_dispatch(action)
|
|
24
|
+
else
|
|
25
|
+
# get class state
|
|
26
|
+
# check if we have a component local state value
|
|
27
|
+
if @native && @native.JS[:props].JS[:store]
|
|
28
|
+
if @native.JS[:props].JS[:store].JS[:class_state] &&
|
|
29
|
+
@native.JS[:props].JS[:store].JS[:class_state].JS[@component_name] &&
|
|
30
|
+
@native.JS[:props].JS[:store].JS[:class_state].JS[@component_name].JS.hasOwnProperty(key)
|
|
31
|
+
return @native.JS[:props].JS[:store].JS[:class_state].JS[@component_name].JS[key]
|
|
32
|
+
end
|
|
33
|
+
else
|
|
34
|
+
a_state = Isomorfeus.store.get_state
|
|
35
|
+
if a_state.key?(:class_state) && a_state[:class_state].key?(@component_name) && a_state[:class_state][@component_name].key?(key)
|
|
36
|
+
return a_state[:class_state][@component_name][key]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
# otherwise return nil
|
|
40
|
+
return nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
module LucidComponent
|
|
2
|
-
module Initializer
|
|
3
|
-
def initialize(native_component)
|
|
4
|
-
@native = native_component
|
|
5
|
-
@app_store = LucidComponent::AppStoreProxy.new(self)
|
|
6
|
-
@class_store = LucidComponent::ClassStoreProxy.new(self.class.to_s, self, @native)
|
|
7
|
-
# @iso_store = Isomorfeus::IsomorphicStoreProxy.new(self)
|
|
8
|
-
# @local_store = Isomorfeus::LocalStoreProxy.new(self)
|
|
9
|
-
@store = LucidComponent::InstanceStoreProxy.new(self)
|
|
10
|
-
@props = `Opal.React.Component.Props.$new(#@native)`
|
|
11
|
-
@state = `Opal.React.Component.State.$new(#@native)`
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
1
|
+
module LucidComponent
|
|
2
|
+
module Initializer
|
|
3
|
+
def initialize(native_component)
|
|
4
|
+
@native = native_component
|
|
5
|
+
@app_store = LucidComponent::AppStoreProxy.new(self)
|
|
6
|
+
@class_store = LucidComponent::ClassStoreProxy.new(self.class.to_s, self, @native)
|
|
7
|
+
# @iso_store = Isomorfeus::IsomorphicStoreProxy.new(self)
|
|
8
|
+
# @local_store = Isomorfeus::LocalStoreProxy.new(self)
|
|
9
|
+
@store = LucidComponent::InstanceStoreProxy.new(self)
|
|
10
|
+
@props = `Opal.React.Component.Props.$new(#@native)`
|
|
11
|
+
@state = `Opal.React.Component.State.$new(#@native)`
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
module LucidComponent
|
|
2
|
-
class InstanceStoreProxy
|
|
3
|
-
def initialize(component_instance)
|
|
4
|
-
@native = component_instance.to_n
|
|
5
|
-
@component_instance = component_instance
|
|
6
|
-
@component_object_id = component_instance.object_id.to_s
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def [](key)
|
|
10
|
-
method_missing(key)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def []=(key, value)
|
|
14
|
-
method_missing(key, value)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def method_missing(key, *args, &block)
|
|
18
|
-
if `args.length > 0`
|
|
19
|
-
# set instance state, simply a dispatch
|
|
20
|
-
|
|
21
|
-
action = { type: 'INSTANCE_STATE', object_id: @component_object_id, name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
|
|
22
|
-
Isomorfeus.store.collect_and_defer_dispatch(action)
|
|
23
|
-
|
|
24
|
-
else
|
|
25
|
-
# get instance state
|
|
26
|
-
if @native.JS[:props].JS[:store]
|
|
27
|
-
if @native.JS[:props].JS[:store].JS[:instance_state] &&
|
|
28
|
-
@native.JS[:props].JS[:store].JS[:instance_state].JS[@component_object_id] &&
|
|
29
|
-
@native.JS[:props].JS[:store].JS[:instance_state].JS[@component_object_id].JS.hasOwnProperty(key)
|
|
30
|
-
# check if we have a component local state value
|
|
31
|
-
return @native.JS[:props].JS[:store].JS[:instance_state].JS[@component_object_id].JS[key]
|
|
32
|
-
end
|
|
33
|
-
else
|
|
34
|
-
a_state = Isomorfeus.store.get_state
|
|
35
|
-
if a_state.key?(:instance_state) && a_state[:instance_state].key?(key)
|
|
36
|
-
return a_state[:instance_state][key]
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
# otherwise return nil
|
|
40
|
-
return nil
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
1
|
+
module LucidComponent
|
|
2
|
+
class InstanceStoreProxy
|
|
3
|
+
def initialize(component_instance)
|
|
4
|
+
@native = component_instance.to_n
|
|
5
|
+
@component_instance = component_instance
|
|
6
|
+
@component_object_id = component_instance.object_id.to_s
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def [](key)
|
|
10
|
+
method_missing(key)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def []=(key, value)
|
|
14
|
+
method_missing(key, value)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def method_missing(key, *args, &block)
|
|
18
|
+
if `args.length > 0`
|
|
19
|
+
# set instance state, simply a dispatch
|
|
20
|
+
|
|
21
|
+
action = { type: 'INSTANCE_STATE', object_id: @component_object_id, name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
|
|
22
|
+
Isomorfeus.store.collect_and_defer_dispatch(action)
|
|
23
|
+
|
|
24
|
+
else
|
|
25
|
+
# get instance state
|
|
26
|
+
if @native.JS[:props].JS[:store]
|
|
27
|
+
if @native.JS[:props].JS[:store].JS[:instance_state] &&
|
|
28
|
+
@native.JS[:props].JS[:store].JS[:instance_state].JS[@component_object_id] &&
|
|
29
|
+
@native.JS[:props].JS[:store].JS[:instance_state].JS[@component_object_id].JS.hasOwnProperty(key)
|
|
30
|
+
# check if we have a component local state value
|
|
31
|
+
return @native.JS[:props].JS[:store].JS[:instance_state].JS[@component_object_id].JS[key]
|
|
32
|
+
end
|
|
33
|
+
else
|
|
34
|
+
a_state = Isomorfeus.store.get_state
|
|
35
|
+
if a_state.key?(:instance_state) && a_state[:instance_state].key?(key)
|
|
36
|
+
return a_state[:instance_state][key]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
# otherwise return nil
|
|
40
|
+
return nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
module LucidComponent
|
|
2
|
-
module Mixin
|
|
3
|
-
def self.included(base)
|
|
4
|
-
base.include(::Native::Wrapper)
|
|
5
|
-
base.extend(::LucidComponent::NativeLucidComponentConstructor)
|
|
6
|
-
if on_browser? || on_ssr?
|
|
7
|
-
base.extend(::LucidComponent::NativeComponentConstructor)
|
|
8
|
-
base.include(::React::Component::Elements)
|
|
9
|
-
elsif on_mobile?
|
|
10
|
-
base.extend(::LucidComponent::ReactNativeComponentConstructor)
|
|
11
|
-
base.include(::ReactNative::Component::Elements)
|
|
12
|
-
end
|
|
13
|
-
base.extend(::LucidPropDeclaration::Mixin)
|
|
14
|
-
base.include(::React::Component::Api)
|
|
15
|
-
base.include(::React::Component::Callbacks)
|
|
16
|
-
base.include(::LucidComponent::Api)
|
|
17
|
-
base.include(::LucidComponent::StylesApi)
|
|
18
|
-
base.include(::LucidComponent::Initializer)
|
|
19
|
-
base.include(::React::Component::Features)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
1
|
+
module LucidComponent
|
|
2
|
+
module Mixin
|
|
3
|
+
def self.included(base)
|
|
4
|
+
base.include(::Native::Wrapper)
|
|
5
|
+
base.extend(::LucidComponent::NativeLucidComponentConstructor)
|
|
6
|
+
if on_browser? || on_ssr?
|
|
7
|
+
base.extend(::LucidComponent::NativeComponentConstructor)
|
|
8
|
+
base.include(::React::Component::Elements)
|
|
9
|
+
elsif on_mobile?
|
|
10
|
+
base.extend(::LucidComponent::ReactNativeComponentConstructor)
|
|
11
|
+
base.include(::ReactNative::Component::Elements)
|
|
12
|
+
end
|
|
13
|
+
base.extend(::LucidPropDeclaration::Mixin)
|
|
14
|
+
base.include(::React::Component::Api)
|
|
15
|
+
base.include(::React::Component::Callbacks)
|
|
16
|
+
base.include(::LucidComponent::Api)
|
|
17
|
+
base.include(::LucidComponent::StylesApi)
|
|
18
|
+
base.include(::LucidComponent::Initializer)
|
|
19
|
+
base.include(::React::Component::Features)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
module LucidComponent
|
|
2
|
-
module NativeComponentConstructor
|
|
3
|
-
# for should_component_update we apply ruby semantics for comparing props
|
|
4
|
-
# to do so, we convert the props to ruby hashes and then compare
|
|
5
|
-
# this makes sure, that for example rubys Nil object gets handled properly
|
|
6
|
-
def self.extended(base)
|
|
7
|
-
component_name = base.to_s + 'Wrapper'
|
|
8
|
-
# language=JS
|
|
9
|
-
%x{
|
|
10
|
-
base.react_component = Opal.global.React.memo(function(props) {
|
|
11
|
-
let opag = Opal.global;
|
|
12
|
-
let classes;
|
|
13
|
-
let store;
|
|
14
|
-
if (base.store_updates) { store = opag.React.useContext(opag.LucidApplicationContext); }
|
|
15
|
-
let theme = opag.ReactJSS.useTheme();
|
|
16
|
-
if (base.jss_styles) {
|
|
17
|
-
if (!base.use_styles || (Opal.Isomorfeus.development === true)) {
|
|
18
|
-
let styles;
|
|
19
|
-
if (typeof base.jss_styles === 'function') { styles = base.jss_styles(theme); }
|
|
20
|
-
else { styles = base.jss_styles; }
|
|
21
|
-
base.use_styles = opag.ReactJSS.createUseStyles(styles);
|
|
22
|
-
}
|
|
23
|
-
classes = base.use_styles();
|
|
24
|
-
}
|
|
25
|
-
let new_props = Object.assign({}, props)
|
|
26
|
-
new_props.classes = classes;
|
|
27
|
-
new_props.theme = theme;
|
|
28
|
-
new_props.store = store;
|
|
29
|
-
return opag.React.createElement(base.lucid_react_component, new_props);
|
|
30
|
-
}, Opal.React.props_are_equal);
|
|
31
|
-
base.react_component.displayName = #{component_name};
|
|
32
|
-
}
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
1
|
+
module LucidComponent
|
|
2
|
+
module NativeComponentConstructor
|
|
3
|
+
# for should_component_update we apply ruby semantics for comparing props
|
|
4
|
+
# to do so, we convert the props to ruby hashes and then compare
|
|
5
|
+
# this makes sure, that for example rubys Nil object gets handled properly
|
|
6
|
+
def self.extended(base)
|
|
7
|
+
component_name = base.to_s + 'Wrapper'
|
|
8
|
+
# language=JS
|
|
9
|
+
%x{
|
|
10
|
+
base.react_component = Opal.global.React.memo(function(props) {
|
|
11
|
+
let opag = Opal.global;
|
|
12
|
+
let classes;
|
|
13
|
+
let store;
|
|
14
|
+
if (base.store_updates) { store = opag.React.useContext(opag.LucidApplicationContext); }
|
|
15
|
+
let theme = opag.ReactJSS.useTheme();
|
|
16
|
+
if (base.jss_styles) {
|
|
17
|
+
if (!base.use_styles || (Opal.Isomorfeus.development === true)) {
|
|
18
|
+
let styles;
|
|
19
|
+
if (typeof base.jss_styles === 'function') { styles = base.jss_styles(theme); }
|
|
20
|
+
else { styles = base.jss_styles; }
|
|
21
|
+
base.use_styles = opag.ReactJSS.createUseStyles(styles);
|
|
22
|
+
}
|
|
23
|
+
classes = base.use_styles();
|
|
24
|
+
}
|
|
25
|
+
let new_props = Object.assign({}, props)
|
|
26
|
+
new_props.classes = classes;
|
|
27
|
+
new_props.theme = theme;
|
|
28
|
+
new_props.store = store;
|
|
29
|
+
return opag.React.createElement(base.lucid_react_component, new_props);
|
|
30
|
+
}, Opal.React.props_are_equal);
|
|
31
|
+
base.react_component.displayName = #{component_name};
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -1,83 +1,82 @@
|
|
|
1
|
-
module LucidComponent
|
|
2
|
-
module NativeLucidComponentConstructor
|
|
3
|
-
# for should_component_update we apply ruby semantics for comparing props
|
|
4
|
-
# to do so, we convert the props to ruby hashes and then compare
|
|
5
|
-
# this makes sure, that for example rubys Nil object gets handled properly
|
|
6
|
-
def self.extended(base)
|
|
7
|
-
component_name = base.to_s
|
|
8
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
oper.render_buffer.
|
|
48
|
-
|
|
49
|
-
oper.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
oper.
|
|
56
|
-
oper.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
base.
|
|
76
|
-
base.
|
|
77
|
-
base.
|
|
78
|
-
base.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
end
|
|
1
|
+
module LucidComponent
|
|
2
|
+
module NativeLucidComponentConstructor
|
|
3
|
+
# for should_component_update we apply ruby semantics for comparing props
|
|
4
|
+
# to do so, we convert the props to ruby hashes and then compare
|
|
5
|
+
# this makes sure, that for example rubys Nil object gets handled properly
|
|
6
|
+
def self.extended(base)
|
|
7
|
+
component_name = base.to_s
|
|
8
|
+
%x{
|
|
9
|
+
base.lucid_react_component = class extends Opal.global.React.Component {
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super(props);
|
|
12
|
+
const oper = Opal.React;
|
|
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 = oper.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
|
+
if (base.preload_block) {
|
|
32
|
+
oper.active_redux_components.push(this);
|
|
33
|
+
this.state.preloaded = this.__ruby_instance.$execute_preload_block();
|
|
34
|
+
oper.active_redux_components.pop();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
static get displayName() {
|
|
38
|
+
return #{component_name};
|
|
39
|
+
}
|
|
40
|
+
static set displayName(new_name) {
|
|
41
|
+
// dont do anything here except returning the set value
|
|
42
|
+
return new_name;
|
|
43
|
+
}
|
|
44
|
+
render() {
|
|
45
|
+
const oper = Opal.React;
|
|
46
|
+
oper.render_buffer.push([]);
|
|
47
|
+
// console.log("lucid component pushed", oper.render_buffer, oper.render_buffer.toString());
|
|
48
|
+
oper.active_components.push(this);
|
|
49
|
+
oper.active_redux_components.push(this);
|
|
50
|
+
let block_result;
|
|
51
|
+
if (base.while_loading_block && !this.state.preloaded) { block_result = #{`this.__ruby_instance`.instance_exec(&`base.while_loading_block`)}; }
|
|
52
|
+
else { block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)}; }
|
|
53
|
+
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
|
54
|
+
oper.active_redux_components.pop();
|
|
55
|
+
oper.active_components.pop();
|
|
56
|
+
// console.log("lucid component popping", oper.render_buffer, oper.render_buffer.toString());
|
|
57
|
+
let result = oper.render_buffer.pop();
|
|
58
|
+
return (result.length === 1) ? result[0] : result;
|
|
59
|
+
}
|
|
60
|
+
data_access() {
|
|
61
|
+
return this.props.store;
|
|
62
|
+
}
|
|
63
|
+
shouldComponentUpdate(next_props, next_state) {
|
|
64
|
+
if (!Opal.React.props_are_equal(this.props, next_props)) { return true; }
|
|
65
|
+
if (Opal.React.state_is_not_equal(this.state, next_state)) { return true; }
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
validateProp(props, propName, componentName) {
|
|
69
|
+
try { base.$validate_prop(propName, props[propName]) }
|
|
70
|
+
catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
base.preload_block = null;
|
|
75
|
+
base.while_loading_block = null;
|
|
76
|
+
base.jss_styles = null;
|
|
77
|
+
base.use_styles = null;
|
|
78
|
+
base.store_updates = true;
|
|
79
|
+
}
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
module LucidComponent
|
|
2
|
-
module StylesApi
|
|
3
|
-
def self.included(base)
|
|
4
|
-
base.instance_exec do
|
|
5
|
-
# styles
|
|
6
|
-
def styles(styles_hash = nil, &block)
|
|
7
|
-
if block_given?
|
|
8
|
-
%x{
|
|
9
|
-
base.jss_styles = function(theme) {
|
|
10
|
-
let wrapped_theme = Opal.React.Component.Styles.$new(theme);
|
|
11
|
-
var result = block.$call(wrapped_theme);
|
|
12
|
-
return result.$to_n();
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
nil
|
|
16
|
-
elsif styles_hash
|
|
17
|
-
`base.jss_styles = #{styles_hash.to_n}` if styles_hash
|
|
18
|
-
styles_hash
|
|
19
|
-
elsif `typeof base.jss_styles === 'object'`
|
|
20
|
-
`Opal.Hash.$new(base.jss_styles)`
|
|
21
|
-
else
|
|
22
|
-
nil
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
alias_method :styles=, :styles
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# styles
|
|
29
|
-
def styles
|
|
30
|
-
props.classes
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
1
|
+
module LucidComponent
|
|
2
|
+
module StylesApi
|
|
3
|
+
def self.included(base)
|
|
4
|
+
base.instance_exec do
|
|
5
|
+
# styles
|
|
6
|
+
def styles(styles_hash = nil, &block)
|
|
7
|
+
if block_given?
|
|
8
|
+
%x{
|
|
9
|
+
base.jss_styles = function(theme) {
|
|
10
|
+
let wrapped_theme = Opal.React.Component.Styles.$new(theme);
|
|
11
|
+
var result = block.$call(wrapped_theme);
|
|
12
|
+
return result.$to_n();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
nil
|
|
16
|
+
elsif styles_hash
|
|
17
|
+
`base.jss_styles = #{styles_hash.to_n}` if styles_hash
|
|
18
|
+
styles_hash
|
|
19
|
+
elsif `typeof base.jss_styles === 'object'`
|
|
20
|
+
`Opal.Hash.$new(base.jss_styles)`
|
|
21
|
+
else
|
|
22
|
+
nil
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
alias_method :styles=, :styles
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# styles
|
|
29
|
+
def styles
|
|
30
|
+
props.classes
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
module LucidFunc
|
|
2
|
-
class Base
|
|
3
|
-
def self.inherited(base)
|
|
4
|
-
base.include(::LucidFunc::Mixin)
|
|
5
|
-
end
|
|
6
|
-
end
|
|
7
|
-
end
|
|
1
|
+
module LucidFunc
|
|
2
|
+
class Base
|
|
3
|
+
def self.inherited(base)
|
|
4
|
+
base.include(::LucidFunc::Mixin)
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
module LucidFunc
|
|
2
|
-
module Initializer
|
|
3
|
-
def initialize
|
|
4
|
-
self.JS[:native_props] = `{ props: null }`
|
|
5
|
-
@native_props = `Opal.React.Component.Props.$new(#{self})`
|
|
6
|
-
@app_store = LucidComponent::AppStoreProxy.new(self)
|
|
7
|
-
@class_store = LucidComponent::ClassStoreProxy.new(self.class.to_s, self, self)
|
|
8
|
-
@store = LucidComponent::InstanceStoreProxy.new(self)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
1
|
+
module LucidFunc
|
|
2
|
+
module Initializer
|
|
3
|
+
def initialize
|
|
4
|
+
self.JS[:native_props] = `{ props: null }`
|
|
5
|
+
@native_props = `Opal.React.Component.Props.$new(#{self})`
|
|
6
|
+
@app_store = LucidComponent::AppStoreProxy.new(self)
|
|
7
|
+
@class_store = LucidComponent::ClassStoreProxy.new(self.class.to_s, self, self)
|
|
8
|
+
@store = LucidComponent::InstanceStoreProxy.new(self)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
module LucidFunc
|
|
2
|
-
module Mixin
|
|
3
|
-
def self.included(base)
|
|
4
|
-
base.include(::React::Component::Features)
|
|
5
|
-
base.include(::LucidFunc::Initializer)
|
|
6
|
-
base.include(::React::FunctionComponent::Api)
|
|
7
|
-
if on_browser? || on_ssr?
|
|
8
|
-
base.extend(::LucidFunc::NativeComponentConstructor)
|
|
9
|
-
base.include(::React::Component::Elements)
|
|
10
|
-
elsif on_mobile?
|
|
11
|
-
base.extend(::LucidFunc::ReactNativeComponentConstructor)
|
|
12
|
-
base.include(::ReactNative::Component::Elements)
|
|
13
|
-
end
|
|
14
|
-
base.include(::LucidComponent::Api)
|
|
15
|
-
base.include(::LucidComponent::StylesApi)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
1
|
+
module LucidFunc
|
|
2
|
+
module Mixin
|
|
3
|
+
def self.included(base)
|
|
4
|
+
base.include(::React::Component::Features)
|
|
5
|
+
base.include(::LucidFunc::Initializer)
|
|
6
|
+
base.include(::React::FunctionComponent::Api)
|
|
7
|
+
if on_browser? || on_ssr?
|
|
8
|
+
base.extend(::LucidFunc::NativeComponentConstructor)
|
|
9
|
+
base.include(::React::Component::Elements)
|
|
10
|
+
elsif on_mobile?
|
|
11
|
+
base.extend(::LucidFunc::ReactNativeComponentConstructor)
|
|
12
|
+
base.include(::ReactNative::Component::Elements)
|
|
13
|
+
end
|
|
14
|
+
base.include(::LucidComponent::Api)
|
|
15
|
+
base.include(::LucidComponent::StylesApi)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|