isomorfeus-preact 10.6.30 → 10.6.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/isomorfeus/preact_view_helper.rb +9 -7
  4. data/lib/isomorfeus-preact.rb +15 -0
  5. data/lib/isomorfeus_preact/lucid_app/api.rb +30 -32
  6. data/lib/isomorfeus_preact/lucid_app/mixin.rb +12 -13
  7. data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +88 -90
  8. data/lib/isomorfeus_preact/lucid_component/api.rb +96 -98
  9. data/lib/isomorfeus_preact/lucid_component/initializer.rb +8 -10
  10. data/lib/isomorfeus_preact/lucid_component/mixin.rb +11 -12
  11. data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +77 -79
  12. data/lib/isomorfeus_preact/lucid_func/initializer.rb +7 -9
  13. data/lib/isomorfeus_preact/lucid_func/mixin.rb +8 -9
  14. data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +49 -51
  15. data/lib/isomorfeus_preact/preact/function_component/api.rb +102 -106
  16. data/lib/isomorfeus_preact/preact/function_component/base.rb +5 -7
  17. data/lib/isomorfeus_preact/preact/function_component/initializer.rb +4 -8
  18. data/lib/isomorfeus_preact/preact/function_component/mixin.rb +6 -10
  19. data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +41 -45
  20. data/lib/preact/component/api.rb +99 -103
  21. data/lib/preact/component/base.rb +5 -7
  22. data/lib/preact/component/callbacks.rb +99 -103
  23. data/lib/preact/component/initializer.rb +5 -9
  24. data/lib/preact/component/mixin.rb +9 -13
  25. data/lib/preact/component/native_component_constructor.rb +67 -71
  26. data/lib/preact/component_resolution.rb +78 -80
  27. data/lib/preact/elements.rb +55 -57
  28. data/lib/preact/version.rb +1 -1
  29. data/node_modules/.package-lock.json +3 -3
  30. data/node_modules/preact/compat/LICENSE +21 -0
  31. data/node_modules/preact/compat/jsx-dev-runtime.js +2 -0
  32. data/node_modules/preact/compat/jsx-dev-runtime.mjs +2 -0
  33. data/node_modules/preact/compat/jsx-runtime.js +2 -0
  34. data/node_modules/preact/compat/jsx-runtime.mjs +2 -0
  35. data/node_modules/preact/debug/LICENSE +21 -0
  36. data/node_modules/preact/devtools/LICENSE +21 -0
  37. data/node_modules/preact/devtools/dist/devtools.js +1 -1
  38. data/node_modules/preact/devtools/dist/devtools.js.map +1 -1
  39. data/node_modules/preact/devtools/dist/devtools.mjs +1 -1
  40. data/node_modules/preact/devtools/dist/devtools.module.js +1 -1
  41. data/node_modules/preact/devtools/dist/devtools.module.js.map +1 -1
  42. data/node_modules/preact/devtools/dist/devtools.umd.js +1 -1
  43. data/node_modules/preact/devtools/dist/devtools.umd.js.map +1 -1
  44. data/node_modules/preact/devtools/src/devtools.js +1 -1
  45. data/node_modules/preact/dist/preact.js +1 -1
  46. data/node_modules/preact/dist/preact.js.map +1 -1
  47. data/node_modules/preact/dist/preact.min.js +1 -1
  48. data/node_modules/preact/dist/preact.min.js.map +1 -1
  49. data/node_modules/preact/dist/preact.mjs +1 -1
  50. data/node_modules/preact/dist/preact.module.js +1 -1
  51. data/node_modules/preact/dist/preact.module.js.map +1 -1
  52. data/node_modules/preact/dist/preact.umd.js +1 -1
  53. data/node_modules/preact/dist/preact.umd.js.map +1 -1
  54. data/node_modules/preact/hooks/LICENSE +21 -0
  55. data/node_modules/preact/jsx-runtime/LICENSE +21 -0
  56. data/node_modules/preact/package.json +1 -1
  57. data/node_modules/preact/src/diff/index.js +6 -3
  58. data/package.json +1 -1
  59. metadata +19 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 261bf828fca3276232e1cc9a57f32cb6bd45ddd0fa2d386c42dc799813a5f110
4
- data.tar.gz: a18cdda3bbb233fd376f90c0cabda7637cd110a34697e2a2d7710e78249775db
3
+ metadata.gz: 94d90b7804579f6dd573ec4878ad1d0f4579a7541eefb6b8a7874ca115b36951
4
+ data.tar.gz: 835a4f9d89c1f0cdd2bc3e7f909481ed182fb4cbd8d5aaf545744280645c16aa
5
5
  SHA512:
6
- metadata.gz: a76b3e58d5d4fd34409126b93487eb8f257509f6c9ff4697248c60333d51c416b1232bc78c4e72d694fbbab5b2392405cdda5aa40310f500e0a53e8d7e61e76b
7
- data.tar.gz: ea99ad3ec25838e3c6c94d971e529fe92b7ba7597e685578fcd097a62a852e095faae7f10d18d7822d5880510350ac1997578818d4cde8ae9a45bd2ec9a8f971
6
+ metadata.gz: 2ec9097e4dfae922a7d665831a90ded698c549f1ac1cbde91912bce844b7124c7de6a4eaaade509624e4a44e56f265fe0c1625daec89375313a91f8d2cae9a29
7
+ data.tar.gz: b4219dd2ad74032549c276a29d4388058175ea4baf161dfee8c2f5ad7d4181314895289917b2db4e898375130940ab8fd6a244b062c153891cb4586d8c548cb8
data/README.md CHANGED
@@ -7,7 +7,7 @@ Isomorfeus Preact<br/>
7
7
  Develop Preact components for Opal Ruby along with very easy to use and advanced Preact-Redux Components.
8
8
 
9
9
  ## Community and Support
10
- At the [Isomorfeus Framework Project](http://isomorfeus.com)
10
+ At the [Isomorfeus Framework Project](https://isomorfeus.com)
11
11
 
12
12
  ## Versioning and Compatibility
13
13
  isomorfeus-preact version follows the Preact version which features and API it implements.
@@ -60,7 +60,9 @@ module Isomorfeus
60
60
  global.Exception = false;
61
61
  global.IsomorfeusSessionId = '#{Thread.current[:isomorfeus_session_id]}';
62
62
  global.Opal.Isomorfeus['$env=']('#{Isomorfeus.env}');
63
- if (typeof global.Opal.Isomorfeus.$negotiated_locale === 'function') {
63
+ if (typeof global.Opal.Isomorfeus["$current_locale="] === 'function') {
64
+ global.Opal.Isomorfeus["$current_locale="]('#{props[:locale]}');
65
+ } else if (typeof global.Opal.Isomorfeus["$negotiated_locale="] === 'function') { // remove later on
64
66
  global.Opal.Isomorfeus["$negotiated_locale="]('#{props[:locale]}');
65
67
  }
66
68
  global.Opal.Isomorfeus['$force_init!']();
@@ -124,11 +126,11 @@ module Isomorfeus
124
126
  let rendered_tree;
125
127
  let ssr_styles;
126
128
  let component;
127
- try {
128
- rendered_tree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)});
129
- } catch (e) {
130
- global.Exception = e;
131
- }
129
+ try {
130
+ rendered_tree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)});
131
+ } catch (e) {
132
+ global.Exception = e;
133
+ }
132
134
  let application_state = global.Opal.Isomorfeus.store.native.getState();
133
135
  let transport_busy = false;
134
136
  if (typeof global.Opal.Isomorfeus.Transport !== 'undefined' && global.Opal.Isomorfeus.Transport["$busy?"]()) { transport_busy = true; }
@@ -171,7 +173,7 @@ module Isomorfeus
171
173
  if Isomorfeus.server_side_rendering
172
174
  render_result = "<script type='application/javascript'>\nServerSideRenderingStateJSON = #{Oj.dump(application_state, mode: :strict)}\n</script>\n" << render_result
173
175
  end
174
- STDERR.puts "PreactViewHelper Server Side Rendering rendered #{pass} passes and took ~#{Time.now - start_time}s" if Isomorfeus.development? && !skip_ssr
176
+ STDERR.puts "PreactViewHelper Server Side Rendering rendered #{pass} passes and took ~#{((Time.now - start_time)*1000).to_i}ms" if Isomorfeus.development? && !skip_ssr
175
177
  render_result
176
178
  end
177
179
 
@@ -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
- module Api
3
- def self.included(base)
4
- base.instance_exec do
5
- def theme(theme_hash = nil, &block)
6
- theme_hash = block.call if block_given?
7
- if theme_hash
8
- component_name = self.to_s
9
- %x{
10
- let rule_name = component_name.replace(/:/g, '_');
11
- let ogni = Opal.global.NanoCSSInstance;
12
- if (base.css_theme && #{Isomorfeus.production?}) { return base.css_theme; }
13
- else if(#{Isomorfeus.development?}) {
14
- if (#{on_browser?}) {
15
- ogni.delete_from_sheet(rule_name);
16
- ogni.delete_from_rule_blocks(rule_name);
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
- end
31
- %x{
32
- if (!base.css_theme) { return nil; }
33
- return base.css_theme;
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
- alias_method :theme=, :theme
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
- module Mixin
3
- def self.included(base)
4
- base.include(::Native::Wrapper)
5
- base.extend(::LucidApp::NativeComponentConstructor)
6
- base.include(::Preact::Elements)
7
- base.extend(::LucidPropDeclaration::Mixin)
8
- base.include(::Preact::Component::Api)
9
- base.include(::Preact::Component::Callbacks)
10
- base.include(::LucidComponent::Api)
11
- base.include(::LucidApp::Api)
12
- base.include(::LucidComponent::Initializer)
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
- 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
- %x{
9
- base.css_styles = null;
10
- base.css_theme = null;
11
- base.preload_block = null;
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
- base.preact_component = class extends Opal.global.Preact.Component {
15
- constructor(props) {
16
- super(props);
17
- const oper = Opal.Preact;
18
- if (base.$default_state_defined()) {
19
- this.state = base.$state().$to_n();
20
- } else {
21
- this.state = {};
22
- };
23
- this.state.isomorfeus_store_state = Opal.Isomorfeus.store.native.getState();
24
- var current_store_state = this.state.isomorfeus_store_state;
25
- if (typeof current_store_state.class_state[#{component_name}] !== "undefined") {
26
- this.state.class_state = {};
27
- this.state.class_state[#{component_name}] = current_store_state.class_state[#{component_name}];
28
- } else {
29
- this.state.class_state = {};
30
- this.state.class_state[#{component_name}] = {};
31
- };
32
- this.__ruby_instance = base.$new(this);
33
- var defined_refs = #{base.defined_refs};
34
- for (var ref in defined_refs) {
35
- if (defined_refs[ref] != null) {
36
- let r = ref; // to ensure closure for function below gets correct ref name
37
- this[ref] = function(element) {
38
- element = oper.native_element_or_component_to_ruby(element);
39
- oper.register_active_component(this);
40
- try {
41
- #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
42
- } catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
43
- oper.unregister_active_component(this);
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
- render(props, state) {
62
- const oper = Opal.Preact;
63
- oper.render_buffer.push([]);
49
+ if (base.preload_block) {
64
50
  oper.register_active_component(this);
65
- let block_result;
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
- shouldComponentUpdate(next_props, next_state) {
89
- if (!Opal.Preact.props_are_equal(this.props, next_props)) { return true; }
90
- if (Opal.Preact.state_is_not_equal(this.state, next_state)) { return true; }
91
- return false;
92
- }
93
- validateProp(props, propName, componentName) {
94
- try { base.$validate_prop(propName, props[propName]) }
95
- catch (e) { return new Error(componentName + ": Error: prop validation failed: " + e.message); }
96
- return null;
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
- end
98
+ }
101
99
  end
102
100
  end
@@ -1,123 +1,121 @@
1
- module LucidComponent
2
- module Api
3
- def self.included(base)
4
- base.instance_exec do
5
- # stores
6
- attr_accessor :app_store
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
7
+ attr_accessor :store
9
8
 
10
- def class_store
11
- @class_store ||= ::LucidComponent::ClassStoreProxy.new(self.to_s)
12
- end
9
+ def class_store
10
+ @class_store ||= ::LucidComponent::ClassStoreProxy.new(self.to_s)
11
+ end
13
12
 
14
- # preloading
15
- def preload(&block)
16
- `base.preload_block = block`
17
- component_did_mount do
18
- unless self.state.preloaded
19
- @_preload_promise.then { self.state.preloaded = true } if @_preload_promise
20
- end
13
+ # preloading
14
+ def preload(&block)
15
+ `base.preload_block = block`
16
+ component_did_mount do
17
+ unless self.state.preloaded
18
+ @_preload_promise.then { self.state.preloaded = true } if @_preload_promise
21
19
  end
22
20
  end
21
+ end
23
22
 
24
- def while_loading(option = nil, &block)
25
- wl_block = proc do
26
- if @_preload_promise && @_preload_promise.resolved?
27
- instance_exec(&`base.render_block`)
28
- else
29
- instance_exec(&block)
30
- end
23
+ def while_loading(option = nil, &block)
24
+ wl_block = proc do
25
+ if @_preload_promise && @_preload_promise.resolved?
26
+ instance_exec(&`base.render_block`)
27
+ else
28
+ instance_exec(&block)
31
29
  end
32
- `base.while_loading_block = wl_block`
33
30
  end
31
+ `base.while_loading_block = wl_block`
32
+ end
34
33
 
35
- # styles
36
- def styles(styles_hash = nil, &block)
37
- styles_hash = block.call if block_given?
38
- if styles_hash
39
- component_name = self.to_s
40
- %x{
41
- let rule_name = component_name.replace(/:/g, '_');
42
- let ogni = Opal.global.NanoCSSInstance;
43
- if (base.css_styles && #{Isomorfeus.production?}) { return base.css_styles; }
44
- else if(#{Isomorfeus.development?}) {
45
- if (#{on_browser?}) {
46
- ogni.delete_from_sheet(rule_name);
47
- ogni.delete_from_rule_blocks(rule_name);
48
- ogni.hydrate_force_put = true;
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`)};
34
+ # styles
35
+ def styles(styles_hash = nil, &block)
36
+ styles_hash = block.call if block_given?
37
+ if styles_hash
38
+ component_name = self.to_s
39
+ %x{
40
+ let rule_name = component_name.replace(/:/g, '_');
41
+ let ogni = Opal.global.NanoCSSInstance;
42
+ if (base.css_styles && #{Isomorfeus.production?}) { return base.css_styles; }
43
+ else if(#{Isomorfeus.development?}) {
44
+ if (#{on_browser?}) {
45
+ ogni.delete_from_sheet(rule_name);
46
+ ogni.delete_from_rule_blocks(rule_name);
47
+ ogni.hydrate_force_put = true;
59
48
  }
60
49
  }
61
- end
62
- %x{
63
- if (!base.css_styles) { return nil; }
64
- return base.css_styles;
50
+ if (typeof styles_hash.$is_wrapped_style !== 'undefined') {
51
+ base.css_styles = styles_hash;
52
+ } else {
53
+ let css;
54
+ if (typeof styles_hash.$to_n === 'function') { css = styles_hash.$to_n(); }
55
+ else { css = styles_hash; }
56
+ let nano_styles = ogni.sheet(css, rule_name);
57
+ base.css_styles = #{::LucidComponent::StylesWrapper.new(`nano_styles`)};
58
+ }
65
59
  }
66
60
  end
67
- alias_method :styles=, :styles
61
+ %x{
62
+ if (!base.css_styles) { return nil; }
63
+ return base.css_styles;
64
+ }
68
65
  end
66
+ alias_method :styles=, :styles
67
+ end
69
68
 
70
- # stores
71
- def local_store
72
- LocalStore
73
- end
69
+ # stores
70
+ def local_store
71
+ LocalStore
72
+ end
74
73
 
75
- def session_store
76
- SessionStore
77
- end
74
+ def session_store
75
+ SessionStore
76
+ end
78
77
 
79
- def theme
80
- props.theme
81
- end
78
+ def theme
79
+ props.theme
80
+ end
82
81
 
83
- # preloading
84
- def execute_preload_block
85
- begin
86
- @_preload_promise = instance_exec(&self.class.JS[:preload_block])
87
- rescue => e
88
- %x{
89
- console.error(e.message);
90
- console.error(e.stack);
91
- }
92
- end
93
- if @_preload_promise
94
- @_preload_promise.fail do |result|
95
- err_text = "#{self.class.name}: preloading failed, last result: #{result.nil? ? 'nil' : result}!"
96
- `console.error(err_text)`
97
- end
98
- @_preload_promise.resolved?
99
- else
100
- false
82
+ # preloading
83
+ def execute_preload_block
84
+ begin
85
+ @_preload_promise = instance_exec(&self.class.JS[:preload_block])
86
+ rescue => e
87
+ %x{
88
+ console.error(e.message);
89
+ console.error(e.stack);
90
+ }
91
+ end
92
+ if @_preload_promise
93
+ @_preload_promise.fail do |result|
94
+ err_text = "#{self.class.name}: preloading failed, last result: #{result.nil? ? 'nil' : result}!"
95
+ `console.error(err_text)`
101
96
  end
97
+ @_preload_promise.resolved?
98
+ else
99
+ false
102
100
  end
101
+ end
103
102
 
104
- def preloaded?
105
- !!state.preloaded
106
- end
103
+ def preloaded?
104
+ !!state.preloaded
105
+ end
107
106
 
108
- # styles
109
- def styles
110
- %x{
111
- let c = self.$class()
112
- if (typeof(c.css_styles) === 'undefined') { return nil; }
113
- return c.css_styles;
114
- }
115
- end
107
+ # styles
108
+ def styles
109
+ %x{
110
+ let c = self.$class()
111
+ if (typeof(c.css_styles) === 'undefined') { return nil; }
112
+ return c.css_styles;
113
+ }
114
+ end
116
115
 
117
- # requires transport
118
- def current_user
119
- Isomorfeus.current_user
120
- end
116
+ # requires transport
117
+ def current_user
118
+ Isomorfeus.current_user
121
119
  end
122
120
  end
123
121
  end
@@ -1,12 +1,10 @@
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
- @store = LucidComponent::InstanceStoreProxy.new(self)
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
+ @store = LucidComponent::InstanceStoreProxy.new(self)
7
+ @props = `Opal.Preact.Props.$new(#@native)`
8
+ @state = `Opal.Preact.State.$new(#@native)`
11
9
  end
12
10
  end
@@ -1,14 +1,13 @@
1
- module LucidComponent
2
- module Mixin
3
- def self.included(base)
4
- base.include(::Native::Wrapper)
5
- base.extend(::LucidComponent::NativeComponentConstructor)
6
- base.include(::Preact::Elements)
7
- base.extend(::LucidPropDeclaration::Mixin)
8
- base.include(::Preact::Component::Api)
9
- base.include(::Preact::Component::Callbacks)
10
- base.include(::LucidComponent::Api)
11
- base.include(::LucidComponent::Initializer)
12
- end
1
+ module LucidComponent::Mixin
2
+ def self.included(base)
3
+ base.include(::Native::Wrapper)
4
+ base.extend(::LucidComponent::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(::LucidComponent::Initializer)
11
+ base.include(::LucidI18n::Mixin) if `("lucid_i18n/mixin" in Opal.modules)`
13
12
  end
14
13
  end