fix requestIdleCallback usage

This commit is contained in:
Nolan Lawson 2018-02-20 21:29:59 -08:00
parent ea3f5a33fb
commit a73e4b13c4
4 changed files with 11 additions and 12 deletions

View File

@ -208,7 +208,9 @@
stop('handleItemIdsToAdd') stop('handleItemIdsToAdd')
} }
this.observe('itemIdsToAddStringified', itemIdsToAddStringified => { this.observe('itemIdsToAddStringified', itemIdsToAddStringified => {
if (itemIdsToAddStringified) {
scheduleIdleTask(handleItemIdsToAdd) scheduleIdleTask(handleItemIdsToAdd)
}
}) })
}, },
setupFocus() { setupFocus() {

View File

@ -1,17 +1,19 @@
import { setFavicon } from '../_utils/setFavicon' import { setFavicon } from '../_utils/setFavicon'
import { scheduleIdleTask } from '../_utils/scheduleIdleTask' import { scheduleIdleTask } from '../_utils/scheduleIdleTask'
let currentFaviconHasNotifications = false
export function notificationObservers (store) { export function notificationObservers (store) {
store.observe('hasNotifications', hasNotifications => { store.observe('hasNotifications', hasNotifications => {
if (!process.browser) { if (!process.browser) {
return return
} }
scheduleIdleTask(() => { if (currentFaviconHasNotifications === hasNotifications) {
if (hasNotifications) { return
setFavicon('/favicon-alert.png')
} else {
setFavicon('/favicon.png')
} }
scheduleIdleTask(() => {
setFavicon(hasNotifications ? '/favicon-alert.png' : '/favicon.png')
currentFaviconHasNotifications = !currentFaviconHasNotifications
}) })
}) })
} }

View File

@ -41,10 +41,7 @@ export const store = new PinaforeStore({
mixins(PinaforeStore) mixins(PinaforeStore)
computations(store) computations(store)
observers(store)
export function initStore () {
observers(store)
}
if (process.browser && process.env.NODE_ENV !== 'production') { if (process.browser && process.env.NODE_ENV !== 'production') {
window.store = store // for debugging window.store = store // for debugging

View File

@ -1,5 +1,4 @@
import { init } from 'sapper/runtime.js' import { init } from 'sapper/runtime.js'
import { initStore } from '../routes/_store/store'
import { loadPolyfills } from '../routes/_utils/loadPolyfills' import { loadPolyfills } from '../routes/_utils/loadPolyfills'
import '../routes/_utils/offlineNotification' import '../routes/_utils/offlineNotification'
import '../routes/_utils/serviceWorkerClient' import '../routes/_utils/serviceWorkerClient'
@ -8,6 +7,5 @@ import '../routes/_utils/loadingMask'
loadPolyfills().then(() => { loadPolyfills().then(() => {
// `routes` is an array of route objects injected by Sapper // `routes` is an array of route objects injected by Sapper
initStore()
init(document.querySelector('#sapper'), __routes__) init(document.querySelector('#sapper'), __routes__)
}) })