2019-10-15 03:00:57 +00:00
|
|
|
// the page-lifecycle package causes some problems (doesn't work in node),
|
|
|
|
// and plus it's not needed immediately, so lazy-load it
|
2019-10-30 01:58:49 +00:00
|
|
|
import { importPageLifecycle } from './asyncModules/importPageLifecycle.js'
|
2019-10-15 03:00:57 +00:00
|
|
|
|
|
|
|
function addEventListener (event, func) {
|
2021-03-14 17:20:23 +00:00
|
|
|
if (process.browser && !process.env.IS_SERVICE_WORKER) {
|
2019-10-15 03:00:57 +00:00
|
|
|
importPageLifecycle().then(lifecycle => {
|
|
|
|
lifecycle.addEventListener(event, func)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeEventListener (event, func) {
|
2021-03-14 17:20:23 +00:00
|
|
|
if (process.browser && !process.env.IS_SERVICE_WORKER) {
|
2019-10-15 03:00:57 +00:00
|
|
|
importPageLifecycle().then(lifecycle => {
|
|
|
|
lifecycle.removeEventListener(event, func)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const lifecycle = { addEventListener, removeEventListener }
|