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
data/lib/isomorfeus/top_level.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
class TopLevel
|
3
|
-
class << self
|
4
|
-
def mount!
|
5
|
-
Isomorfeus.init
|
6
|
-
Isomorfeus::TopLevel.on_ready do
|
7
|
-
root_element = `document.querySelector('div[data-iso-root]')`
|
8
|
-
component_name = root_element.JS.getAttribute('data-iso-root')
|
9
|
-
Isomorfeus.env = root_element.JS.getAttribute('data-iso-env')
|
10
|
-
component = nil
|
11
|
-
begin
|
12
|
-
component = component_name.constantize
|
13
|
-
rescue Exception
|
14
|
-
@timeout_start = Time.now unless @timeout_start
|
15
|
-
if (Time.now - @timeout_start) < 10
|
16
|
-
`setTimeout(Opal.Isomorfeus.TopLevel['$mount!'], 100)`
|
17
|
-
else
|
18
|
-
`console.error("Unable to mount '" + #{component_name} + "'!")`
|
19
|
-
end
|
20
|
-
end
|
21
|
-
if component
|
22
|
-
props_json = root_element.JS.getAttribute('data-iso-props')
|
23
|
-
props = `Opal.Hash.$new(JSON.parse(props_json))`
|
24
|
-
hydrated = root_element.JS.getAttribute('data-iso-hydrated')
|
25
|
-
state_json = root_element.JS.getAttribute('data-iso-state')
|
26
|
-
if state_json
|
27
|
-
%x{
|
28
|
-
var state = JSON.parse(state_json);
|
29
|
-
var keys = Object.keys(state);
|
30
|
-
for(var i=0; i < keys.length; i++) {
|
31
|
-
global.Opal.Isomorfeus.store.native.dispatch({ type: keys[i].toUpperCase(), set_state: state[keys[i]] });
|
32
|
-
}
|
33
|
-
}
|
34
|
-
end
|
35
|
-
begin
|
36
|
-
Isomorfeus::TopLevel.mount_component(component, props, root_element, hydrated)
|
37
|
-
rescue Exception
|
38
|
-
@timeout_start = Time.now unless @timeout_start
|
39
|
-
if (Time.now - @timeout_start) < 10
|
40
|
-
`setTimeout(Opal.Isomorfeus.TopLevel['$mount!'], 100)`
|
41
|
-
else
|
42
|
-
`console.error("Unable to mount '" + #{component_name} + "'!")`
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def on_ready(&block)
|
50
|
-
# this looks a bit odd but works across _all_ browsers, and no event handler mess
|
51
|
-
%x{
|
52
|
-
function run() { block.$call() };
|
53
|
-
function ready_fun() {
|
54
|
-
/in/.test(document.readyState) ? setTimeout(ready_fun,5) : run();
|
55
|
-
}
|
56
|
-
ready_fun();
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
def on_ready_mount(component, props = nil, element_query = nil)
|
61
|
-
# init in case it hasn't been run yet
|
62
|
-
Isomorfeus.init
|
63
|
-
on_ready do
|
64
|
-
Isomorfeus::TopLevel.mount_component(component, props, element_query)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def mount_component(component, props, element_or_query, hydrated = false)
|
69
|
-
if `(typeof element_or_query === 'string')` || (`(typeof element_or_query.$class === 'function')` && element_or_query.class == String)
|
70
|
-
element = `document.body.querySelector(element_or_query)`
|
71
|
-
elsif `(typeof element_or_query.$is_a === 'function')` && element_or_query.is_a?(Browser::Element)
|
72
|
-
element = element_or_query.to_n
|
73
|
-
else
|
74
|
-
element = element_or_query
|
75
|
-
end
|
76
|
-
|
77
|
-
top = if hydrated
|
78
|
-
ReactDOM.hydrate(React.create_element(component, props), element)
|
79
|
-
else
|
80
|
-
ReactDOM.render(React.create_element(component, props), element)
|
81
|
-
end
|
82
|
-
Isomorfeus.top_component = top if top
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
class TopLevel
|
3
|
-
class << self
|
4
|
-
attr_accessor :ssr_route_path
|
5
|
-
attr_accessor :transport_ws_url
|
6
|
-
|
7
|
-
def mount!
|
8
|
-
# nothing, but keep it for compatibility with browser
|
9
|
-
end
|
10
|
-
|
11
|
-
def render_component_to_string(component_name, props)
|
12
|
-
component = nil
|
13
|
-
%x{
|
14
|
-
if (typeof component_name === 'string' || component_name instanceof String) {
|
15
|
-
component = component_name.split(".").reduce(function(o, x) {
|
16
|
-
return (o !== null && typeof o[x] !== "undefined" && o[x] !== null) ? o[x] : null;
|
17
|
-
}, Opal.global)
|
18
|
-
} else {
|
19
|
-
component = component_name;
|
20
|
-
}
|
21
|
-
}
|
22
|
-
component = Isomorfeus.cached_component_class(component_name) unless component
|
23
|
-
|
24
|
-
ReactDOMServer.render_to_string(React.create_element(component, `Opal.Hash.$new(props)`))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/lib/lucid_app/api.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
module LucidApp
|
2
|
-
module API
|
3
|
-
def self.included(base)
|
4
|
-
base.instance_exec do
|
5
|
-
def theme(theme_hash = nil, &block)
|
6
|
-
if block_given?
|
7
|
-
%x{
|
8
|
-
let result = block.$call(Opal.Hash.$new(base.jss_theme));
|
9
|
-
if (typeof result.$to_n === 'function') { base.jss_theme = result.$to_n(); }
|
10
|
-
else { base.jss_theme = result; }
|
11
|
-
return result;
|
12
|
-
}
|
13
|
-
elsif theme_hash
|
14
|
-
`base.jss_theme = #{theme_hash.to_n}` if theme_hash
|
15
|
-
theme_hash
|
16
|
-
elsif `typeof base.jss_theme === 'object'`
|
17
|
-
`Opal.Hash.$new(base.jss_theme)`
|
18
|
-
else
|
19
|
-
nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
alias_method :theme=, :theme
|
23
|
-
end
|
24
|
-
|
25
|
-
def context
|
26
|
-
@native.JS[:context]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/lucid_app/base.rb
DELETED
data/lib/lucid_app/context.rb
DELETED
data/lib/lucid_app/mixin.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module LucidApp
|
2
|
-
module Mixin
|
3
|
-
def self.included(base)
|
4
|
-
base.include(::Native::Wrapper)
|
5
|
-
base.extend(::LucidApp::NativeComponentConstructor)
|
6
|
-
base.extend(::LucidPropDeclaration::Mixin)
|
7
|
-
base.extend(::React::Component::ShouldComponentUpdate)
|
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(::LucidApp::API)
|
15
|
-
base.include(::LucidComponent::Initializer)
|
16
|
-
base.include(::React::Component::Features)
|
17
|
-
base.include(::React::Component::Resolution)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
module LucidApp
|
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
|
8
|
-
# language=JS
|
9
|
-
%x{
|
10
|
-
base.lucid_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.state.isomorfeus_store_state = Opal.Isomorfeus.store.native.getState();
|
19
|
-
var current_store_state = this.state.isomorfeus_store_state;
|
20
|
-
if (typeof current_store_state.component_class_state[#{component_name}] !== "undefined") {
|
21
|
-
this.state.component_class_state = {};
|
22
|
-
this.state.component_class_state[#{component_name}] = current_store_state.component_class_state[#{component_name}];
|
23
|
-
} else {
|
24
|
-
this.state.component_class_state = {};
|
25
|
-
this.state.component_class_state[#{component_name}] = {};
|
26
|
-
};
|
27
|
-
this.__ruby_instance = base.$new(this);
|
28
|
-
this.__object_id = this.__ruby_instance.$object_id().$to_s();
|
29
|
-
if (Opal.Isomorfeus.$top_component() == nil) { Opal.Isomorfeus['$top_component='](this); }
|
30
|
-
if (!this.state.component_state) {
|
31
|
-
this.state.component_state = {};
|
32
|
-
this.state.component_state[this.__object_id] = {};
|
33
|
-
};
|
34
|
-
var event_handlers = #{base.event_handlers};
|
35
|
-
for (var i = 0; i < event_handlers.length; i++) {
|
36
|
-
this[event_handlers[i]] = this[event_handlers[i]].bind(this);
|
37
|
-
}
|
38
|
-
var defined_refs = #{base.defined_refs};
|
39
|
-
for (var ref in defined_refs) {
|
40
|
-
if (defined_refs[ref] != null) {
|
41
|
-
this[ref] = function(element) {
|
42
|
-
element = Opal.React.native_element_or_component_to_ruby(element);
|
43
|
-
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
|
44
|
-
}
|
45
|
-
this[ref] = this[ref].bind(this);
|
46
|
-
} else {
|
47
|
-
this[ref] = Opal.global.React.createRef();
|
48
|
-
}
|
49
|
-
}
|
50
|
-
this.listener = this.listener.bind(this);
|
51
|
-
this.unsubscriber = Opal.Isomorfeus.store.native.subscribe(this.listener);
|
52
|
-
}
|
53
|
-
static get displayName() {
|
54
|
-
return #{component_name};
|
55
|
-
}
|
56
|
-
render() {
|
57
|
-
Opal.React.render_buffer.push([]);
|
58
|
-
Opal.React.active_components.push(this);
|
59
|
-
Opal.React.active_redux_components.push(this.__ruby_instance);
|
60
|
-
#{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
|
61
|
-
Opal.React.active_redux_components.pop();
|
62
|
-
Opal.React.active_components.pop();
|
63
|
-
let children = Opal.React.render_buffer.pop();
|
64
|
-
return Opal.global.React.createElement(Opal.global.LucidApplicationContext.Provider, { value: this.state.isomorfeus_store_state }, children);
|
65
|
-
}
|
66
|
-
listener() {
|
67
|
-
let next_state = Opal.Isomorfeus.store.native.getState();
|
68
|
-
this.setState({ isomorfeus_store_state: next_state });
|
69
|
-
}
|
70
|
-
componentWillUnmount() {
|
71
|
-
if (typeof this.unsubscriber === "function") { this.unsubscriber(); };
|
72
|
-
}
|
73
|
-
validateProp(props, propName, componentName) {
|
74
|
-
try { base.$validate_prop(propName, props[propName]) }
|
75
|
-
catch (e) { return new Error(componentName + ": Error: prop validation failed: " + e.message); }
|
76
|
-
return null;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
base.jss_styles = null;
|
80
|
-
base.jss_styles_used = null;
|
81
|
-
base.jss_theme = {};
|
82
|
-
base.use_styles = null;
|
83
|
-
base.themed_react_component = function(props) {
|
84
|
-
let classes = null;
|
85
|
-
let theme = Opal.global.ReactJSS.useTheme();
|
86
|
-
if (base.jss_styles) {
|
87
|
-
if (!base.use_styles || (Opal.Isomorfeus["$development?"]() && !Object.is(base.jss_styles, base.jss_styles_used))) {
|
88
|
-
base.jss_styles_used = base.jss_styles;
|
89
|
-
let styles = base.jss_styles
|
90
|
-
if (typeof styles === 'function') { styles = styles(theme); }
|
91
|
-
base.use_styles = Opal.global.ReactJSS.createUseStyles(styles);
|
92
|
-
}
|
93
|
-
classes = base.use_styles();
|
94
|
-
}
|
95
|
-
let themed_classes_props = Object.assign({}, props, { classes: classes, theme: theme });
|
96
|
-
return Opal.global.React.createElement(base.lucid_react_component, themed_classes_props);
|
97
|
-
}
|
98
|
-
base.react_component = function(props) {
|
99
|
-
let themed_component = Opal.global.React.createElement(base.themed_react_component, props);
|
100
|
-
return Opal.global.React.createElement(Opal.global.ReactJSS.ThemeProvider, { theme: base.jss_theme }, themed_component);
|
101
|
-
}
|
102
|
-
}
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module LucidComponent
|
2
|
-
class AppStoreDefaults
|
3
|
-
def initialize(state, component_name)
|
4
|
-
@state = state
|
5
|
-
if @state.isomorfeus_store
|
6
|
-
@state.isomorfeus_store.merge!(application_state: {})
|
7
|
-
else
|
8
|
-
@state.isomorfeus_store = { application_state: {}}
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def method_missing(key, *args, &block)
|
13
|
-
if `args.length > 0`
|
14
|
-
# set initial class state
|
15
|
-
key = key.chop if `key.endsWith('=')`
|
16
|
-
@state.isomorfeus_store[:application_state][key] = args[0]
|
17
|
-
current_state = Isomorfeus.store.get_state
|
18
|
-
if !(current_state[:application_state].key?(key))
|
19
|
-
Isomorfeus.store.dispatch(type: 'APPLICATION_STATE', name: key, value: args[0])
|
20
|
-
end
|
21
|
-
else
|
22
|
-
# get class state
|
23
|
-
|
24
|
-
# check if we have a component local state value
|
25
|
-
if @state.isomorfeus_store[:application_state].key?(key)
|
26
|
-
return @state.isomorfeus_store[:application_state][key]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
nil
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_h
|
33
|
-
@state.isomorfeus_store[:application_state]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module LucidComponent
|
2
|
-
class AppStoreProxy
|
3
|
-
def initialize(component_instance)
|
4
|
-
@native_component_instance = component_instance.to_n
|
5
|
-
@component_instance = component_instance
|
6
|
-
end
|
7
|
-
|
8
|
-
def method_missing(key, *args, &block)
|
9
|
-
if `args.length > 0`
|
10
|
-
# set class state, simply a dispatch
|
11
|
-
action = { type: 'APPLICATION_STATE', name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
|
12
|
-
Isomorfeus.store.dispatch(action)
|
13
|
-
else
|
14
|
-
# check if we have a component local state value
|
15
|
-
if `this.native_component_instance.context.application_state.hasOwnProperty(key)`
|
16
|
-
return @native_component_instance.JS['context'].JS[:application_state].JS[key]
|
17
|
-
elsif @component_instance.class.default_app_store_defined && @component_instance.class.app_store.to_h.key?(key)
|
18
|
-
# check if a default value was given
|
19
|
-
return @component_instance.class.app_store.to_h[key]
|
20
|
-
end
|
21
|
-
# otherwise return nil
|
22
|
-
return nil
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def dispatch(action)
|
27
|
-
Isomorfeus.store.dispatch(action)
|
28
|
-
end
|
29
|
-
|
30
|
-
def subscribe(&block)
|
31
|
-
Isomorfeus.store.subscribe(&block)
|
32
|
-
end
|
33
|
-
|
34
|
-
def unsubscribe(unsubscriber)
|
35
|
-
`unsubscriber()`
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/lucid_component/base.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module LucidComponent
|
2
|
-
class ClassStoreProxy
|
3
|
-
def initialize(component_instance)
|
4
|
-
@native_component_instance = component_instance.to_n
|
5
|
-
@component_instance = component_instance
|
6
|
-
@component_name = component_instance.class.to_s
|
7
|
-
end
|
8
|
-
|
9
|
-
def method_missing(key, *args, &block)
|
10
|
-
if `args.length > 0`
|
11
|
-
# set class state, simply a dispatch
|
12
|
-
action = { type: 'COMPONENT_CLASS_STATE', class: @component_name, name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
|
13
|
-
Isomorfeus.store.dispatch(action)
|
14
|
-
else
|
15
|
-
# get class state
|
16
|
-
# check if we have a component local state value
|
17
|
-
if @native_component_instance.JS['context'].JS[:component_class_state].JS[@component_name] &&
|
18
|
-
@native_component_instance.JS['context'].JS[:component_class_state].JS[@component_name].JS.hasOwnProperty(key)
|
19
|
-
return @native_component_instance.JS['context'].JS[:component_class_state].JS[@component_name].JS[key]
|
20
|
-
elsif @component_instance.class.default_class_store_defined && @component_instance.class.class_store.to_h.key?(key)
|
21
|
-
# check if a default value was given
|
22
|
-
return @component_instance.class.class_store.to_h[key]
|
23
|
-
end
|
24
|
-
# otherwise return nil
|
25
|
-
return nil
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def dispatch(action)
|
30
|
-
Isomorfeus.store.dispatch(action)
|
31
|
-
end
|
32
|
-
|
33
|
-
def subscribe(&block)
|
34
|
-
Isomorfeus.store.subscribe(&block)
|
35
|
-
end
|
36
|
-
|
37
|
-
def unsubscribe(unsubscriber)
|
38
|
-
`unsubscriber()`
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module LucidComponent
|
2
|
-
class ComponentClassStoreDefaults
|
3
|
-
def initialize(state, component_name)
|
4
|
-
@state = state
|
5
|
-
@component_name = component_name
|
6
|
-
if @state.isomorfeus_store
|
7
|
-
@state.isomorfeus_store.merge!(component_class_state: { @component_name => {} })
|
8
|
-
else
|
9
|
-
@state.isomorfeus_store = { component_class_state: { @component_name => {} } }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def method_missing(key, *args, &block)
|
14
|
-
if `args.length > 0`
|
15
|
-
# set initial class state
|
16
|
-
key = key.chop if `key.endsWith('=')`
|
17
|
-
@state.isomorfeus_store[:component_class_state][@component_name][key] = args[0]
|
18
|
-
current_state = Isomorfeus.store.get_state
|
19
|
-
if !(current_state[:component_class_state].key?(@component_name) && current_state[:component_class_state][@component_name].key?(key))
|
20
|
-
Isomorfeus.store.dispatch(type: 'COMPONENT_CLASS_STATE', class: @component_name, name: key, value: args[0])
|
21
|
-
end
|
22
|
-
else
|
23
|
-
# get class state
|
24
|
-
|
25
|
-
# check if we have a component local state value
|
26
|
-
|
27
|
-
if @state.isomorfeus_store[:component_class_state][@component_name].key?(key)
|
28
|
-
return @state.isomorfeus_store[:component_class_state][@component_name][key]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
nil
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_h
|
35
|
-
@state.isomorfeus_store[:component_class_state][@component_name]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|