fix: move page-lifecycle and idb-getall-shim to dynamic modules (#804)

This would help with Rollup compat if we ever decided to switch to
Rollup
This commit is contained in:
Nolan Lawson 2018-12-13 22:55:04 -08:00 committed by GitHub
parent 25793e2fec
commit d5c0268ef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 21 deletions

View File

@ -15,10 +15,6 @@ import {
} from './constants' } from './constants'
import { addKnownInstance, deleteKnownInstance } from './knownInstances' import { addKnownInstance, deleteKnownInstance } from './knownInstances'
if (process.browser) {
require('indexeddb-getall-shim') // needed for Edge
}
const openReqs = {} const openReqs = {}
const databaseCache = {} const databaseCache = {}

View File

@ -1,10 +1,6 @@
import { Store } from 'svelte/store' import { Store } from 'svelte/store'
import { safeLocalStorage as LS } from '../_utils/safeLocalStorage' import { safeLocalStorage as LS } from '../_utils/safeLocalStorage'
import { importPageLifecycle } from '../_utils/asyncModules'
let lifecycle
if (process.browser) {
lifecycle = require('page-lifecycle/dist/lifecycle.mjs').default
}
function safeParse (str) { function safeParse (str) {
return !str ? undefined : (str === 'undefined' ? undefined : JSON.parse(str)) return !str ? undefined : (str === 'undefined' ? undefined : JSON.parse(str))
@ -35,12 +31,14 @@ export class LocalStorageStore extends Store {
}) })
}) })
if (process.browser) { if (process.browser) {
importPageLifecycle().then(lifecycle => {
lifecycle.addEventListener('statechange', e => { lifecycle.addEventListener('statechange', e => {
if (e.newState === 'passive') { if (e.newState === 'passive') {
console.log('saving LocalStorageStore...') console.log('saving LocalStorageStore...')
this.save() this.save()
} }
}) })
})
} }
} }

View File

@ -1,6 +1,8 @@
const getDefault = mod => mod.default
export const importTimeline = () => import( export const importTimeline = () => import(
/* webpackChunkName: 'Timeline' */ '../_components/timeline/Timeline.html' /* webpackChunkName: 'Timeline' */ '../_components/timeline/Timeline.html'
).then(mod => mod.default) ).then(getDefault)
export const importIntersectionObserver = () => import( export const importIntersectionObserver = () => import(
/* webpackChunkName: 'intersection-observer' */ 'intersection-observer' /* webpackChunkName: 'intersection-observer' */ 'intersection-observer'
@ -14,22 +16,30 @@ export const importWebAnimationPolyfill = () => import(
/* webpackChunkName: 'web-animations-js' */ 'web-animations-js' /* webpackChunkName: 'web-animations-js' */ 'web-animations-js'
) )
export const importIndexedDBGetAllShim = () => import(
/* webpackChunkName: 'indexeddb-getall-shim' */ 'indexeddb-getall-shim'
)
export const importPageLifecycle = () => import(
/* webpackChunkName: 'page-lifecycle' */ 'page-lifecycle/dist/lifecycle.mjs'
).then(getDefault)
export const importWebSocketClient = () => import( export const importWebSocketClient = () => import(
/* webpackChunkName: '@gamestdio/websocket' */ '@gamestdio/websocket' /* webpackChunkName: '@gamestdio/websocket' */ '@gamestdio/websocket'
).then(mod => mod.default) ).then(getDefault)
export const importVirtualList = () => import( export const importVirtualList = () => import(
/* webpackChunkName: 'VirtualList.html' */ '../_components/virtualList/VirtualList.html' /* webpackChunkName: 'VirtualList.html' */ '../_components/virtualList/VirtualList.html'
).then(mod => mod.default) ).then(getDefault)
export const importList = () => import( export const importList = () => import(
/* webpackChunkName: 'List.html' */ '../_components/list/List.html' /* webpackChunkName: 'List.html' */ '../_components/list/List.html'
).then(mod => mod.default) ).then(getDefault)
export const importStatusVirtualListItem = () => import( export const importStatusVirtualListItem = () => import(
/* webpackChunkName: 'StatusVirtualListItem.html' */ '../_components/timeline/StatusVirtualListItem.html' /* webpackChunkName: 'StatusVirtualListItem.html' */ '../_components/timeline/StatusVirtualListItem.html'
).then(mod => mod.default) ).then(getDefault)
export const importNotificationVirtualListItem = () => import( export const importNotificationVirtualListItem = () => import(
/* webpackChunkName: 'NotificationVirtualListItem.html' */ '../_components/timeline/NotificationVirtualListItem.html' /* webpackChunkName: 'NotificationVirtualListItem.html' */ '../_components/timeline/NotificationVirtualListItem.html'
).then(mod => mod.default) ).then(getDefault)

View File

@ -1,4 +1,5 @@
import { import {
importIndexedDBGetAllShim,
importIntersectionObserver, importIntersectionObserver,
importRequestIdleCallback, importRequestIdleCallback,
importWebAnimationPolyfill importWebAnimationPolyfill
@ -8,6 +9,7 @@ export function loadPolyfills () {
return Promise.all([ return Promise.all([
typeof IntersectionObserver === 'undefined' && importIntersectionObserver(), typeof IntersectionObserver === 'undefined' && importIntersectionObserver(),
typeof requestIdleCallback === 'undefined' && importRequestIdleCallback(), typeof requestIdleCallback === 'undefined' && importRequestIdleCallback(),
!Element.prototype.animate && importWebAnimationPolyfill() !Element.prototype.animate && importWebAnimationPolyfill(),
!IDBObjectStore.prototype.getAll && importIndexedDBGetAllShim()
]) ])
} }