This repository was archived by the owner on Oct 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +77
-1
lines changed Expand file tree Collapse file tree 4 files changed +77
-1
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ class extends React.Component {
71
71
this.__opalInstanceSyncSetState = true;
72
72
this.__opalInstance.$component_will_mount();
73
73
this.__opalInstanceSyncSetState = false;
74
- }
74
+ }
75
75
}
76
76
componentDidMount() {
77
77
this.__opalInstance.is_mounted = true
@@ -171,6 +171,10 @@ def self.convert_props(properties)
171
171
props [ "className" ] = value
172
172
elsif [ "style" , "dangerously_set_inner_HTML" ] . include? key
173
173
props [ lower_camelize ( key ) ] = value . to_n
174
+
175
+ elsif key == "key"
176
+ props [ "key" ] = value . to_key
177
+
174
178
elsif key == 'ref' && value . is_a? ( Proc )
175
179
props [ key ] = %x{
176
180
function(dom_node){
Original file line number Diff line number Diff line change @@ -12,4 +12,19 @@ def const_missing(const_name)
12
12
React ::Component ::Tags . html_tag_class_for ( const_name ) || raise ( e )
13
13
end
14
14
end
15
+
16
+ def to_key
17
+ object_id
18
+ end
19
+ end
20
+ class Number
21
+ def to_key
22
+ self
23
+ end
24
+ end
25
+
26
+ class Boolean
27
+ def to_key
28
+ self
29
+ end
15
30
end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe 'key_to_react helper' , js : true do
4
+ it "will use the use the to_key method to get the react key" do
5
+ mount "TestComponent" do
6
+ class MyTestClass
7
+ attr_reader :to_key_called
8
+ def to_key
9
+ @to_key_called = true
10
+ super
11
+ end
12
+ end
13
+ class TestComponent < Hyperloop ::Component
14
+ before_mount { @test_object = MyTestClass . new }
15
+ render do
16
+ DIV ( key : @test_object ) { TestComponent2 ( test_object : @test_object ) }
17
+ end
18
+ end
19
+ class TestComponent2 < Hyperloop ::Component
20
+ param :test_object
21
+ render do
22
+ "to key was called!" if params . test_object . to_key_called
23
+ end
24
+ end
25
+ end
26
+ pause
27
+ expect ( page ) . to have_content ( 'to key was called!' )
28
+ end
29
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe 'to_key helper' , js : true do
4
+ it "has added 'to_key' method to Object and each key is different" do
5
+ expect_evaluate_ruby do
6
+ Object . new . to_key != Object . new . to_key
7
+ end . to be_truthy
8
+ end
9
+
10
+ it "to_key return 'self' for String objects" do
11
+ expect_evaluate_ruby do
12
+ debugger
13
+ "hello" . to_key == "hello"
14
+ end . to be_truthy
15
+ end
16
+
17
+ it "to_key return 'self' for Number objects" do
18
+ expect_evaluate_ruby do
19
+ 12 . to_key == 12
20
+ end . to be_truthy
21
+ end
22
+
23
+ it "to_key return 'self' for Boolean objects" do
24
+ expect_evaluate_ruby do
25
+ true . to_key == true && false . to_key == false
26
+ end . to be_truthy
27
+ end
28
+ end
You can’t perform that action at this time.
0 commit comments