isomorfeus-preact 10.6.32 → 10.6.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isomorfeus-preact.rb +15 -0
  3. data/lib/isomorfeus_preact/lucid_app/api.rb +30 -32
  4. data/lib/isomorfeus_preact/lucid_app/mixin.rb +12 -13
  5. data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +88 -90
  6. data/lib/isomorfeus_preact/lucid_component/api.rb +96 -98
  7. data/lib/isomorfeus_preact/lucid_component/initializer.rb +8 -10
  8. data/lib/isomorfeus_preact/lucid_component/mixin.rb +11 -12
  9. data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +77 -79
  10. data/lib/isomorfeus_preact/lucid_func/initializer.rb +7 -9
  11. data/lib/isomorfeus_preact/lucid_func/mixin.rb +8 -9
  12. data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +49 -51
  13. data/lib/isomorfeus_preact/preact/function_component/api.rb +102 -106
  14. data/lib/isomorfeus_preact/preact/function_component/base.rb +5 -7
  15. data/lib/isomorfeus_preact/preact/function_component/initializer.rb +4 -8
  16. data/lib/isomorfeus_preact/preact/function_component/mixin.rb +6 -10
  17. data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +41 -45
  18. data/lib/preact/component/api.rb +99 -103
  19. data/lib/preact/component/base.rb +5 -7
  20. data/lib/preact/component/callbacks.rb +99 -103
  21. data/lib/preact/component/initializer.rb +5 -9
  22. data/lib/preact/component/mixin.rb +9 -13
  23. data/lib/preact/component/native_component_constructor.rb +67 -71
  24. data/lib/preact/component_resolution.rb +78 -80
  25. data/lib/preact/elements.rb +55 -57
  26. data/lib/preact/version.rb +1 -1
  27. metadata +1 -1
@@ -1,51 +1,47 @@
1
- module Preact
2
- module FunctionComponent
3
- module NativeComponentConstructor
4
- def self.extended(base)
5
- component_name = base.to_s
6
- %x{
7
- base.instance_init = function(initial) {
8
- let ruby_state = { instance: #{base.new(`{}`)} };
9
- ruby_state.instance.__ruby_instance = ruby_state.instance;
10
- return ruby_state;
11
- }
12
- base.instance_reducer = function(state, action) { return state; }
13
- base.preact_component = function(props) {
14
- const oper = Opal.Preact;
15
- oper.render_buffer.push([]);
16
- const [__ruby_state, __ruby_dispatch] = Opal.global.PreactHooks.useReducer(base.instance_reducer, null, base.instance_init);
17
- const __ruby_instance = __ruby_state.instance;
18
- __ruby_instance.props = props;
19
- oper.register_active_component(__ruby_instance);
20
- try {
21
- let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
22
- if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
23
- } catch (e) {
24
- if (oper.using_did_catch) { throw e; }
25
- else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
26
- }
27
- oper.unregister_active_component(__ruby_instance);
28
- let result = oper.render_buffer.pop();
29
- return (result.length === 1) ? result[0] : result;
30
- }
31
- base.preact_component.displayName = #{component_name};
1
+ module Preact::FunctionComponent::NativeComponentConstructor
2
+ def self.extended(base)
3
+ component_name = base.to_s
4
+ %x{
5
+ base.instance_init = function(initial) {
6
+ let ruby_state = { instance: #{base.new(`{}`)} };
7
+ ruby_state.instance.__ruby_instance = ruby_state.instance;
8
+ return ruby_state;
9
+ }
10
+ base.instance_reducer = function(state, action) { return state; }
11
+ base.preact_component = function(props) {
12
+ const oper = Opal.Preact;
13
+ oper.render_buffer.push([]);
14
+ const [__ruby_state, __ruby_dispatch] = Opal.global.PreactHooks.useReducer(base.instance_reducer, null, base.instance_init);
15
+ const __ruby_instance = __ruby_state.instance;
16
+ __ruby_instance.props = props;
17
+ oper.register_active_component(__ruby_instance);
18
+ try {
19
+ let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
20
+ if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
21
+ } catch (e) {
22
+ if (oper.using_did_catch) { throw e; }
23
+ else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
32
24
  }
25
+ oper.unregister_active_component(__ruby_instance);
26
+ let result = oper.render_buffer.pop();
27
+ return (result.length === 1) ? result[0] : result;
28
+ }
29
+ base.preact_component.displayName = #{component_name};
30
+ }
33
31
 
34
- base_module = base.to_s.deconstantize
35
- if base_module != ''
36
- base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
37
- `Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
38
- end
39
- else
40
- Object.define_method(base.to_s) do |*args, &block|
41
- `Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
42
- end
43
- end
44
-
45
- def render(&block)
46
- `base.render_block = #{block}`
47
- end
32
+ base_module = base.to_s.deconstantize
33
+ if base_module != ''
34
+ base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
35
+ `Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
36
+ end
37
+ else
38
+ Object.define_method(base.to_s) do |*args, &block|
39
+ `Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
48
40
  end
49
41
  end
42
+
43
+ def render(&block)
44
+ `base.render_block = #{block}`
45
+ end
50
46
  end
51
47
  end
@@ -1,124 +1,120 @@
1
- module Preact
2
- module Component
3
- module Api
4
- def self.included(base)
5
- base.instance_exec do
6
- base_module = base.to_s.deconstantize
7
- if base_module != ''
8
- base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
9
- `Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
10
- end
11
- else
12
- Object.define_method(base.to_s) do |*args, &block|
13
- `Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
14
- end
15
- end
16
-
17
- attr_accessor :props
18
- attr_accessor :state
19
-
20
- def ref(ref_name, &block)
21
- defined_refs.JS[ref_name] = block_given? ? block : `null`
22
- end
23
-
24
- def defined_refs
25
- @defined_refs ||= `{}`
26
- end
27
-
28
- def default_state_defined
29
- @default_state_defined
30
- end
31
-
32
- def state
33
- return @default_state if @default_state
34
- @default_state_defined = true
35
- %x{
36
- var native_state = {state: {}};
37
- native_state.setState = function(new_state, callback) {
38
- for (var key in new_state) {
39
- this.state[key] = new_state[key];
40
- }
41
- if (callback) { callback.call(); }
42
- }
43
- }
44
- @default_state = `Opal.Preact.State.$new(native_state)`
45
- end
46
-
47
- def render(&block)
48
- `base.render_block = #{block}`
49
- end
50
-
51
- def should_component_update?(&block)
52
- `base.should_component_update_block = block`
53
- end
1
+ module Preact::Component::Api
2
+ def self.included(base)
3
+ base.instance_exec do
4
+ base_module = base.to_s.deconstantize
5
+ if base_module != ''
6
+ base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
7
+ `Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
8
+ end
9
+ else
10
+ Object.define_method(base.to_s) do |*args, &block|
11
+ `Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
54
12
  end
55
13
  end
56
14
 
57
- def display_name
58
- @native.JS[:displayName]
15
+ attr_accessor :props
16
+ attr_accessor :state
17
+
18
+ def ref(ref_name, &block)
19
+ defined_refs.JS[ref_name] = block_given? ? block : `null`
59
20
  end
60
21
 
61
- def force_update(&block)
62
- if block_given?
63
- # this maybe needs instance_exec too
64
- @native.JS.forceUpdate(`function() { block.$call(); }`)
65
- else
66
- @native.JS.forceUpdate
67
- end
22
+ def defined_refs
23
+ @defined_refs ||= `{}`
68
24
  end
69
25
 
70
- def get_preact_element(arg, &block)
71
- if block_given?
72
- # execute block, fetch last element from buffer
73
- %x{
74
- let last_buffer_length = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].length;
75
- let last_buffer_element = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1][last_buffer_length - 1];
76
- block.$call();
77
- // console.log("get_preact_element popping", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())
78
- let new_element = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].pop();
79
- if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any Preact element!")} }
80
- return new_element;
81
- }
82
- else
83
- # element was rendered before being passed as arg
84
- # fetch last element from buffer
85
- # `console.log("get_preact_element popping", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())`
86
- `Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].pop()`
87
- end
26
+ def default_state_defined
27
+ @default_state_defined
88
28
  end
89
- alias gpe get_preact_element
90
29
 
91
- def method_ref(method_symbol, *args)
92
- method_key = "#{method_symbol}#{args}"
30
+ def state
31
+ return @default_state if @default_state
32
+ @default_state_defined = true
93
33
  %x{
94
- if (#@native.method_refs && #@native.method_refs[#{method_key}]) { return #@native.method_refs[#{method_key}]; }
95
- if (!#@native.method_refs) { #@native.method_refs = {}; }
96
- #@native.method_refs[#{method_key}] = { m: #{method(method_symbol)}, a: args };
97
- return #@native.method_refs[#{method_key}];
34
+ var native_state = {state: {}};
35
+ native_state.setState = function(new_state, callback) {
36
+ for (var key in new_state) {
37
+ this.state[key] = new_state[key];
38
+ }
39
+ if (callback) { callback.call(); }
40
+ }
98
41
  }
42
+ @default_state = `Opal.Preact.State.$new(native_state)`
99
43
  end
100
- alias m_ref method_ref
101
44
 
102
- def render_preact_element(el)
103
- # push el to buffer
104
- `Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].push(el)`
105
- # `console.log("render_preact_element pushed", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())`
106
- nil
45
+ def render(&block)
46
+ `base.render_block = #{block}`
107
47
  end
108
- alias rpe render_preact_element
109
48
 
110
- def ref(name)
111
- `#@native[name]`
49
+ def should_component_update?(&block)
50
+ `base.should_component_update_block = block`
112
51
  end
52
+ end
53
+ end
113
54
 
114
- def ruby_ref(name)
115
- return `#@native[name]` if `(typeof #@native[name] === 'function')`
116
- `Opal.Preact.Ref.$new(#@native[name])`
117
- end
55
+ def display_name
56
+ @native.JS[:displayName]
57
+ end
118
58
 
119
- def set_state(updater, &callback)
120
- @state.set_state(updater, &callback)
121
- end
59
+ def force_update(&block)
60
+ if block_given?
61
+ # this maybe needs instance_exec too
62
+ @native.JS.forceUpdate(`function() { block.$call(); }`)
63
+ else
64
+ @native.JS.forceUpdate
65
+ end
66
+ end
67
+
68
+ def get_preact_element(arg, &block)
69
+ if block_given?
70
+ # execute block, fetch last element from buffer
71
+ %x{
72
+ let last_buffer_length = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].length;
73
+ let last_buffer_element = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1][last_buffer_length - 1];
74
+ block.$call();
75
+ // console.log("get_preact_element popping", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())
76
+ let new_element = Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].pop();
77
+ if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any Preact element!")} }
78
+ return new_element;
79
+ }
80
+ else
81
+ # element was rendered before being passed as arg
82
+ # fetch last element from buffer
83
+ # `console.log("get_preact_element popping", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())`
84
+ `Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].pop()`
122
85
  end
123
86
  end
87
+ alias gpe get_preact_element
88
+
89
+ def method_ref(method_symbol, *args)
90
+ method_key = "#{method_symbol}#{args}"
91
+ %x{
92
+ if (#@native.method_refs && #@native.method_refs[#{method_key}]) { return #@native.method_refs[#{method_key}]; }
93
+ if (!#@native.method_refs) { #@native.method_refs = {}; }
94
+ #@native.method_refs[#{method_key}] = { m: #{method(method_symbol)}, a: args };
95
+ return #@native.method_refs[#{method_key}];
96
+ }
97
+ end
98
+ alias m_ref method_ref
99
+
100
+ def render_preact_element(el)
101
+ # push el to buffer
102
+ `Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].push(el)`
103
+ # `console.log("render_preact_element pushed", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())`
104
+ nil
105
+ end
106
+ alias rpe render_preact_element
107
+
108
+ def ref(name)
109
+ `#@native[name]`
110
+ end
111
+
112
+ def ruby_ref(name)
113
+ return `#@native[name]` if `(typeof #@native[name] === 'function')`
114
+ `Opal.Preact.Ref.$new(#@native[name])`
115
+ end
116
+
117
+ def set_state(updater, &callback)
118
+ @state.set_state(updater, &callback)
119
+ end
124
120
  end
@@ -1,9 +1,7 @@
1
- module Preact
2
- module Component
3
- class Base
4
- def self.inherited(base)
5
- base.include(::Preact::Component::Mixin)
6
- end
1
+ module Preact::Component
2
+ class Base
3
+ def self.inherited(base)
4
+ base.include(::Preact::Component::Mixin)
7
5
  end
8
6
  end
9
- end
7
+ end
@@ -1,114 +1,110 @@
1
- module Preact
2
- module Component
3
- module Callbacks
4
- def self.included(base)
5
- base.instance_exec do
6
- def component_did_catch(&block)
7
- # TODO convert error
8
- %x{
9
- var fun = function(error) {
10
- Opal.Preact.register_active_component(this);
11
- try {
12
- #{`this.__ruby_instance`.instance_exec(`error`, &block)};
13
- } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
14
- Opal.Preact.unregister_active_component(this);
15
- }
16
- if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidCatch = fun; }
17
- else { self.preact_component.prototype.componentDidCatch = fun; }
18
- Opal.Preact.using_did_catch = true;
19
- }
20
- end
1
+ module Preact::Component::Callbacks
2
+ def self.included(base)
3
+ base.instance_exec do
4
+ def component_did_catch(&block)
5
+ # TODO convert error
6
+ %x{
7
+ var fun = function(error) {
8
+ Opal.Preact.register_active_component(this);
9
+ try {
10
+ #{`this.__ruby_instance`.instance_exec(`error`, &block)};
11
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
12
+ Opal.Preact.unregister_active_component(this);
13
+ }
14
+ if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidCatch = fun; }
15
+ else { self.preact_component.prototype.componentDidCatch = fun; }
16
+ Opal.Preact.using_did_catch = true;
17
+ }
18
+ end
21
19
 
22
- def component_did_mount(&block)
23
- %x{
24
- let fun = function() {
25
- Opal.Preact.register_active_component(this);
26
- try {
27
- #{`this.__ruby_instance`.instance_exec(&block)};
28
- } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
29
- Opal.Preact.unregister_active_component(this);
20
+ def component_did_mount(&block)
21
+ %x{
22
+ let fun = function() {
23
+ Opal.Preact.register_active_component(this);
24
+ try {
25
+ #{`this.__ruby_instance`.instance_exec(&block)};
26
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
27
+ Opal.Preact.unregister_active_component(this);
28
+ }
29
+ if (self.lucid_preact_component) {
30
+ if (self.lucid_preact_component.prototype.componentDidMount) {
31
+ let fun_one = self.lucid_preact_component.prototype.componentDidMount;
32
+ let fun_two = fun;
33
+ fun = function() {
34
+ fun_one();
35
+ fun_two();
30
36
  }
31
- if (self.lucid_preact_component) {
32
- if (self.lucid_preact_component.prototype.componentDidMount) {
33
- let fun_one = self.lucid_preact_component.prototype.componentDidMount;
34
- let fun_two = fun;
35
- fun = function() {
36
- fun_one();
37
- fun_two();
38
- }
39
- }
40
- self.lucid_preact_component.prototype.componentDidMount = fun;
41
- } else { self.preact_component.prototype.componentDidMount = fun; }
42
37
  }
43
- end
38
+ self.lucid_preact_component.prototype.componentDidMount = fun;
39
+ } else { self.preact_component.prototype.componentDidMount = fun; }
40
+ }
41
+ end
44
42
 
45
- def component_did_update(&block)
46
- %x{
47
- var fun = function(prev_props, prev_state, snapshot) {
48
- Opal.Preact.register_active_component(this);
49
- try {
50
- #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
51
- `Opal.Preact.State.$new({state: prev_state})`,
52
- `snapshot`, &block)};
53
- } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
54
- Opal.Preact.unregister_active_component(this);
55
- }
56
- if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidUpdate = fun; }
57
- else { self.preact_component.prototype.componentDidUpdate = fun; }
58
- }
59
- end
43
+ def component_did_update(&block)
44
+ %x{
45
+ var fun = function(prev_props, prev_state, snapshot) {
46
+ Opal.Preact.register_active_component(this);
47
+ try {
48
+ #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
49
+ `Opal.Preact.State.$new({state: prev_state})`,
50
+ `snapshot`, &block)};
51
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
52
+ Opal.Preact.unregister_active_component(this);
53
+ }
54
+ if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidUpdate = fun; }
55
+ else { self.preact_component.prototype.componentDidUpdate = fun; }
56
+ }
57
+ end
60
58
 
61
- def component_will_unmount(&block)
62
- %x{
63
- var fun = function() {
64
- if (typeof this.unsubscriber === "function") { this.unsubscriber(); };
65
- Opal.Preact.register_active_component(this);
66
- try {
67
- #{`this.__ruby_instance`.instance_exec(&block)};
68
- } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
69
- Opal.Preact.unregister_active_component(this);
70
- }
71
- if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentWillUnmount = fun; }
72
- else { self.preact_component.prototype.componentWillUnmount = fun; }
73
- }
74
- end
59
+ def component_will_unmount(&block)
60
+ %x{
61
+ var fun = function() {
62
+ if (typeof this.unsubscriber === "function") { this.unsubscriber(); };
63
+ Opal.Preact.register_active_component(this);
64
+ try {
65
+ #{`this.__ruby_instance`.instance_exec(&block)};
66
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
67
+ Opal.Preact.unregister_active_component(this);
68
+ }
69
+ if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentWillUnmount = fun; }
70
+ else { self.preact_component.prototype.componentWillUnmount = fun; }
71
+ }
72
+ end
75
73
 
76
74
 
77
- def get_derived_state_from_props(&block)
78
- %x{
79
- var fun = function(props, state) {
80
- Opal.Preact.register_active_component(this);
81
- try {
82
- var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: props})`,
83
- `Opal.Preact.State.$new({state: state})`, &block)};
84
- } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
85
- Opal.Preact.unregister_active_component(this);
86
- if (typeof result.$to_n === 'function') { result = result.$to_n() }
87
- if (result === nil) { return null; }
88
- return result;
89
- }
90
- if (self.lucid_preact_component) { self.lucid_preact_component.prototype.getDerivedStateFromProps = fun; }
91
- else { self.preact_component.prototype.getDerivedStateFromProps = fun; }
92
- }
93
- end
75
+ def get_derived_state_from_props(&block)
76
+ %x{
77
+ var fun = function(props, state) {
78
+ Opal.Preact.register_active_component(this);
79
+ try {
80
+ var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: props})`,
81
+ `Opal.Preact.State.$new({state: state})`, &block)};
82
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
83
+ Opal.Preact.unregister_active_component(this);
84
+ if (typeof result.$to_n === 'function') { result = result.$to_n() }
85
+ if (result === nil) { return null; }
86
+ return result;
87
+ }
88
+ if (self.lucid_preact_component) { self.lucid_preact_component.prototype.getDerivedStateFromProps = fun; }
89
+ else { self.preact_component.prototype.getDerivedStateFromProps = fun; }
90
+ }
91
+ end
94
92
 
95
- def get_snapshot_before_update(&block)
96
- %x{
97
- var fun = function(prev_props, prev_state) {
98
- Opal.Preact.register_active_component(this);
99
- try {
100
- var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
101
- `Opal.Preact.State.$new({state: prev_state})`, &block)};
102
- } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
103
- Opal.Preact.unregister_active_component(this);
104
- if (result === nil) { return null; }
105
- return result;
106
- }
107
- if (self.lucid_preact_component) { self.lucid_preact_component.prototype.getSnapshotBeforeUpdate = fun; }
108
- else { self.preact_component.prototype.getSnapshotBeforeUpdate = fun; }
109
- }
110
- end
111
- end
93
+ def get_snapshot_before_update(&block)
94
+ %x{
95
+ var fun = function(prev_props, prev_state) {
96
+ Opal.Preact.register_active_component(this);
97
+ try {
98
+ var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
99
+ `Opal.Preact.State.$new({state: prev_state})`, &block)};
100
+ } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
101
+ Opal.Preact.unregister_active_component(this);
102
+ if (result === nil) { return null; }
103
+ return result;
104
+ }
105
+ if (self.lucid_preact_component) { self.lucid_preact_component.prototype.getSnapshotBeforeUpdate = fun; }
106
+ else { self.preact_component.prototype.getSnapshotBeforeUpdate = fun; }
107
+ }
112
108
  end
113
109
  end
114
110
  end
@@ -1,11 +1,7 @@
1
- module Preact
2
- module Component
3
- module Initializer
4
- def initialize(native_component)
5
- @native = native_component
6
- @props = `Opal.Preact.Props.$new(#@native)`
7
- @state = `Opal.Preact.State.$new(#@native)`
8
- end
9
- end
1
+ module Preact::Component::Initializer
2
+ def initialize(native_component)
3
+ @native = native_component
4
+ @props = `Opal.Preact.Props.$new(#@native)`
5
+ @state = `Opal.Preact.State.$new(#@native)`
10
6
  end
11
7
  end
@@ -1,15 +1,11 @@
1
- module Preact
2
- module Component
3
- module Mixin
4
- def self.included(base)
5
- base.include(::Native::Wrapper)
6
- base.extend(::Preact::Component::NativeComponentConstructor)
7
- base.extend(::LucidPropDeclaration::Mixin)
8
- base.include(::Preact::Elements)
9
- base.include(::Preact::Component::Api)
10
- base.include(::Preact::Component::Callbacks)
11
- base.include(::Preact::Component::Initializer)
12
- end
13
- end
1
+ module Preact::Component::Mixin
2
+ def self.included(base)
3
+ base.include(::Native::Wrapper)
4
+ base.extend(::Preact::Component::NativeComponentConstructor)
5
+ base.extend(::LucidPropDeclaration::Mixin)
6
+ base.include(::Preact::Elements)
7
+ base.include(::Preact::Component::Api)
8
+ base.include(::Preact::Component::Callbacks)
9
+ base.include(::Preact::Component::Initializer)
14
10
  end
15
11
  end