Skip to content

Commit

Permalink
Merge pull request #867 from reactjs/fix-762
Browse files Browse the repository at this point in the history
fix(#762): ensure react is mounted in Jquery3
  • Loading branch information
BookOfGreg committed Feb 5, 2018
2 parents 318ae5b + 23d6e2a commit f17376f
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 130 deletions.
2 changes: 2 additions & 0 deletions gemfiles/.bundle/config
@@ -0,0 +1,2 @@
---
BUNDLE_RETRY: "1"
15 changes: 2 additions & 13 deletions lib/assets/javascripts/react_ujs.js
Expand Up @@ -128,14 +128,7 @@ module.exports = function(ujs) {
nativeEvents.teardown(ujs);
}

if (ujs.jQuery) {
ujs.handleEvent = function(eventName, callback) {
ujs.jQuery(document).on(eventName, callback);
};
ujs.removeEvent = function(eventName, callback) {
ujs.jQuery(document).off(eventName, callback);
}
} else if ('addEventListener' in window) {
if ('addEventListener' in window) {
ujs.handleEvent = function(eventName, callback) {
document.addEventListener(eventName, callback);
};
Expand Down Expand Up @@ -387,10 +380,7 @@ module.exports = {
// Attach handlers to browser events to mount
// (There are no unmount handlers since the page is destroyed on navigation)
setup: function(ujs) {
if (ujs.jQuery) {
// Use jQuery if it's present:
ujs.handleEvent("ready", ujs.handleMount);
} else if ('addEventListener' in window) {
if ('addEventListener' in window) {
ujs.handleEvent('DOMContentLoaded', ujs.handleMount);
} else {
// add support to IE8 without jQuery
Expand All @@ -399,7 +389,6 @@ module.exports = {
},

teardown: function(ujs) {
ujs.removeEvent("ready", ujs.handleMount);
ujs.removeEvent('DOMContentLoaded', ujs.handleMount);
ujs.removeEvent('onload', ujs.handleMount);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -14,6 +14,6 @@
"webpack": "^2.3.3"
},
"dependencies": {
"react_ujs": "^2.4.2"
"react_ujs": "^2.4.3"
}
}
15 changes: 2 additions & 13 deletions react_ujs/dist/react_ujs.js
Expand Up @@ -128,14 +128,7 @@ module.exports = function(ujs) {
nativeEvents.teardown(ujs);
}

if (ujs.jQuery) {
ujs.handleEvent = function(eventName, callback) {
ujs.jQuery(document).on(eventName, callback);
};
ujs.removeEvent = function(eventName, callback) {
ujs.jQuery(document).off(eventName, callback);
}
} else if ('addEventListener' in window) {
if ('addEventListener' in window) {
ujs.handleEvent = function(eventName, callback) {
document.addEventListener(eventName, callback);
};
Expand Down Expand Up @@ -387,10 +380,7 @@ module.exports = {
// Attach handlers to browser events to mount
// (There are no unmount handlers since the page is destroyed on navigation)
setup: function(ujs) {
if (ujs.jQuery) {
// Use jQuery if it's present:
ujs.handleEvent("ready", ujs.handleMount);
} else if ('addEventListener' in window) {
if ('addEventListener' in window) {
ujs.handleEvent('DOMContentLoaded', ujs.handleMount);
} else {
// add support to IE8 without jQuery
Expand All @@ -399,7 +389,6 @@ module.exports = {
},

teardown: function(ujs) {
ujs.removeEvent("ready", ujs.handleMount);
ujs.removeEvent('DOMContentLoaded', ujs.handleMount);
ujs.removeEvent('onload', ujs.handleMount);
}
Expand Down
9 changes: 1 addition & 8 deletions react_ujs/src/events/detect.js
Expand Up @@ -18,14 +18,7 @@ module.exports = function(ujs) {
nativeEvents.teardown(ujs);
}

if (ujs.jQuery) {
ujs.handleEvent = function(eventName, callback) {
ujs.jQuery(document).on(eventName, callback);
};
ujs.removeEvent = function(eventName, callback) {
ujs.jQuery(document).off(eventName, callback);
}
} else if ('addEventListener' in window) {
if ('addEventListener' in window) {
ujs.handleEvent = function(eventName, callback) {
document.addEventListener(eventName, callback);
};
Expand Down
6 changes: 1 addition & 5 deletions react_ujs/src/events/native.js
Expand Up @@ -2,10 +2,7 @@ module.exports = {
// Attach handlers to browser events to mount
// (There are no unmount handlers since the page is destroyed on navigation)
setup: function(ujs) {
if (ujs.jQuery) {
// Use jQuery if it's present:
ujs.handleEvent("ready", ujs.handleMount);
} else if ('addEventListener' in window) {
if ('addEventListener' in window) {
ujs.handleEvent('DOMContentLoaded', ujs.handleMount);
} else {
// add support to IE8 without jQuery
Expand All @@ -14,7 +11,6 @@ module.exports = {
},

teardown: function(ujs) {
ujs.removeEvent("ready", ujs.handleMount);
ujs.removeEvent('DOMContentLoaded', ujs.handleMount);
ujs.removeEvent('onload', ujs.handleMount);
}
Expand Down

0 comments on commit f17376f

Please sign in to comment.