1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

use Promise to update head (#574)

This commit is contained in:
Naoyuki Kanezawa 2016-12-31 04:14:36 +09:00 committed by Guillermo Rauch
parent 1fbf324883
commit f7ee50323d

View file

@ -10,14 +10,14 @@ const DOMAttributeNames = {
export default class HeadManager {
constructor () {
this.requestId = null
this.updatePromise = null
}
updateHead (head) {
// perform batch update
window.cancelAnimationFrame(this.requestId)
this.requestId = window.requestAnimationFrame(() => {
this.requestId = null
const promise = this.updatePromise = Promise.resolve().then(() => {
if (promise !== this.updatePromise) return
this.updatePromise = null
this.doUpdateHead(head)
})
}