isomorfeus-preact 10.6.17 → 10.6.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/browser/delegate_native.rb +31 -39
- data/lib/isomorfeus-preact.rb +1 -1
- data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +4 -7
- data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +4 -7
- data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +2 -4
- data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +2 -4
- data/lib/preact/component/api.rb +1 -1
- data/lib/preact/component/callbacks.rb +14 -14
- data/lib/preact/component/native_component_constructor.rb +4 -5
- data/lib/preact/version.rb +1 -1
- data/lib/preact.rb +19 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76c5ba07f42c9e53b189fed74f0ac51e7041cd9d243b080295e86492cfc12bd8
|
4
|
+
data.tar.gz: 5ae156acd8f5c22acfdca4642df719459183727df885d141a1b72b37268c4304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aecd0b46f5d6901d435444fe02080d2aa114778bf3de8ce1ee42052226bd06a3d91644bfe73456a8bce24f336769e1347a079b38894f63ef16f3186732a98dd
|
7
|
+
data.tar.gz: a3c3ae921ad2bd80cc5fae87857b299ff206c9026300c99a177b96249b5517eb09b1401a56e287b629cfabf4a613dd37cc39b0fffc95afd64beda63f97bda6ce
|
@@ -16,55 +16,47 @@ module Browser
|
|
16
16
|
# function, that function is invoked with `args`. Otherwise, the property
|
17
17
|
# is returned as is.
|
18
18
|
def method_missing message, *args, &block
|
19
|
-
property_name = property_for_message(message)
|
20
|
-
property = `#@native[#{property_name}]`
|
21
|
-
|
22
|
-
# translate setting a property
|
23
19
|
if message.end_with? '='
|
20
|
+
message = message.chop
|
21
|
+
property_name = property_for_message(message)
|
24
22
|
return `#@native[#{property_name}] = args[0]`
|
25
|
-
end
|
26
|
-
|
27
|
-
# If the native element doesn't have this property, bubble it up
|
28
|
-
super unless `#{property_name} in #@native`
|
29
|
-
|
30
|
-
if `property === false`
|
31
|
-
return false
|
32
|
-
elsif `typeof(property) === 'number' && isNaN(property)`
|
33
|
-
return nil
|
34
23
|
else
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
24
|
+
property_name = property_for_message(message)
|
25
|
+
|
26
|
+
%x{
|
27
|
+
let value = #@native[#{property_name}];
|
28
|
+
let type = typeof(value);
|
29
|
+
if (type === 'function') {
|
30
|
+
return value.apply(#@native, args);
|
31
|
+
} else if (value === null || type === 'undefined' || (type === 'number' && isNaN(value))) {
|
32
|
+
return nil;
|
33
|
+
}
|
34
|
+
return value;
|
35
|
+
}
|
43
36
|
end
|
44
37
|
end
|
45
38
|
|
46
39
|
def respond_to_missing? message, include_all
|
47
|
-
|
48
|
-
|
49
|
-
|
40
|
+
message = message.chop if message.end_with? '='
|
41
|
+
property_name = property_for_message(message)
|
42
|
+
return true unless `#{property_name} in #@native`
|
50
43
|
false
|
51
44
|
end
|
52
45
|
|
53
|
-
def property_for_message
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
camel_cased_message
|
46
|
+
def property_for_message(message)
|
47
|
+
%x{
|
48
|
+
let camel_cased_message;
|
49
|
+
if (typeof(#@native[message]) !== 'undefined') { camel_cased_message = message; }
|
50
|
+
else { camel_cased_message = Opal.Preact.lower_camelize(message) }
|
51
|
+
|
52
|
+
if (camel_cased_message.endsWith('?')) {
|
53
|
+
camel_cased_message = camel_cased_message.substring(0, camel_cased_message.length - 2);
|
54
|
+
if (typeof(#@native[camel_cased_message]) === 'undefined') {
|
55
|
+
camel_cased_message = 'is' + camel_cased_message[0].toUpperCase() + camel_cased_message.substring(0, camel_cased_message.length - 1);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
return camel_cased_message
|
59
|
+
}
|
68
60
|
end
|
69
61
|
end
|
70
62
|
end
|
data/lib/isomorfeus-preact.rb
CHANGED
@@ -33,9 +33,10 @@ module LucidApp
|
|
33
33
|
var defined_refs = #{base.defined_refs};
|
34
34
|
for (var ref in defined_refs) {
|
35
35
|
if (defined_refs[ref] != null) {
|
36
|
+
let r = ref; // to ensure closure for function below gets correct ref name
|
36
37
|
this[ref] = function(element) {
|
37
38
|
element = oper.native_element_or_component_to_ruby(element);
|
38
|
-
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[
|
39
|
+
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
|
39
40
|
}
|
40
41
|
this[ref] = this[ref].bind(this);
|
41
42
|
} else {
|
@@ -56,17 +57,13 @@ module LucidApp
|
|
56
57
|
render(props, state) {
|
57
58
|
const oper = Opal.Preact;
|
58
59
|
oper.render_buffer.push([]);
|
59
|
-
|
60
|
-
oper.active_components.push(this);
|
61
|
-
oper.active_redux_components.push(this);
|
60
|
+
oper.register_active_component(this);
|
62
61
|
let block_result;
|
63
62
|
if (base.while_loading_block && !state.preloaded) { block_result = #{`this.__ruby_instance`.instance_exec(&`base.while_loading_block`)}; }
|
64
63
|
else { block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)}; }
|
65
64
|
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
66
|
-
oper.
|
67
|
-
oper.active_components.pop();
|
65
|
+
oper.unregister_active_component(this);
|
68
66
|
let children = oper.render_buffer.pop();
|
69
|
-
// console.log("lucid app popping", oper.render_buffer, oper.render_buffer.toString());
|
70
67
|
return Opal.global.Preact.createElement(Opal.global.LucidApplicationContext.Provider, { value: { iso_store: this.state.isomorfeus_store_state, iso_theme: base.css_theme }}, children);
|
71
68
|
}
|
72
69
|
data_access() {
|
@@ -29,9 +29,10 @@ module LucidComponent
|
|
29
29
|
var defined_refs = base.$defined_refs();
|
30
30
|
for (var ref in defined_refs) {
|
31
31
|
if (defined_refs[ref] != null) {
|
32
|
+
let r = ref; // to ensure closure for function below gets correct ref name
|
32
33
|
this[ref] = function(element) {
|
33
34
|
element = oper.native_element_or_component_to_ruby(element);
|
34
|
-
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[
|
35
|
+
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
|
35
36
|
}
|
36
37
|
this[ref] = this[ref].bind(this);
|
37
38
|
} else {
|
@@ -50,16 +51,12 @@ module LucidComponent
|
|
50
51
|
render(props, state) {
|
51
52
|
const oper = Opal.Preact;
|
52
53
|
oper.render_buffer.push([]);
|
53
|
-
|
54
|
-
oper.active_components.push(this);
|
55
|
-
oper.active_redux_components.push(this);
|
54
|
+
oper.register_active_component(this);
|
56
55
|
let block_result;
|
57
56
|
if (base.while_loading_block && !state.preloaded) { block_result = #{`this.__ruby_instance`.instance_exec(&`base.while_loading_block`)}; }
|
58
57
|
else { block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)}; }
|
59
58
|
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
60
|
-
oper.
|
61
|
-
oper.active_components.pop();
|
62
|
-
// console.log("lucid component popping", oper.render_buffer, oper.render_buffer.toString());
|
59
|
+
oper.unregister_active_component(this);
|
63
60
|
let result = oper.render_buffer.pop();
|
64
61
|
return (result.length === 1) ? result[0] : result;
|
65
62
|
}
|
@@ -23,12 +23,10 @@ module LucidFunc
|
|
23
23
|
const [__ruby_state, __ruby_dispatch] = og.PreactHooks.useReducer(base.instance_reducer, null, base.instance_init);
|
24
24
|
const __ruby_instance = __ruby_state.instance;
|
25
25
|
__ruby_instance.props = Object.assign({}, props, context);
|
26
|
-
oper.
|
27
|
-
oper.active_redux_components.push(__ruby_instance);
|
26
|
+
oper.register_active_component(__ruby_instance);
|
28
27
|
let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
|
29
28
|
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
30
|
-
oper.
|
31
|
-
oper.active_components.pop();
|
29
|
+
oper.unregister_active_component(__ruby_instance);
|
32
30
|
// console.log("function popping", oper.render_buffer, oper.render_buffer.toString());
|
33
31
|
let result = oper.render_buffer.pop();
|
34
32
|
return (result.length === 1) ? result[0] : result;
|
@@ -13,15 +13,13 @@ module Preact
|
|
13
13
|
base.preact_component = function(props) {
|
14
14
|
const oper = Opal.Preact;
|
15
15
|
oper.render_buffer.push([]);
|
16
|
-
// console.log("function pushed", oper.render_buffer, oper.render_buffer.toString());
|
17
16
|
const [__ruby_state, __ruby_dispatch] = Opal.global.PreactHooks.useReducer(base.instance_reducer, null, base.instance_init);
|
18
17
|
const __ruby_instance = __ruby_state.instance;
|
19
18
|
__ruby_instance.props = props;
|
20
|
-
oper.
|
19
|
+
oper.register_active_component(__ruby_instance);
|
21
20
|
let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
|
22
21
|
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
23
|
-
oper.
|
24
|
-
// console.log("function popping", oper.render_buffer, oper.render_buffer.toString());
|
22
|
+
oper.unregister_active_component(__ruby_instance);
|
25
23
|
let result = oper.render_buffer.pop();
|
26
24
|
return (result.length === 1) ? result[0] : result;
|
27
25
|
}
|
data/lib/preact/component/api.rb
CHANGED
@@ -7,9 +7,9 @@ module Preact
|
|
7
7
|
# TODO convert error
|
8
8
|
%x{
|
9
9
|
var fun = function(error) {
|
10
|
-
Opal.Preact.
|
10
|
+
Opal.Preact.register_active_component(this);
|
11
11
|
#{`this.__ruby_instance`.instance_exec(`error`, &block)};
|
12
|
-
Opal.Preact.
|
12
|
+
Opal.Preact.unregister_active_component(this);
|
13
13
|
}
|
14
14
|
if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidCatch = fun; }
|
15
15
|
else { self.preact_component.prototype.componentDidCatch = fun; }
|
@@ -19,9 +19,9 @@ module Preact
|
|
19
19
|
def component_did_mount(&block)
|
20
20
|
%x{
|
21
21
|
let fun = function() {
|
22
|
-
Opal.Preact.
|
22
|
+
Opal.Preact.register_active_component(this);
|
23
23
|
#{`this.__ruby_instance`.instance_exec(&block)};
|
24
|
-
Opal.Preact.
|
24
|
+
Opal.Preact.unregister_active_component(this);
|
25
25
|
}
|
26
26
|
if (self.lucid_preact_component) {
|
27
27
|
if (self.lucid_preact_component.prototype.componentDidMount) {
|
@@ -40,11 +40,11 @@ module Preact
|
|
40
40
|
def component_did_update(&block)
|
41
41
|
%x{
|
42
42
|
var fun = function(prev_props, prev_state, snapshot) {
|
43
|
-
Opal.Preact.
|
43
|
+
Opal.Preact.register_active_component(this);
|
44
44
|
#{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
|
45
45
|
`Opal.Preact.State.$new({state: prev_state})`,
|
46
46
|
`snapshot`, &block)};
|
47
|
-
Opal.Preact.
|
47
|
+
Opal.Preact.unregister_active_component(this);
|
48
48
|
}
|
49
49
|
if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidUpdate = fun; }
|
50
50
|
else { self.preact_component.prototype.componentDidUpdate = fun; }
|
@@ -55,9 +55,9 @@ module Preact
|
|
55
55
|
%x{
|
56
56
|
var fun = function() {
|
57
57
|
if (typeof this.unsubscriber === "function") { this.unsubscriber(); };
|
58
|
-
Opal.Preact.
|
58
|
+
Opal.Preact.register_active_component(this);
|
59
59
|
#{`this.__ruby_instance`.instance_exec(&block)};
|
60
|
-
Opal.Preact.
|
60
|
+
Opal.Preact.unregister_active_component(this);
|
61
61
|
}
|
62
62
|
if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentWillUnmount = fun; }
|
63
63
|
else { self.preact_component.prototype.componentWillUnmount = fun; }
|
@@ -68,12 +68,12 @@ module Preact
|
|
68
68
|
def get_derived_state_from_props(&block)
|
69
69
|
%x{
|
70
70
|
var fun = function(props, state) {
|
71
|
-
Opal.Preact.
|
71
|
+
Opal.Preact.register_active_component(this);
|
72
72
|
var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: props})`,
|
73
73
|
`Opal.Preact.State.$new({state: state})`, &block)};
|
74
|
-
Opal.Preact.
|
74
|
+
Opal.Preact.unregister_active_component(this);
|
75
75
|
if (typeof result.$to_n === 'function') { result = result.$to_n() }
|
76
|
-
if (result ===
|
76
|
+
if (result === nil) { return null; }
|
77
77
|
return result;
|
78
78
|
}
|
79
79
|
if (self.lucid_preact_component) { self.lucid_preact_component.prototype.getDerivedStateFromProps = fun; }
|
@@ -84,11 +84,11 @@ module Preact
|
|
84
84
|
def get_snapshot_before_update(&block)
|
85
85
|
%x{
|
86
86
|
var fun = function(prev_props, prev_state) {
|
87
|
-
Opal.Preact.
|
87
|
+
Opal.Preact.register_active_component(this);
|
88
88
|
var result = #{`this.__ruby_instance`.instance_exec(`Opal.Preact.Props.$new({props: prev_props})`,
|
89
89
|
`Opal.Preact.State.$new({state: prev_state})`, &block)};
|
90
|
-
Opal.Preact.
|
91
|
-
if (result ===
|
90
|
+
Opal.Preact.unregister_active_component(this);
|
91
|
+
if (result === nil) { return null; }
|
92
92
|
return result;
|
93
93
|
}
|
94
94
|
if (self.lucid_preact_component) { self.lucid_preact_component.prototype.getSnapshotBeforeUpdate = fun; }
|
@@ -19,9 +19,10 @@ module Preact
|
|
19
19
|
var defined_refs = #{base.defined_refs};
|
20
20
|
for (var ref in defined_refs) {
|
21
21
|
if (defined_refs[ref] != null) {
|
22
|
+
let r = ref; // to ensure closure for function below gets correct ref name
|
22
23
|
this[ref] = function(element) {
|
23
24
|
element = Opal.Preact.native_element_or_component_to_ruby(element);
|
24
|
-
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[
|
25
|
+
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
|
25
26
|
}
|
26
27
|
this[ref] = this[ref].bind(this);
|
27
28
|
} else {
|
@@ -35,12 +36,10 @@ module Preact
|
|
35
36
|
render(props, state) {
|
36
37
|
const oper = Opal.Preact;
|
37
38
|
oper.render_buffer.push([]);
|
38
|
-
|
39
|
-
oper.active_components.push(this);
|
39
|
+
oper.register_active_component(this);
|
40
40
|
let block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
|
41
41
|
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
42
|
-
|
43
|
-
oper.active_components.pop();
|
42
|
+
oper.unregister_active_component(this);
|
44
43
|
let result = oper.render_buffer.pop();
|
45
44
|
return (result.length === 1) ? result[0] : result;
|
46
45
|
}
|
data/lib/preact/version.rb
CHANGED
data/lib/preact.rb
CHANGED
@@ -57,8 +57,9 @@ module Preact
|
|
57
57
|
};
|
58
58
|
|
59
59
|
self.native_element_or_component_to_ruby = function (element) {
|
60
|
-
if (typeof
|
61
|
-
if (
|
60
|
+
if (element == null || typeof(element) === 'undefined' ) { return nil; }
|
61
|
+
if (typeof element.__ruby_instance !== 'undefined') { return element.__ruby_instance; }
|
62
|
+
if (element instanceof Element || element instanceof Node) { return #{Browser::Element.new(`element`)}; }
|
62
63
|
return element;
|
63
64
|
};
|
64
65
|
|
@@ -95,6 +96,20 @@ module Preact
|
|
95
96
|
return self.active_redux_components[length-1];
|
96
97
|
};
|
97
98
|
|
99
|
+
self.register_active_component = function(component) {
|
100
|
+
self.active_components.push(component);
|
101
|
+
if (typeof(component.data_access) === 'function') {
|
102
|
+
self.active_redux_components.push(component);
|
103
|
+
}
|
104
|
+
};
|
105
|
+
|
106
|
+
self.unregister_active_component = function(component) {
|
107
|
+
if (typeof(component.data_access) === 'function') {
|
108
|
+
self.active_redux_components.pop();
|
109
|
+
}
|
110
|
+
self.active_components.pop();
|
111
|
+
};
|
112
|
+
|
98
113
|
function isObject(obj) { return (obj && typeof obj === 'object'); }
|
99
114
|
|
100
115
|
self.merge_deep = function(one, two) {
|
@@ -169,6 +184,8 @@ module Preact
|
|
169
184
|
else { component_name = active_component.$to_s(); }
|
170
185
|
#{Isomorfeus.raise_error(message: "Is #{`value`} a valid method of #{`component_name`}? If so then please use: #{`key`}: method_ref(:#{`value`}) within component: #{`component_name`}")}
|
171
186
|
}
|
187
|
+
} else if (type === "object" && value === nil) {
|
188
|
+
result[self.lower_camelize(key)] = null;
|
172
189
|
} else {
|
173
190
|
let active_component = self.active_component();
|
174
191
|
let component_name;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-preact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.6.
|
4
|
+
version: 10.6.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.14.
|
89
|
+
version: 0.14.7
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.14.
|
96
|
+
version: 0.14.7
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: isomorfeus-redux
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|