From e21224067bf5250f4d87894fbaa7c53883184e4f Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 27 Jan 2018 16:31:26 -0800 Subject: [PATCH] refactor --- routes/_utils/loadPolyfills.js | 17 +++++++++++++++++ templates/main.js | 18 ++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 routes/_utils/loadPolyfills.js diff --git a/routes/_utils/loadPolyfills.js b/routes/_utils/loadPolyfills.js new file mode 100644 index 00000000..b88ea953 --- /dev/null +++ b/routes/_utils/loadPolyfills.js @@ -0,0 +1,17 @@ +import { + importURLSearchParams, + importIntersectionObserver, + importRequestIdleCallback, + importIndexedDBGetAllShim, + importDialogPolyfill +} from './asyncModules' + +export function loadPolyfills() { + return Promise.all([ + typeof URLSearchParams === 'undefined' && importURLSearchParams(), + typeof IntersectionObserver === 'undefined' && importIntersectionObserver(), + typeof requestIdleCallback === 'undefined' && importRequestIdleCallback(), + !IDBObjectStore.prototype.getAll && importIndexedDBGetAllShim(), + typeof HTMLDialogElement === 'undefined' && importDialogPolyfill() + ]) +} \ No newline at end of file diff --git a/templates/main.js b/templates/main.js index 5c6ede6f..5fd13159 100644 --- a/templates/main.js +++ b/templates/main.js @@ -1,23 +1,9 @@ import { init } from 'sapper/runtime.js' import { offlineNotifiction } from '../routes/_utils/offlineNotification' import { serviceWorkerClient } from '../routes/_utils/serviceWorkerClient' +import { loadPolyfills } from '../routes/_utils/loadPolyfills' -import { - importURLSearchParams, - importIntersectionObserver, - importRequestIdleCallback, - importIndexedDBGetAllShim, - importDialogPolyfill -} from '../routes/_utils/asyncModules' - -// polyfills -Promise.all([ - typeof URLSearchParams === 'undefined' && importURLSearchParams(), - typeof IntersectionObserver === 'undefined' && importIntersectionObserver(), - typeof requestIdleCallback === 'undefined' && importRequestIdleCallback(), - !IDBObjectStore.prototype.getAll && importIndexedDBGetAllShim(), - typeof HTMLDialogElement === 'undefined' && importDialogPolyfill() -]).then(() => { +loadPolyfills().then(() => { // `routes` is an array of route objects injected by Sapper init(document.querySelector('#sapper'), __routes__) }) \ No newline at end of file