fix requestIdleCallback usage
This commit is contained in:
		
							parent
							
								
									ea3f5a33fb
								
							
						
					
					
						commit
						a73e4b13c4
					
				
					 4 changed files with 11 additions and 12 deletions
				
			
		| 
						 | 
				
			
			@ -208,7 +208,9 @@
 | 
			
		|||
          stop('handleItemIdsToAdd')
 | 
			
		||||
        }
 | 
			
		||||
        this.observe('itemIdsToAddStringified', itemIdsToAddStringified => {
 | 
			
		||||
          scheduleIdleTask(handleItemIdsToAdd)
 | 
			
		||||
          if (itemIdsToAddStringified) {
 | 
			
		||||
            scheduleIdleTask(handleItemIdsToAdd)
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
      },
 | 
			
		||||
      setupFocus() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,17 +1,19 @@
 | 
			
		|||
import { setFavicon } from '../_utils/setFavicon'
 | 
			
		||||
import { scheduleIdleTask } from '../_utils/scheduleIdleTask'
 | 
			
		||||
 | 
			
		||||
let currentFaviconHasNotifications = false
 | 
			
		||||
 | 
			
		||||
export function notificationObservers (store) {
 | 
			
		||||
  store.observe('hasNotifications', hasNotifications => {
 | 
			
		||||
    if (!process.browser) {
 | 
			
		||||
      return
 | 
			
		||||
    }
 | 
			
		||||
    if (currentFaviconHasNotifications === hasNotifications) {
 | 
			
		||||
      return
 | 
			
		||||
    }
 | 
			
		||||
    scheduleIdleTask(() => {
 | 
			
		||||
      if (hasNotifications) {
 | 
			
		||||
        setFavicon('/favicon-alert.png')
 | 
			
		||||
      } else {
 | 
			
		||||
        setFavicon('/favicon.png')
 | 
			
		||||
      }
 | 
			
		||||
      setFavicon(hasNotifications ? '/favicon-alert.png' : '/favicon.png')
 | 
			
		||||
      currentFaviconHasNotifications = !currentFaviconHasNotifications
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,10 +41,7 @@ export const store = new PinaforeStore({
 | 
			
		|||
 | 
			
		||||
mixins(PinaforeStore)
 | 
			
		||||
computations(store)
 | 
			
		||||
 | 
			
		||||
export function initStore () {
 | 
			
		||||
  observers(store)
 | 
			
		||||
}
 | 
			
		||||
observers(store)
 | 
			
		||||
 | 
			
		||||
if (process.browser && process.env.NODE_ENV !== 'production') {
 | 
			
		||||
  window.store = store // for debugging
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,4 @@
 | 
			
		|||
import { init } from 'sapper/runtime.js'
 | 
			
		||||
import { initStore } from '../routes/_store/store'
 | 
			
		||||
import { loadPolyfills } from '../routes/_utils/loadPolyfills'
 | 
			
		||||
import '../routes/_utils/offlineNotification'
 | 
			
		||||
import '../routes/_utils/serviceWorkerClient'
 | 
			
		||||
| 
						 | 
				
			
			@ -8,6 +7,5 @@ import '../routes/_utils/loadingMask'
 | 
			
		|||
 | 
			
		||||
loadPolyfills().then(() => {
 | 
			
		||||
  // `routes` is an array of route objects injected by Sapper
 | 
			
		||||
  initStore()
 | 
			
		||||
  init(document.querySelector('#sapper'), __routes__)
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue