-
Notifications
You must be signed in to change notification settings - Fork 431
/
error_renderer.js
39 lines (32 loc) · 1.03 KB
/
error_renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { activateScriptElement } from "../../util"
import { Renderer } from "../renderer"
export class ErrorRenderer extends Renderer {
static renderElement(currentElement, newElement) {
const { documentElement, body } = document
documentElement.replaceChild(newElement, body)
}
async render() {
this.replaceHeadAndBody()
this.activateScriptElements()
}
replaceHeadAndBody() {
const { documentElement, head } = document
documentElement.replaceChild(this.newHead, head)
this.renderElement(this.currentElement, this.newElement)
}
activateScriptElements() {
for (const replaceableElement of this.scriptElements) {
const parentNode = replaceableElement.parentNode
if (parentNode) {
const element = activateScriptElement(replaceableElement)
parentNode.replaceChild(element, replaceableElement)
}
}
}
get newHead() {
return this.newSnapshot.headSnapshot.element
}
get scriptElements() {
return document.documentElement.querySelectorAll("script")
}
}