isomorfeus-react 16.8.0 → 16.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 572d49e689c48227eff72f1c354d6d09e342d110cfcb1e95f7a9a1a523fe345f
4
- data.tar.gz: 4ffc0e63dde3adafc83f72a239e041186e4af492d60b02724c783b823ade4846
3
+ metadata.gz: 6e1f51aa98f40271693104f25f9321a0b1ce04668666efe2f6b345958f2d4687
4
+ data.tar.gz: 0c823d4922443ab1b157b638438a908caff664906be19c7fbef4f0410cb3a36d
5
5
  SHA512:
6
- metadata.gz: 133cc190d7a975b12b1c70462aef1fe473cb819b172be6dfcfdebf7b331aba73fd9fa4c6264fe4aca942c18d2b5944c6dd321451e51f38a387fd098a4f1f7ba5
7
- data.tar.gz: 9bc4d86826962e1b9c2bf5c9bb94c03166950a619a41312b0f74e2d59fb5bccc22c41af7f430e7246745d88584836755480cc71a3d26abf9f2f4518d75e1510c
6
+ metadata.gz: d14aa94c3504a7cf2eee50db467e468045660f4fcdc1dbc8f2beb95f7f2ad45e6ceca07c8a53b8291a354859e42e8c1d6cc2f6245ef5e2c0ab0bc2ccf4865cda
7
+ data.tar.gz: 9b36d35c724f49776ec46bb4c4bf4530f7ccd3cb2b29d83ed2b8fbbb7c619dbf5c4c23a5c86c87ebd13eb8cccbe315f2f543a6bca5f7f2a102eae2c1051d4322
@@ -38,7 +38,8 @@ module LucidApp
38
38
  for (var ref in defined_refs) {
39
39
  if (defined_refs[ref] != null) {
40
40
  this[ref] = function(element) {
41
- #{`this.__ruby_instance`.instance_exec(React::Ref.new(`element`), `defined_refs[ref]`)}
41
+ element = Opal.React.native_element_or_component_to_ruby(element);
42
+ #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
42
43
  }
43
44
  this[ref] = this[ref].bind(this);
44
45
  } else {
@@ -35,7 +35,8 @@ module LucidComponent
35
35
  for (var ref in defined_refs) {
36
36
  if (defined_refs[ref] != null) {
37
37
  this[ref] = function(element) {
38
- #{`this.__ruby_instance`.instance_exec(React::Ref.new(`element`), `defined_refs[ref]`)}
38
+ element = Opal.React.native_element_or_component_to_ruby(element);
39
+ #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
39
40
  }
40
41
  this[ref] = this[ref].bind(this);
41
42
  } else {
@@ -40,7 +40,8 @@ module LucidMaterial
40
40
  for (var ref in defined_refs) {
41
41
  if (defined_refs[ref] != null) {
42
42
  this[ref] = function(element) {
43
- #{`this.__ruby_instance`.instance_exec(React::Ref.new(`element`), `defined_refs[ref]`)}
43
+ element = Opal.React.native_element_or_component_to_ruby(element);
44
+ #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
44
45
  }
45
46
  this[ref] = this[ref].bind(this);
46
47
  } else {
@@ -31,7 +31,8 @@ module LucidMaterial
31
31
  for (var ref in defined_refs) {
32
32
  if (defined_refs[ref] != null) {
33
33
  this[ref] = function(element) {
34
- #{`this.__ruby_instance`.instance_exec(React::Ref.new(`element`), `defined_refs[ref]`)}
34
+ element = Opal.React.native_element_or_component_to_ruby(element);
35
+ #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
35
36
  }
36
37
  this[ref] = this[ref].bind(this);
37
38
  } else {
data/lib/react.rb CHANGED
@@ -5,6 +5,15 @@ module React
5
5
  %x{
6
6
  self.render_buffer = [];
7
7
 
8
+ self.set_validate_prop = function(component, prop_name) {
9
+ if (typeof component.react_component.propTypes == "undefined") {
10
+ component.react_component.propTypes = {};
11
+ component.react_component.propValidations = {};
12
+ component.react_component.propValidations[prop_name] = {};
13
+ }
14
+ component.react_component.propTypes[prop_name] = component.react_component.prototype.validateProp;
15
+ };
16
+
8
17
  self.lower_camelize = function(snake_cased_word) {
9
18
  var parts = snake_cased_word.split('_');
10
19
  var res = parts[0];
@@ -15,6 +24,13 @@ module React
15
24
  return res;
16
25
  };
17
26
 
27
+ self.native_element_or_component_to_ruby = function (element) {
28
+ if (typeof element.__ruby_instance !== 'undefined') { return element.__ruby_instance }
29
+ if (element instanceof Element) { return #{Browser::DOM::Element.new(`element`)} }
30
+ if (element instanceof Node) { return #{Browser::DOM::Node.new(`element`)} }
31
+ return element;
32
+ };
33
+
18
34
  self.to_native_react_props = function(ruby_style_props) {
19
35
  var result = {};
20
36
  var keys = ruby_style_props.$keys();
@@ -57,53 +57,29 @@ module React
57
57
  end
58
58
  if options.has_key?(:class)
59
59
  %x{
60
- if (typeof self.react_component.propTypes == "undefined") {
61
- self.react_component.propTypes = {};
62
- self.react_component.propValidations = {};
63
- self.react_component.propValidations[name] = {};
64
- }
65
- self.react_component.propTypes[name] = self.react_component.prototype.validateProp;
60
+ Opal.React.set_validate_prop(self, name);
66
61
  self.react_component.propValidations[name].ruby_class = options.$fetch("class");
67
62
  }
68
63
  elsif options.has_key?(:is_a)
69
64
  %x{
70
- if (typeof self.react_component.propTypes == "undefined") {
71
- self.react_component.propTypes = {};
72
- self.react_component.propValidations = {};
73
- self.react_component.propValidations[name] = {};
74
- }
75
- self.react_component.propTypes[name] = self.react_component.prototype.validateProp;
65
+ Opal.React.set_validate_prop(self, name);
76
66
  self.react_component.propValidations[name].is_a = options.$fetch("is_a");
77
67
  }
78
68
  end
79
69
  if options.has_key?(:required)
80
70
  %x{
81
- if (typeof self.react_component.propTypes == "undefined") {
82
- self.react_component.propTypes = {};
83
- self.react_component.propValidations = {};
84
- self.react_component.propValidations[name] = {};
85
- }
86
- self.react_component.propTypes[name] = self.react_component.prototype.validateProp;
71
+ Opal.React.set_validate_prop(self, name);
87
72
  self.react_component.propValidations[name].required = options.$fetch("required");
88
73
  }
89
74
  elsif !options.has_key?(:default)
90
75
  %x{
91
- if (typeof self.react_component.propTypes == "undefined") {
92
- self.react_component.propTypes = {};
93
- self.react_component.propValidations = {};
94
- }
95
- self.react_component.propTypes[name] = self.react_component.prototype.validateProp;
76
+ Opal.React.set_validate_prop(self, name);
96
77
  self.react_component.propValidations[name].required = true;
97
78
  }
98
79
  end
99
80
  else
100
81
  %x{
101
- if (typeof self.react_component.propTypes == "undefined") {
102
- self.react_component.propTypes = {};
103
- self.react_component.propValidations = {};
104
- self.react_component.propValidations[name] = {};
105
- }
106
- self.react_component.propTypes[name] = self.react_component.prototype.validateProp;
82
+ Opal.React.set_validate_prop(self, name);
107
83
  self.react_component.propValidations[name].required = options.$fetch("required");
108
84
  }
109
85
  end
@@ -134,6 +110,15 @@ module React
134
110
  end
135
111
  end
136
112
 
113
+ def ref(name)
114
+ `#@native[name]`
115
+ end
116
+
117
+ def ruby_ref(name)
118
+ return `#@native[name]` if `(typeof #@native[name] === 'function')`
119
+ React::Ref::new(`#@native[name]`)
120
+ end
121
+
137
122
  def set_state(updater, &callback)
138
123
  @state.set_state(updater, &callback)
139
124
  end
@@ -25,7 +25,8 @@ module React
25
25
  for (var ref in defined_refs) {
26
26
  if (defined_refs[ref] != null) {
27
27
  this[ref] = function(element) {
28
- #{`this.__ruby_instance`.instance_exec(React::Ref.new(`element`), `defined_refs[ref]`)}
28
+ element = Opal.React.native_element_or_component_to_ruby(element);
29
+ #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
29
30
  }
30
31
  this[ref] = this[ref].bind(this);
31
32
  } else {
@@ -37,7 +37,8 @@ module React
37
37
  for (var ref in defined_refs) {
38
38
  if (defined_refs[ref] != null) {
39
39
  this[ref] = function(element) {
40
- #{`this.__ruby_instance`.instance_exec(React::Ref.new(`element`), `defined_refs[ref]`)}
40
+ element = Opal.React.native_element_or_component_to_ruby(element);
41
+ #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
41
42
  }
42
43
  this[ref] = this[ref].bind(this);
43
44
  } else {
data/lib/react/ref.rb CHANGED
@@ -6,18 +6,8 @@ module React
6
6
  true
7
7
  end
8
8
 
9
- def initialize(native_ref)
10
- @native = native_ref
11
- end
12
-
13
9
  def current
14
- %x{
15
- if (typeof #@native.current.__ruby_instance != undefined) {
16
- return #@native.current.__ruby_instance;
17
- } else {
18
- #@native.current;
19
- }
20
- }
10
+ `Opal.React.native_element_or_component_to_ruby(#@native.current)`
21
11
  end
22
12
  end
23
13
  end
data/lib/react/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = '16.8.0'
2
+ VERSION = '16.8.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-react
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.8.0
4
+ version: 16.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-08 00:00:00.000000000 Z
11
+ date: 2019-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj