isomorfeus-preact 10.6.18 → 10.6.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ea65d13596d480bc9236508994f2fe5e8faed1d74cab03acd6f2c3b272c4446
4
- data.tar.gz: 961c5f11b767f30b4db8a7124c2029f0aa748404c175dc8466b67f38ef58292a
3
+ metadata.gz: dcabd6672c23dfd3a4eaf10b565b032522c1f0d352778e2d92366a24061b8d97
4
+ data.tar.gz: 0bb1045aa576165352bf122f510eb3e94cffa6ea277008ab3a0c835502331e88
5
5
  SHA512:
6
- metadata.gz: 57baa3fcf48a20fa0693942f0ffd84794b2ae3409a27e8cf925d3f67c27d03dc2ecdd8a5517bdd392cb06f04212892dd1d5d64177e85ddb59dc2e393bf3991be
7
- data.tar.gz: 808e9777924661bef69c400af5ab5c04d02f76df9ae644344a474df2e8d14f63e6fcf2754af9cfd1cefab590cfcfedc0c7d18109ca1022341a8358f8f9d829ed
6
+ metadata.gz: 2c478adf7ffcfab21bb7ba74ca6c109bdb4ec257ba830ba7bafbd91b1f12e2e50b427cf57dfd78b50570ca788630e539e1203ada466af987dcc23e5caf0aa9e9
7
+ data.tar.gz: eb945769548e040115bca58246c94625dec9bb68e585bc1fd9268ebcc58c26d6894a72816d4d4ceea751e881a7933418bca067c867ea4e8ff92c342adffb30a5
@@ -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
- property = `property == null ? nil : property`
36
- end
37
-
38
- # If it's a method, call it. Otherwise, return it.
39
- if `typeof(property) === 'function'`
40
- `property.apply(#@native, args)`
41
- else
42
- property
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
- return true if message.end_with? '='
48
- return true if property_for_message(message)
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 message
54
- camel_cased_message = message
55
- .gsub(/_\w/) { |match| `match[1]`.upcase }
56
- .sub(/=$/, '')
57
-
58
- # translate `supported?` to `supported` or `isSupported`
59
- if message.end_with? '?'
60
- camel_cased_message = camel_cased_message.chop
61
- property_type = `typeof(#@native[camel_cased_message])`
62
- if property_type == 'undefined'
63
- camel_cased_message = "is#{camel_cased_message[0].upcase}#{camel_cased_message[1..-1]}"
64
- end
65
- end
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
@@ -7,7 +7,7 @@ if RUBY_ENGINE == 'opal'
7
7
  require 'browser/event'
8
8
  require 'browser/event_target'
9
9
  require 'browser/delegate_native'
10
- require 'browser/element'
10
+ require 'browser/element' # depends on 'preact'
11
11
  end
12
12
 
13
13
  require 'isomorfeus/preact/config'
@@ -1,3 +1,3 @@
1
1
  module Preact
2
- VERSION = '10.6.18'
2
+ VERSION = '10.6.19'
3
3
  end
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 element.__ruby_instance !== 'undefined') { return element.__ruby_instance }
61
- if (element instanceof Element || element instanceof Node) { return #{Browser::Element.new(`element`)} }
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
 
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.18
4
+ version: 10.6.19
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-28 00:00:00.000000000 Z
11
+ date: 2022-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby