Skip to content

Commit 23d6e2a

Browse files
committed
fix(JQuery3): ensure react is mounted in Jquery3
1 parent 96a0fbd commit 23d6e2a

File tree

7 files changed

+97
-130
lines changed

7 files changed

+97
-130
lines changed

gemfiles/.bundle/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
BUNDLE_RETRY: "1"

lib/assets/javascripts/react_ujs.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,7 @@ module.exports = function(ujs) {
128128
nativeEvents.teardown(ujs);
129129
}
130130

131-
if (ujs.jQuery) {
132-
ujs.handleEvent = function(eventName, callback) {
133-
ujs.jQuery(document).on(eventName, callback);
134-
};
135-
ujs.removeEvent = function(eventName, callback) {
136-
ujs.jQuery(document).off(eventName, callback);
137-
}
138-
} else if ('addEventListener' in window) {
131+
if ('addEventListener' in window) {
139132
ujs.handleEvent = function(eventName, callback) {
140133
document.addEventListener(eventName, callback);
141134
};
@@ -387,10 +380,7 @@ module.exports = {
387380
// Attach handlers to browser events to mount
388381
// (There are no unmount handlers since the page is destroyed on navigation)
389382
setup: function(ujs) {
390-
if (ujs.jQuery) {
391-
// Use jQuery if it's present:
392-
ujs.handleEvent("ready", ujs.handleMount);
393-
} else if ('addEventListener' in window) {
383+
if ('addEventListener' in window) {
394384
ujs.handleEvent('DOMContentLoaded', ujs.handleMount);
395385
} else {
396386
// add support to IE8 without jQuery
@@ -399,7 +389,6 @@ module.exports = {
399389
},
400390

401391
teardown: function(ujs) {
402-
ujs.removeEvent("ready", ujs.handleMount);
403392
ujs.removeEvent('DOMContentLoaded', ujs.handleMount);
404393
ujs.removeEvent('onload', ujs.handleMount);
405394
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"webpack": "^2.3.3"
1515
},
1616
"dependencies": {
17-
"react_ujs": "^2.4.2"
17+
"react_ujs": "^2.4.3"
1818
}
1919
}

react_ujs/dist/react_ujs.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,7 @@ module.exports = function(ujs) {
128128
nativeEvents.teardown(ujs);
129129
}
130130

131-
if (ujs.jQuery) {
132-
ujs.handleEvent = function(eventName, callback) {
133-
ujs.jQuery(document).on(eventName, callback);
134-
};
135-
ujs.removeEvent = function(eventName, callback) {
136-
ujs.jQuery(document).off(eventName, callback);
137-
}
138-
} else if ('addEventListener' in window) {
131+
if ('addEventListener' in window) {
139132
ujs.handleEvent = function(eventName, callback) {
140133
document.addEventListener(eventName, callback);
141134
};
@@ -387,10 +380,7 @@ module.exports = {
387380
// Attach handlers to browser events to mount
388381
// (There are no unmount handlers since the page is destroyed on navigation)
389382
setup: function(ujs) {
390-
if (ujs.jQuery) {
391-
// Use jQuery if it's present:
392-
ujs.handleEvent("ready", ujs.handleMount);
393-
} else if ('addEventListener' in window) {
383+
if ('addEventListener' in window) {
394384
ujs.handleEvent('DOMContentLoaded', ujs.handleMount);
395385
} else {
396386
// add support to IE8 without jQuery
@@ -399,7 +389,6 @@ module.exports = {
399389
},
400390

401391
teardown: function(ujs) {
402-
ujs.removeEvent("ready", ujs.handleMount);
403392
ujs.removeEvent('DOMContentLoaded', ujs.handleMount);
404393
ujs.removeEvent('onload', ujs.handleMount);
405394
}

react_ujs/src/events/detect.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@ module.exports = function(ujs) {
1818
nativeEvents.teardown(ujs);
1919
}
2020

21-
if (ujs.jQuery) {
22-
ujs.handleEvent = function(eventName, callback) {
23-
ujs.jQuery(document).on(eventName, callback);
24-
};
25-
ujs.removeEvent = function(eventName, callback) {
26-
ujs.jQuery(document).off(eventName, callback);
27-
}
28-
} else if ('addEventListener' in window) {
21+
if ('addEventListener' in window) {
2922
ujs.handleEvent = function(eventName, callback) {
3023
document.addEventListener(eventName, callback);
3124
};

react_ujs/src/events/native.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ module.exports = {
22
// Attach handlers to browser events to mount
33
// (There are no unmount handlers since the page is destroyed on navigation)
44
setup: function(ujs) {
5-
if (ujs.jQuery) {
6-
// Use jQuery if it's present:
7-
ujs.handleEvent("ready", ujs.handleMount);
8-
} else if ('addEventListener' in window) {
5+
if ('addEventListener' in window) {
96
ujs.handleEvent('DOMContentLoaded', ujs.handleMount);
107
} else {
118
// add support to IE8 without jQuery
@@ -14,7 +11,6 @@ module.exports = {
1411
},
1512

1613
teardown: function(ujs) {
17-
ujs.removeEvent("ready", ujs.handleMount);
1814
ujs.removeEvent('DOMContentLoaded', ujs.handleMount);
1915
ujs.removeEvent('onload', ujs.handleMount);
2016
}

0 commit comments

Comments
 (0)