From 6c58052684a824d8a81829cd1f0c4fdb0d8d32dd Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 23 Jul 2019 20:33:31 -0700 Subject: [PATCH] fix: remove unnecessary function cache (#1358) This is just a bit of code cleanup; I think this cache logic is excessive --- src/routes/_utils/isMobile.js | 11 ----------- src/routes/_utils/runMediumPriorityTask.js | 7 +++++-- 2 files changed, 5 insertions(+), 13 deletions(-) delete mode 100644 src/routes/_utils/isMobile.js diff --git a/src/routes/_utils/isMobile.js b/src/routes/_utils/isMobile.js deleted file mode 100644 index b272a337..00000000 --- a/src/routes/_utils/isMobile.js +++ /dev/null @@ -1,11 +0,0 @@ -// Rough guess at whether this is a "mobile" device or not, for the purposes -// of "device class" estimations - -let cached - -export function isMobile () { - if (typeof cached === 'undefined') { - cached = !!(process.browser && navigator.userAgent.match(/(iPhone|iPod|iPad|Android)/)) - } - return cached -} diff --git a/src/routes/_utils/runMediumPriorityTask.js b/src/routes/_utils/runMediumPriorityTask.js index 9696b396..5e489af1 100644 --- a/src/routes/_utils/runMediumPriorityTask.js +++ b/src/routes/_utils/runMediumPriorityTask.js @@ -1,6 +1,9 @@ import { scheduleIdleTask } from './scheduleIdleTask' import { store } from '../_store/store' -import { isMobile } from './isMobile' + +// Rough guess at whether this is a "mobile" device or not, for the purposes +// of "device class" estimations +const IS_MOBILE = process.browser && navigator.userAgent.match(/(?:iPhone|iPod|iPad|Android)/) // Run a task that doesn't need to be processed immediately, but should // probably be delayed if we're on a mobile device. Also run it sooner @@ -8,7 +11,7 @@ import { isMobile } from './isMobile' export function runMediumPriorityTask (fn) { if (store.get().pageVisibilityHidden) { fn() - } else if (isMobile()) { + } else if (IS_MOBILE) { scheduleIdleTask(fn) } else { requestAnimationFrame(fn)