Skip to content

Commit

Permalink
Add patch for preventDefault to library.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenshank committed Jul 9, 2019
1 parent a4a4121 commit 839b645
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 51 deletions.
53 changes: 2 additions & 51 deletions src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as FASTA from "./app/FASTA.jsx";
import * as FNA from "./app/FNA.jsx";
import * as BAM from "./app/BAM.jsx";
import Components from "./app/Components.jsx";
import PreventDefaultPatch from "./prevent_default_patch";
import "./app/styles.scss";

function Divider(props) {
Expand Down Expand Up @@ -153,57 +154,7 @@ function Main(props) {
);
}

/* Temporary fix for a breaking change in Chrome to React
* See https://github.com/facebook/react/issues/14856
*/
const EVENTS_TO_MODIFY = [
"touchstart",
"touchmove",
"touchend",
"touchcancel",
"wheel"
];

const originalAddEventListener = document.addEventListener.bind();
document.addEventListener = (type, listener, options, wantsUntrusted) => {
let modOptions = options;
if (EVENTS_TO_MODIFY.includes(type)) {
if (typeof options === "boolean") {
modOptions = {
capture: options,
passive: false
};
} else if (typeof options === "object") {
modOptions = {
...options,
passive: false
};
}
}

return originalAddEventListener(type, listener, modOptions, wantsUntrusted);
};

const originalRemoveEventListener = document.removeEventListener.bind();
document.removeEventListener = (type, listener, options) => {
let modOptions = options;
if (EVENTS_TO_MODIFY.includes(type)) {
if (typeof options === "boolean") {
modOptions = {
capture: options,
passive: false
};
} else if (typeof options === "object") {
modOptions = {
...options,
passive: false
};
}
}
return originalRemoveEventListener(type, listener, modOptions);
};
// End of temporary fix

PreventDefaultPatch(document);
ReactDOM.render(
<Main />,
document.body.appendChild(document.createElement("div"))
Expand Down
3 changes: 3 additions & 0 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import fastaParser from "./helpers/fasta";
import computeLabelWidth from "./helpers/computeLabelWidth";
import ScrollBroadcaster from "./helpers/ScrollBroadcaster";
import * as colors from "./helpers/colors";
import PreventDefaultPatch from "./prevent_default_patch";

require("./app/styles.scss");

PreventDefaultPatch(document);

export default Alignment;
export {
BAMViewer,
Expand Down
52 changes: 52 additions & 0 deletions src/prevent_default_patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Temporary fix for a breaking change in Chrome to React
* See https://github.com/facebook/react/issues/14856
*/

export default function(document) {
const EVENTS_TO_MODIFY = [
"touchstart",
"touchmove",
"touchend",
"touchcancel",
"wheel"
];

const originalAddEventListener = document.addEventListener.bind();
document.addEventListener = (type, listener, options, wantsUntrusted) => {
let modOptions = options;
if (EVENTS_TO_MODIFY.includes(type)) {
if (typeof options === "boolean") {
modOptions = {
capture: options,
passive: false
};
} else if (typeof options === "object") {
modOptions = {
...options,
passive: false
};
}
}

return originalAddEventListener(type, listener, modOptions, wantsUntrusted);
};

const originalRemoveEventListener = document.removeEventListener.bind();
document.removeEventListener = (type, listener, options) => {
let modOptions = options;
if (EVENTS_TO_MODIFY.includes(type)) {
if (typeof options === "boolean") {
modOptions = {
capture: options,
passive: false
};
} else if (typeof options === "object") {
modOptions = {
...options,
passive: false
};
}
}
return originalRemoveEventListener(type, listener, modOptions);
};
}

0 comments on commit 839b645

Please sign in to comment.