From bf7fefd58b90c0860507b49df31ce8d6a753d91d Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Tue, 3 Sep 2019 14:01:20 -0400 Subject: [PATCH] refactor: Remove dom-helpers --- package.json | 1 - src/BrowserProtocol.js | 6 ++---- src/HashProtocol.js | 6 ++---- src/createTransitionHookMiddleware.js | 6 ++---- yarn.lock | 14 -------------- 5 files changed, 6 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 61f996d..ad8f194 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ }, "homepage": "https://github.com/4Catalyzer/farce#readme", "dependencies": { - "dom-helpers": "^3.4.0", "invariant": "^2.2.4", "is-promise": "^2.1.0", "query-string": "^5.1.1", diff --git a/src/BrowserProtocol.js b/src/BrowserProtocol.js index 10402ad..0076c72 100644 --- a/src/BrowserProtocol.js +++ b/src/BrowserProtocol.js @@ -1,5 +1,3 @@ -import off from 'dom-helpers/events/off'; -import on from 'dom-helpers/events/on'; import invariant from 'invariant'; import createPath from './utils/createPath'; @@ -41,8 +39,8 @@ export default class BrowserProtocol { // TODO: On most versions of IE, we need a hashChange listener for hash- // only changes. - on(window, 'popstate', onPopState); - return () => off(window, 'popstate', onPopState); + window.addEventListener('popstate', onPopState); + return () => window.removeEventListener('popstate', onPopState); } transition(location) { diff --git a/src/HashProtocol.js b/src/HashProtocol.js index 0240e1b..90c3190 100644 --- a/src/HashProtocol.js +++ b/src/HashProtocol.js @@ -1,5 +1,3 @@ -import off from 'dom-helpers/events/off'; -import on from 'dom-helpers/events/on'; import invariant from 'invariant'; import StateStorage from './StateStorage'; @@ -42,8 +40,8 @@ export default class HashProtocol { listener(this.init()); }; - on(window, 'hashchange', onHashChange); - return () => off(window, 'hashchange', onHashChange); + window.addEventListener('hashchange', onHashChange); + return () => window.removeEventListener('hashchange', onHashChange); } transition(location) { diff --git a/src/createTransitionHookMiddleware.js b/src/createTransitionHookMiddleware.js index 391a33a..c1bfbce 100644 --- a/src/createTransitionHookMiddleware.js +++ b/src/createTransitionHookMiddleware.js @@ -1,5 +1,3 @@ -import off from 'dom-helpers/events/off'; -import on from 'dom-helpers/events/on'; import isPromise from 'is-promise'; import warning from 'warning'; @@ -115,7 +113,7 @@ export default function createTransitionHookMiddleware({ return resultSafe; }; - on(window, 'beforeunload', onBeforeUnload); + window.addEventListener('beforeunload', onBeforeUnload); } return next(action); @@ -207,7 +205,7 @@ export default function createTransitionHookMiddleware({ } case ActionTypes.DISPOSE: if (onBeforeUnload) { - off(window, 'beforeunload', onBeforeUnload); + window.removeEventListener('beforeunload', onBeforeUnload); onBeforeUnload = null; } diff --git a/yarn.lock b/yarn.lock index d33ef57..aeb1513 100644 --- a/yarn.lock +++ b/yarn.lock @@ -782,13 +782,6 @@ "@babel/plugin-transform-react-jsx-self" "^7.0.0" "@babel/plugin-transform-react-jsx-source" "^7.0.0" -"@babel/runtime@^7.1.2": - version "7.5.5" - resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.5.5.tgz#74fba56d35efbeca444091c7850ccd494fd2f132" - integrity sha512-28QvEGyQyNkB0/m2B4FU7IEZGK2NUrcMtT6BZEFALTguLk+AUT6ofsHtPk5QyjAdUkpMJ+/Em+quwz4HOt30AQ== - dependencies: - regenerator-runtime "^0.13.2" - "@babel/template@^7.1.0", "@babel/template@^7.4.0", "@babel/template@^7.4.4": version "7.4.4" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.4.4.tgz#f4b88d1225689a08f5bc3a17483545be9e4ed237" @@ -2387,13 +2380,6 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" -dom-helpers@^3.4.0: - version "3.4.0" - resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.4.0.tgz#e9b369700f959f62ecde5a6babde4bccd9169af8" - integrity sha512-LnuPJ+dwqKDIyotW1VzmOZ5TONUN7CwkCR5hrgawTUbkBGYdeoNLZo6nNfGkCrjtE1nXXaj7iMMpDa8/d9WoIA== - dependencies: - "@babel/runtime" "^7.1.2" - dom-serialize@^2.2.0: version "2.2.1" resolved "https://registry.yarnpkg.com/dom-serialize/-/dom-serialize-2.2.1.tgz#562ae8999f44be5ea3076f5419dcd59eb43ac95b"