Skip to content

Commit

Permalink
Rename to avoid collision with browser globals
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Nov 8, 2019
1 parent 50997b3 commit c647e9c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const PopAction = 'POP';
const PushAction = 'PUSH';
const ReplaceAction = 'REPLACE';

const BeforeUnloadEvent = 'beforeunload';
const PopStateEvent = 'popstate';
const HashChangeEvent = 'hashchange';
const BeforeUnloadEventType = 'beforeunload';
const PopStateEventType = 'popstate';
const HashChangeEventType = 'hashchange';

// There's some duplication in this code, but only one create* method
// should ever be used in a given web page, so it's best for minifying
Expand Down Expand Up @@ -224,7 +224,7 @@ export const createBrowserHistory = ({
}
};

window.addEventListener(PopStateEvent, handlePop);
window.addEventListener(PopStateEventType, handlePop);

let action = PopAction;
let [index, location] = getIndexAndLocation();
Expand Down Expand Up @@ -319,7 +319,7 @@ export const createBrowserHistory = ({
let unblock = blockers.push(fn);

if (blockers.length === 1) {
window.addEventListener(BeforeUnloadEvent, promptBeforeUnload);
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
}

return () => {
Expand All @@ -329,7 +329,7 @@ export const createBrowserHistory = ({
// still be salvageable in the pagehide event.
// See https://html.spec.whatwg.org/#unloading-documents
if (!blockers.length) {
window.removeEventListener(BeforeUnloadEvent, promptBeforeUnload);
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
};
};
Expand Down Expand Up @@ -426,11 +426,11 @@ export const createHashHistory = ({ window = document.defaultView } = {}) => {
}
};

window.addEventListener(PopStateEvent, handlePop);
window.addEventListener(PopStateEventType, handlePop);

// TODO: Is this still necessary? Which browsers do
// not trigger popstate when the hash changes?
window.addEventListener(HashChangeEvent, event => {
window.addEventListener(HashChangeEventType, event => {
let [, nextLocation] = getIndexAndLocation();

// Ignore extraneous hashchange events.
Expand Down Expand Up @@ -561,7 +561,7 @@ export const createHashHistory = ({ window = document.defaultView } = {}) => {
let unblock = blockers.push(fn);

if (blockers.length === 1) {
window.addEventListener(BeforeUnloadEvent, promptBeforeUnload);
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
}

return () => {
Expand All @@ -571,7 +571,7 @@ export const createHashHistory = ({ window = document.defaultView } = {}) => {
// still be salvageable in the pagehide event.
// See https://html.spec.whatwg.org/#unloading-documents
if (!blockers.length) {
window.removeEventListener(BeforeUnloadEvent, promptBeforeUnload);
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
}
};
};
Expand Down

0 comments on commit c647e9c

Please sign in to comment.