Skip to content

Commit 07dcbcb

Browse files
committed
cleanup style
1 parent 2a4ef6d commit 07dcbcb

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

lib/assets/javascripts/react_ujs.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1+
/*globals React, Turbolinks*/
2+
13
// Unobtrusive scripting adapter for React
24
(function(document, window) {
35
// jQuery is optional. Use it to support legacy browsers.
46
var $ = (typeof window.jQuery !== 'undefined') && window.jQuery;
57

68
// create the namespace
79
window.ReactRailsUJS = {
8-
910
CLASS_NAME_ATTR: 'data-react-class',
10-
1111
PROPS_ATTR: 'data-react-props',
12-
1312
// helper method for the mount and unmount methods to find the
1413
// `data-react-class` DOM elements
1514
findDOMNodes: function() {
16-
1715
// we will use fully qualified paths as we do not bind the callbacks
1816
var selector = '[' + window.ReactRailsUJS.CLASS_NAME_ATTR + ']';
1917

20-
if ($) return $(selector);
21-
22-
else return document.querySelectorAll(selector);
18+
if ($) {
19+
return $(selector);
20+
} else {
21+
return document.querySelectorAll(selector);
22+
}
2323
},
2424

2525
mountComponents: function() {
26-
var nodes = ReactRailsUJS.findDOMNodes();
26+
var nodes = window.ReactRailsUJS.findDOMNodes();
2727

2828
for (var i = 0; i < nodes.length; ++i) {
2929
var node = nodes[i];
@@ -57,30 +57,25 @@
5757
var handleEvent;
5858

5959
if ($) {
60-
6160
handleEvent = function(eventName, callback) {
6261
$(document).on(eventName, callback);
6362
};
6463

6564
} else {
66-
6765
handleEvent = function(eventName, callback) {
6866
document.addEventListener(eventName, callback);
6967
};
70-
7168
}
7269
handleEvent('page:change', window.ReactRailsUJS.mountComponents);
7370
handleEvent('page:receive', window.ReactRailsUJS.unmountComponents);
7471
}
7572

7673
function handleNativeEvents() {
77-
if ($) {
78-
74+
if ($) {
7975
$(window.ReactRailsUJS.mountComponents);
8076
$(window).unload(window.ReactRailsUJS.unmountComponents);
8177

8278
} else {
83-
8479
document.addEventListener('DOMContentLoaded', window.ReactRailsUJS.mountComponents);
8580
window.addEventListener('unload', window.ReactRailsUJS.unmountComponents);
8681
}

0 commit comments

Comments
 (0)