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:
parent
25793e2fec
commit
d5c0268ef2
|
@ -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 = {}
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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()
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue