Skip to content

Commit 79ed06f

Browse files
committed
fixed variable typo in findDOMNodes, added spec
1 parent fc7b165 commit 79ed06f

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

lib/assets/javascripts/react_ujs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ var ReactRailsUJS = {
238238

239239
// helper method for the mount and unmount methods to find the
240240
// `data-react-class` DOM elements
241-
findDOMNodes: function(selector) {
241+
findDOMNodes: function(searchSelector) {
242242
var classNameAttr = ReactRailsUJS.CLASS_NAME_ATTR
243243
// we will use fully qualified paths as we do not bind the callbacks
244244
var selector, parent;
@@ -502,4 +502,4 @@ module.exports = function(reqctx) {
502502

503503
/***/ })
504504
/******/ ]);
505-
});
505+
});

react_ujs/dist/react_ujs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ var ReactRailsUJS = {
238238

239239
// helper method for the mount and unmount methods to find the
240240
// `data-react-class` DOM elements
241-
findDOMNodes: function(selector) {
241+
findDOMNodes: function(searchSelector) {
242242
var classNameAttr = ReactRailsUJS.CLASS_NAME_ATTR
243243
// we will use fully qualified paths as we do not bind the callbacks
244244
var selector, parent;
@@ -502,4 +502,4 @@ module.exports = function(reqctx) {
502502

503503
/***/ })
504504
/******/ ]);
505-
});
505+
});

react_ujs/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var ReactRailsUJS = {
2020

2121
// helper method for the mount and unmount methods to find the
2222
// `data-react-class` DOM elements
23-
findDOMNodes: function(selector) {
23+
findDOMNodes: function(searchSelector) {
2424
var classNameAttr = ReactRailsUJS.CLASS_NAME_ATTR
2525
// we will use fully qualified paths as we do not bind the callbacks
2626
var selector, parent;

test/dummy/app/views/pages/show.html.erb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<ul>
2-
<li><%= link_to 'Alice', page_path(:id => 0) %></li>
3-
<li><%= link_to 'Bob', page_path(:id => 1) %></li>
2+
<li><%= link_to 'Alice', page_path(id: 0) %></li>
3+
<li><%= link_to 'Bob', page_path(id: 1) %></li>
44
</ul>
55

66
<div id='component-parent'>
7-
<%= react_component 'GreetingMessage', { :name => @name }, { :id => 'component', prerender: @prerender } %>
7+
<%= react_component 'GreetingMessage', { name: @name }, { id: 'component', prerender: @prerender } %>
8+
<ul>
9+
<%= react_component 'Todo', { todo: 'Another Component' }, { id: 'todo', prerender: @prerender } %>
10+
</ul>
811
</div>
912

1013
<button onClick="ReactRailsUJS.unmountComponents('#component-parent')">Unmount by parent selector</button>

test/react/rails/controller_lifecycle_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def teardown
4646
test "it calls setup and teardown methods" do
4747
get '/pages/1?param_test=123'
4848
helper_obj = controller.__react_component_helper
49-
lifecycle_steps = ["123", :react_component, :teardown]
49+
lifecycle_steps = ["123", :react_component, :react_component, :teardown]
5050
assert_equal(lifecycle_steps, helper_obj.events)
5151
end
5252

test/react/rails/react_rails_ujs_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ def refute_greeting(page, greeting)
124124
assert_greeting(page, 'Hello Bob')
125125
end
126126

127+
test 'react_ujs does not unmount components that do not match a selector reference for the component' do
128+
visit '/pages/1'
129+
assert_greeting page, 'Hello Bob'
130+
assert page.has_content?('Another Component'), page.body
131+
132+
page.click_button "Unmount by own selector"
133+
refute_greeting(page, 'Hello Bob')
134+
assert page.has_content?('Another Component'), page.body
135+
136+
page.click_button "Mount by own selector"
137+
assert_greeting(page, 'Hello Bob')
138+
assert page.has_content?('Another Component'), page.body
139+
end
140+
141+
127142
test 'react_ujs can unmount/mount using a dom node context' do
128143
visit '/pages/1'
129144
assert_greeting(page, 'Hello Bob')

0 commit comments

Comments
 (0)