isomorfeus-preact 10.6.32 → 10.6.36
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isomorfeus/preact_view_helper.rb +11 -11
- data/lib/isomorfeus-preact.rb +15 -0
- data/lib/isomorfeus_preact/lucid_app/api.rb +30 -32
- data/lib/isomorfeus_preact/lucid_app/mixin.rb +12 -13
- data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +88 -90
- data/lib/isomorfeus_preact/lucid_component/api.rb +95 -98
- data/lib/isomorfeus_preact/lucid_component/initializer.rb +7 -10
- data/lib/isomorfeus_preact/lucid_component/mixin.rb +11 -12
- data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +77 -79
- data/lib/isomorfeus_preact/lucid_func/initializer.rb +6 -9
- data/lib/isomorfeus_preact/lucid_func/mixin.rb +8 -9
- data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +49 -51
- data/lib/isomorfeus_preact/preact/function_component/api.rb +102 -106
- data/lib/isomorfeus_preact/preact/function_component/base.rb +5 -7
- data/lib/isomorfeus_preact/preact/function_component/initializer.rb +4 -8
- data/lib/isomorfeus_preact/preact/function_component/mixin.rb +6 -10
- data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +41 -45
- data/lib/lucid_app/context.rb +1 -1
- data/lib/nano_css.rb +10 -10
- data/lib/preact/component/api.rb +99 -103
- data/lib/preact/component/base.rb +5 -7
- data/lib/preact/component/callbacks.rb +99 -103
- data/lib/preact/component/initializer.rb +5 -9
- data/lib/preact/component/mixin.rb +9 -13
- data/lib/preact/component/native_component_constructor.rb +67 -71
- data/lib/preact/component_resolution.rb +78 -80
- data/lib/preact/elements.rb +55 -57
- data/lib/preact/version.rb +1 -1
- data/node_modules/.package-lock.json +3 -3
- data/node_modules/preact/compat/LICENSE +21 -0
- data/node_modules/preact/compat/jsx-dev-runtime.js +2 -0
- data/node_modules/preact/compat/jsx-dev-runtime.mjs +2 -0
- data/node_modules/preact/compat/jsx-runtime.js +2 -0
- data/node_modules/preact/compat/jsx-runtime.mjs +2 -0
- data/node_modules/preact/debug/LICENSE +21 -0
- data/node_modules/preact/devtools/LICENSE +21 -0
- data/node_modules/preact/devtools/dist/devtools.js +1 -1
- data/node_modules/preact/devtools/dist/devtools.js.map +1 -1
- data/node_modules/preact/devtools/dist/devtools.mjs +1 -1
- data/node_modules/preact/devtools/dist/devtools.module.js +1 -1
- data/node_modules/preact/devtools/dist/devtools.module.js.map +1 -1
- data/node_modules/preact/devtools/dist/devtools.umd.js +1 -1
- data/node_modules/preact/devtools/dist/devtools.umd.js.map +1 -1
- data/node_modules/preact/devtools/src/devtools.js +1 -1
- data/node_modules/preact/dist/preact.js +1 -1
- data/node_modules/preact/dist/preact.js.map +1 -1
- data/node_modules/preact/dist/preact.min.js +1 -1
- data/node_modules/preact/dist/preact.min.js.map +1 -1
- data/node_modules/preact/dist/preact.mjs +1 -1
- data/node_modules/preact/dist/preact.module.js +1 -1
- data/node_modules/preact/dist/preact.module.js.map +1 -1
- data/node_modules/preact/dist/preact.umd.js +1 -1
- data/node_modules/preact/dist/preact.umd.js.map +1 -1
- data/node_modules/preact/hooks/LICENSE +21 -0
- data/node_modules/preact/jsx-runtime/LICENSE +21 -0
- data/node_modules/preact/package.json +1 -1
- data/node_modules/preact/src/diff/index.js +6 -3
- data/package.json +1 -1
- metadata +11 -7
- data/lib/isomorfeus_preact/lucid_component/instance_store_proxy.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b8caa31aa809b6b2d5a661043f1d63c601b68435abb00e82b427875b40e8843
|
4
|
+
data.tar.gz: 2e6e86666baaf1afed35e623d498190a8dd3c81ba1a2778efef3e9fd47a0ac20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37963c919f5580f5efff03dec74ae6a34cee64f7789cb5db65b9d1944af95b12076e098da6feaf5198e86d992761673f27f528c80e859f17fa70b3a85a44c70c
|
7
|
+
data.tar.gz: 407af4aa4f09bed6ffc05c94a1670534cea93fbb3c6cd664e9dd49fdaa05a7f78e990c542f165758b8a2247c72f15d87c1c62dcf8ff82999499a3804075288ac
|
@@ -4,9 +4,9 @@ module Isomorfeus
|
|
4
4
|
base.include Isomorfeus::AssetManager::ViewHelper
|
5
5
|
end
|
6
6
|
|
7
|
-
def cached_mount_component(component_name, props = {}, asset_key = 'ssr.js', skip_ssr: false, use_ssr: false, max_passes: 4)
|
7
|
+
def cached_mount_component(component_name, props = {}, asset_key = 'ssr.js', skip_ssr: false, use_ssr: false, max_passes: 4, force: false)
|
8
8
|
key = "#{component_name}#{props}#{asset}"
|
9
|
-
if Isomorfeus.production?
|
9
|
+
if Isomorfeus.production? && !force
|
10
10
|
render_result, @ssr_response_status, @ssr_styles = component_cache.fetch(key)
|
11
11
|
return render_result if render_result
|
12
12
|
end
|
@@ -86,13 +86,13 @@ module Isomorfeus
|
|
86
86
|
JAVASCRIPT
|
87
87
|
# execute first render pass
|
88
88
|
begin
|
89
|
-
pass += 1
|
90
89
|
first_pass_skipped = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
91
90
|
rescue Exception => e
|
92
91
|
Isomorfeus.raise_error(error: e)
|
93
92
|
end
|
94
93
|
# wait for first pass to finish
|
95
94
|
unless first_pass_skipped
|
95
|
+
pass += 1
|
96
96
|
first_pass_finished, exception = Isomorfeus.ssr_contexts[thread_id_asset].exec('return [global.FirstPassFinished, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false ]')
|
97
97
|
Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
|
98
98
|
unless first_pass_finished
|
@@ -132,24 +132,24 @@ module Isomorfeus
|
|
132
132
|
global.Exception = e;
|
133
133
|
}
|
134
134
|
let application_state = global.Opal.Isomorfeus.store.native.getState();
|
135
|
-
let
|
136
|
-
if (typeof global.Opal.Isomorfeus.Transport !== 'undefined' && global.Opal.Isomorfeus.Transport["$busy?"]()) {
|
135
|
+
let still_busy = (#{pass}<2) ? global.Opal.Isomorfeus.store['$recently_dispatched?']() : false;
|
136
|
+
if (typeof global.Opal.Isomorfeus.Transport !== 'undefined' && global.Opal.Isomorfeus.Transport["$busy?"]()) { still_busy = true; }
|
137
137
|
if (typeof global.NanoCSSInstance !== 'undefined') { ssr_styles = global.NanoCSSInstance.raw }
|
138
|
-
return [rendered_tree, application_state, ssr_styles, global.Opal.Isomorfeus['$ssr_response_status'](),
|
138
|
+
return [rendered_tree, application_state, ssr_styles, global.Opal.Isomorfeus['$ssr_response_status'](), still_busy, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false];
|
139
139
|
JAVASCRIPT
|
140
140
|
# execute further render passes
|
141
141
|
pass += 1
|
142
|
-
rendered_tree, application_state, @ssr_styles, @ssr_response_status,
|
142
|
+
rendered_tree, application_state, @ssr_styles, @ssr_response_status, still_busy, exception = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
143
143
|
start_time = Time.now
|
144
|
-
while
|
144
|
+
while still_busy
|
145
145
|
break if (Time.now - start_time) > 5
|
146
|
-
while
|
146
|
+
while still_busy
|
147
147
|
break if (Time.now - start_time) > 4
|
148
148
|
sleep 0.01
|
149
|
-
|
149
|
+
still_busy = Isomorfeus.ssr_contexts[thread_id_asset].exec('return (typeof global.Opal.Isomorfeus.Transport !== "undefined") ? global.Opal.Isomorfeus.Transport["$busy?"]() : false')
|
150
150
|
end
|
151
151
|
pass += 1
|
152
|
-
rendered_tree, application_state, @ssr_styles, @ssr_response_status,
|
152
|
+
rendered_tree, application_state, @ssr_styles, @ssr_response_status, still_busy, exception = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
153
153
|
break if pass >= max_passes
|
154
154
|
end
|
155
155
|
javascript = <<~JAVASCRIPT
|
data/lib/isomorfeus-preact.rb
CHANGED
@@ -38,6 +38,14 @@ if RUBY_ENGINE == 'opal'
|
|
38
38
|
require 'preact/native_constant_wrapper'
|
39
39
|
|
40
40
|
# Preact::Component
|
41
|
+
# make modules available
|
42
|
+
module Preact
|
43
|
+
module Component
|
44
|
+
end
|
45
|
+
module FunctionComponent
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
41
49
|
require 'preact/component/api'
|
42
50
|
require 'preact/component/callbacks'
|
43
51
|
require 'preact/component/initializer'
|
@@ -52,6 +60,13 @@ if RUBY_ENGINE == 'opal'
|
|
52
60
|
include Preact::ComponentResolution
|
53
61
|
end
|
54
62
|
|
63
|
+
# make modules available
|
64
|
+
module LucidApp
|
65
|
+
end
|
66
|
+
module LucidComponent
|
67
|
+
end
|
68
|
+
module LucidFunc
|
69
|
+
end
|
55
70
|
# init LucidApplicationContext (Store Provider and Consumer)
|
56
71
|
require 'lucid_app/context'
|
57
72
|
LucidApp::Context.create_application_context
|
@@ -1,40 +1,38 @@
|
|
1
|
-
module LucidApp
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ogni.hydrate_force_put = true;
|
18
|
-
}
|
19
|
-
}
|
20
|
-
if (typeof theme_hash.$is_wrapped_style !== 'undefined') {
|
21
|
-
base.css_theme = theme_hash;
|
22
|
-
} else {
|
23
|
-
let css;
|
24
|
-
if (typeof theme_hash.$to_n === 'function') { css = theme_hash.$to_n(); }
|
25
|
-
else { css = theme_hash; }
|
26
|
-
let nano_styles = ogni.sheet(css, rule_name);
|
27
|
-
base.css_theme = #{::LucidComponent::StylesWrapper.new(`nano_styles`)};
|
1
|
+
module LucidApp::Api
|
2
|
+
def self.included(base)
|
3
|
+
base.instance_exec do
|
4
|
+
def theme(theme_hash = nil, &block)
|
5
|
+
theme_hash = block.call if block_given?
|
6
|
+
if theme_hash
|
7
|
+
component_name = self.to_s
|
8
|
+
%x{
|
9
|
+
let rule_name = component_name.replace(/:/g, '_');
|
10
|
+
let ogni = Opal.global.NanoCSSInstance;
|
11
|
+
if (base.css_theme && #{Isomorfeus.production?}) { return base.css_theme; }
|
12
|
+
else if(#{Isomorfeus.development?}) {
|
13
|
+
if (#{on_browser?}) {
|
14
|
+
ogni.delete_from_sheet(rule_name);
|
15
|
+
ogni.delete_from_rule_blocks(rule_name);
|
16
|
+
ogni.hydrate_force_put = true;
|
28
17
|
}
|
29
18
|
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
19
|
+
if (typeof theme_hash.$is_wrapped_style !== 'undefined') {
|
20
|
+
base.css_theme = theme_hash;
|
21
|
+
} else {
|
22
|
+
let css;
|
23
|
+
if (typeof theme_hash.$to_n === 'function') { css = theme_hash.$to_n(); }
|
24
|
+
else { css = theme_hash; }
|
25
|
+
let nano_styles = ogni.sheet(css, rule_name);
|
26
|
+
base.css_theme = #{::LucidComponent::StylesWrapper.new(`nano_styles`)};
|
27
|
+
}
|
34
28
|
}
|
35
29
|
end
|
36
|
-
|
30
|
+
%x{
|
31
|
+
if (!base.css_theme) { return nil; }
|
32
|
+
return base.css_theme;
|
33
|
+
}
|
37
34
|
end
|
35
|
+
alias_method :theme=, :theme
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
@@ -1,15 +1,14 @@
|
|
1
|
-
module LucidApp
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
1
|
+
module LucidApp::Mixin
|
2
|
+
def self.included(base)
|
3
|
+
base.include(::Native::Wrapper)
|
4
|
+
base.extend(::LucidApp::NativeComponentConstructor)
|
5
|
+
base.include(::Preact::Elements)
|
6
|
+
base.extend(::LucidPropDeclaration::Mixin)
|
7
|
+
base.include(::Preact::Component::Api)
|
8
|
+
base.include(::Preact::Component::Callbacks)
|
9
|
+
base.include(::LucidComponent::Api)
|
10
|
+
base.include(::LucidApp::Api)
|
11
|
+
base.include(::LucidComponent::Initializer)
|
12
|
+
base.include(::LucidI18n::Mixin) if `("lucid_i18n/mixin" in Opal.modules)`
|
14
13
|
end
|
15
14
|
end
|
@@ -1,102 +1,100 @@
|
|
1
|
-
module LucidApp
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
base.while_loading_block = null;
|
1
|
+
module LucidApp::NativeComponentConstructor
|
2
|
+
# for should_component_update we apply ruby semantics for comparing props
|
3
|
+
# to do so, we convert the props to ruby hashes and then compare
|
4
|
+
# this makes sure, that for example rubys Nil object gets handled properly
|
5
|
+
def self.extended(base)
|
6
|
+
component_name = base.to_s
|
7
|
+
%x{
|
8
|
+
base.css_styles = null;
|
9
|
+
base.css_theme = null;
|
10
|
+
base.preload_block = null;
|
11
|
+
base.while_loading_block = null;
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
this[ref] = this[ref].bind(this);
|
46
|
-
} else {
|
47
|
-
this[ref] = Opal.global.Preact.createRef();
|
13
|
+
base.preact_component = class extends Opal.global.Preact.Component {
|
14
|
+
constructor(props) {
|
15
|
+
super(props);
|
16
|
+
const oper = Opal.Preact;
|
17
|
+
if (base.$default_state_defined()) {
|
18
|
+
this.state = base.$state().$to_n();
|
19
|
+
} else {
|
20
|
+
this.state = {};
|
21
|
+
};
|
22
|
+
this.state.isomorfeus_store_state = Opal.Isomorfeus.store.native.getState();
|
23
|
+
var current_store_state = this.state.isomorfeus_store_state;
|
24
|
+
if (typeof current_store_state.class_state[#{component_name}] !== "undefined") {
|
25
|
+
this.state.class_state = {};
|
26
|
+
this.state.class_state[#{component_name}] = current_store_state.class_state[#{component_name}];
|
27
|
+
} else {
|
28
|
+
this.state.class_state = {};
|
29
|
+
this.state.class_state[#{component_name}] = {};
|
30
|
+
};
|
31
|
+
this.__ruby_instance = base.$new(this);
|
32
|
+
var defined_refs = #{base.defined_refs};
|
33
|
+
for (var ref in defined_refs) {
|
34
|
+
if (defined_refs[ref] != null) {
|
35
|
+
let r = ref; // to ensure closure for function below gets correct ref name
|
36
|
+
this[ref] = function(element) {
|
37
|
+
element = oper.native_element_or_component_to_ruby(element);
|
38
|
+
oper.register_active_component(this);
|
39
|
+
try {
|
40
|
+
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
|
41
|
+
} catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
|
42
|
+
oper.unregister_active_component(this);
|
48
43
|
}
|
44
|
+
this[ref] = this[ref].bind(this);
|
45
|
+
} else {
|
46
|
+
this[ref] = Opal.global.Preact.createRef();
|
49
47
|
}
|
50
|
-
if (base.preload_block) {
|
51
|
-
oper.register_active_component(this);
|
52
|
-
this.state.preloaded = this.__ruby_instance.$execute_preload_block(); // caught in execute_preload_block itself
|
53
|
-
oper.unregister_active_component(this);
|
54
|
-
}
|
55
|
-
this.listener = this.listener.bind(this);
|
56
|
-
this.unsubscriber = Opal.Isomorfeus.store.native.subscribe(this.listener);
|
57
|
-
}
|
58
|
-
static get displayName() {
|
59
|
-
return #{component_name};
|
60
48
|
}
|
61
|
-
|
62
|
-
const oper = Opal.Preact;
|
63
|
-
oper.render_buffer.push([]);
|
49
|
+
if (base.preload_block) {
|
64
50
|
oper.register_active_component(this);
|
65
|
-
|
66
|
-
try {
|
67
|
-
if (base.while_loading_block && !state.preloaded) { block_result = #{`this.__ruby_instance`.instance_exec(&`base.while_loading_block`)}; }
|
68
|
-
else { block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)}; }
|
69
|
-
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
70
|
-
} catch (e) {
|
71
|
-
if (oper.using_did_catch) { throw e; }
|
72
|
-
else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
|
73
|
-
}
|
51
|
+
this.state.preloaded = this.__ruby_instance.$execute_preload_block(); // caught in execute_preload_block itself
|
74
52
|
oper.unregister_active_component(this);
|
75
|
-
let children = oper.render_buffer.pop();
|
76
|
-
return Opal.global.Preact.createElement(Opal.global.LucidApplicationContext.Provider, { value: { iso_store: this.state.isomorfeus_store_state, iso_theme: base.css_theme }}, children);
|
77
|
-
}
|
78
|
-
data_access() {
|
79
|
-
return this.state.isomorfeus_store_state;
|
80
|
-
}
|
81
|
-
listener() {
|
82
|
-
let next_state = Opal.Isomorfeus.store.native.getState();
|
83
|
-
this.setState({ isomorfeus_store_state: next_state });
|
84
|
-
}
|
85
|
-
componentWillUnmount() {
|
86
|
-
if (typeof this.unsubscriber === "function") { this.unsubscriber(); }
|
87
53
|
}
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
54
|
+
this.listener = this.listener.bind(this);
|
55
|
+
this.unsubscriber = Opal.Isomorfeus.store.native.subscribe(this.listener);
|
56
|
+
}
|
57
|
+
static get displayName() {
|
58
|
+
return #{component_name};
|
59
|
+
}
|
60
|
+
render(props, state) {
|
61
|
+
const oper = Opal.Preact;
|
62
|
+
oper.render_buffer.push([]);
|
63
|
+
oper.register_active_component(this);
|
64
|
+
let block_result;
|
65
|
+
try {
|
66
|
+
if (base.while_loading_block && !state.preloaded) { block_result = #{`this.__ruby_instance`.instance_exec(&`base.while_loading_block`)}; }
|
67
|
+
else { block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)}; }
|
68
|
+
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
69
|
+
} catch (e) {
|
70
|
+
if (oper.using_did_catch) { throw e; }
|
71
|
+
else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
|
97
72
|
}
|
73
|
+
oper.unregister_active_component(this);
|
74
|
+
let children = oper.render_buffer.pop();
|
75
|
+
return Opal.global.Preact.createElement(Opal.global.LucidApplicationContext.Provider, { value: { iso_store: this.state.isomorfeus_store_state, iso_theme: base.css_theme }}, children);
|
76
|
+
}
|
77
|
+
data_access() {
|
78
|
+
return this.state.isomorfeus_store_state;
|
79
|
+
}
|
80
|
+
listener() {
|
81
|
+
let next_state = Opal.Isomorfeus.store.native.getState();
|
82
|
+
this.setState({ isomorfeus_store_state: next_state });
|
83
|
+
}
|
84
|
+
componentWillUnmount() {
|
85
|
+
if (typeof this.unsubscriber === "function") { this.unsubscriber(); }
|
86
|
+
}
|
87
|
+
shouldComponentUpdate(next_props, next_state) {
|
88
|
+
if (!Opal.Preact.props_are_equal(this.props, next_props)) { return true; }
|
89
|
+
if (Opal.Preact.state_is_not_equal(this.state, next_state)) { return true; }
|
90
|
+
return false;
|
91
|
+
}
|
92
|
+
validateProp(props, propName, componentName) {
|
93
|
+
try { base.$validate_prop(propName, props[propName]) }
|
94
|
+
catch (e) { return new Error(componentName + ": Error: prop validation failed: " + e.message); }
|
95
|
+
return null;
|
98
96
|
}
|
99
97
|
}
|
100
|
-
|
98
|
+
}
|
101
99
|
end
|
102
100
|
end
|
@@ -1,123 +1,120 @@
|
|
1
|
-
module LucidComponent
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
attr_accessor :class_store
|
8
|
-
attr_accessor :store
|
1
|
+
module LucidComponent::Api
|
2
|
+
def self.included(base)
|
3
|
+
base.instance_exec do
|
4
|
+
# stores
|
5
|
+
attr_accessor :app_store
|
6
|
+
attr_accessor :class_store
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def class_store
|
9
|
+
@class_store ||= ::LucidComponent::ClassStoreProxy.new(self.to_s)
|
10
|
+
end
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
12
|
+
# preloading
|
13
|
+
def preload(&block)
|
14
|
+
`base.preload_block = block`
|
15
|
+
component_did_mount do
|
16
|
+
unless self.state.preloaded
|
17
|
+
@_preload_promise.then { self.state.preloaded = true } if @_preload_promise
|
21
18
|
end
|
22
19
|
end
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
22
|
+
def while_loading(option = nil, &block)
|
23
|
+
wl_block = proc do
|
24
|
+
if @_preload_promise && @_preload_promise.resolved?
|
25
|
+
instance_exec(&`base.render_block`)
|
26
|
+
else
|
27
|
+
instance_exec(&block)
|
31
28
|
end
|
32
|
-
`base.while_loading_block = wl_block`
|
33
29
|
end
|
30
|
+
`base.while_loading_block = wl_block`
|
31
|
+
end
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}
|
50
|
-
}
|
51
|
-
if (typeof styles_hash.$is_wrapped_style !== 'undefined') {
|
52
|
-
base.css_styles = styles_hash;
|
53
|
-
} else {
|
54
|
-
let css;
|
55
|
-
if (typeof styles_hash.$to_n === 'function') { css = styles_hash.$to_n(); }
|
56
|
-
else { css = styles_hash; }
|
57
|
-
let nano_styles = ogni.sheet(css, rule_name);
|
58
|
-
base.css_styles = #{::LucidComponent::StylesWrapper.new(`nano_styles`)};
|
33
|
+
# styles
|
34
|
+
def styles(styles_hash = nil, &block)
|
35
|
+
styles_hash = block.call if block_given?
|
36
|
+
if styles_hash
|
37
|
+
component_name = self.to_s
|
38
|
+
%x{
|
39
|
+
let rule_name = component_name.replace(/:/g, '_');
|
40
|
+
let ogni = Opal.global.NanoCSSInstance;
|
41
|
+
if (base.css_styles && #{Isomorfeus.production?}) { return base.css_styles; }
|
42
|
+
else if(#{Isomorfeus.development?}) {
|
43
|
+
if (#{on_browser?}) {
|
44
|
+
ogni.delete_from_sheet(rule_name);
|
45
|
+
ogni.delete_from_rule_blocks(rule_name);
|
46
|
+
ogni.hydrate_force_put = true;
|
59
47
|
}
|
60
48
|
}
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
49
|
+
if (typeof styles_hash.$is_wrapped_style !== 'undefined') {
|
50
|
+
base.css_styles = styles_hash;
|
51
|
+
} else {
|
52
|
+
let css;
|
53
|
+
if (typeof styles_hash.$to_n === 'function') { css = styles_hash.$to_n(); }
|
54
|
+
else { css = styles_hash; }
|
55
|
+
let nano_styles = ogni.sheet(css, rule_name);
|
56
|
+
base.css_styles = #{::LucidComponent::StylesWrapper.new(`nano_styles`)};
|
57
|
+
}
|
65
58
|
}
|
66
59
|
end
|
67
|
-
|
60
|
+
%x{
|
61
|
+
if (!base.css_styles) { return nil; }
|
62
|
+
return base.css_styles;
|
63
|
+
}
|
68
64
|
end
|
65
|
+
alias_method :styles=, :styles
|
66
|
+
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
68
|
+
# stores
|
69
|
+
def local_store
|
70
|
+
LocalStore
|
71
|
+
end
|
74
72
|
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
def session_store
|
74
|
+
SessionStore
|
75
|
+
end
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
def theme
|
78
|
+
props.theme
|
79
|
+
end
|
82
80
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
@_preload_promise.resolved?
|
99
|
-
else
|
100
|
-
false
|
81
|
+
# preloading
|
82
|
+
def execute_preload_block
|
83
|
+
begin
|
84
|
+
@_preload_promise = instance_exec(&self.class.JS[:preload_block])
|
85
|
+
rescue => e
|
86
|
+
%x{
|
87
|
+
console.error(e.message);
|
88
|
+
console.error(e.stack);
|
89
|
+
}
|
90
|
+
end
|
91
|
+
if @_preload_promise
|
92
|
+
@_preload_promise.fail do |result|
|
93
|
+
err_text = "#{self.class.name}: preloading failed, last result: #{result.nil? ? 'nil' : result}!"
|
94
|
+
`console.error(err_text)`
|
101
95
|
end
|
96
|
+
@_preload_promise.resolved?
|
97
|
+
else
|
98
|
+
false
|
102
99
|
end
|
100
|
+
end
|
103
101
|
|
104
|
-
|
105
|
-
|
106
|
-
|
102
|
+
def preloaded?
|
103
|
+
!!state.preloaded
|
104
|
+
end
|
107
105
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
106
|
+
# styles
|
107
|
+
def styles
|
108
|
+
%x{
|
109
|
+
let c = self.$class()
|
110
|
+
if (typeof(c.css_styles) === 'undefined') { return nil; }
|
111
|
+
return c.css_styles;
|
112
|
+
}
|
113
|
+
end
|
116
114
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
115
|
+
# requires transport
|
116
|
+
def current_user
|
117
|
+
Isomorfeus.current_user
|
121
118
|
end
|
122
119
|
end
|
123
120
|
end
|
@@ -1,12 +1,9 @@
|
|
1
|
-
module LucidComponent
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@props = `Opal.Preact.Props.$new(#@native)`
|
9
|
-
@state = `Opal.Preact.State.$new(#@native)`
|
10
|
-
end
|
1
|
+
module LucidComponent::Initializer
|
2
|
+
def initialize(native_component)
|
3
|
+
@native = native_component
|
4
|
+
@app_store = LucidComponent::AppStoreProxy.new(self)
|
5
|
+
@class_store = LucidComponent::ClassStoreProxy.new(self.class.to_s, self, @native)
|
6
|
+
@props = `Opal.Preact.Props.$new(#@native)`
|
7
|
+
@state = `Opal.Preact.State.$new(#@native)`
|
11
8
|
end
|
12
9
|
end
|