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:
parent
1fbf324883
commit
f7ee50323d
|
@ -10,14 +10,14 @@ const DOMAttributeNames = {
|
||||||
|
|
||||||
export default class HeadManager {
|
export default class HeadManager {
|
||||||
constructor () {
|
constructor () {
|
||||||
this.requestId = null
|
this.updatePromise = null
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHead (head) {
|
updateHead (head) {
|
||||||
// perform batch update
|
const promise = this.updatePromise = Promise.resolve().then(() => {
|
||||||
window.cancelAnimationFrame(this.requestId)
|
if (promise !== this.updatePromise) return
|
||||||
this.requestId = window.requestAnimationFrame(() => {
|
|
||||||
this.requestId = null
|
this.updatePromise = null
|
||||||
this.doUpdateHead(head)
|
this.doUpdateHead(head)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue