Skip to content

Commit

Permalink
Scope willRender to PageRenderer only
Browse files Browse the repository at this point in the history
The `willRender` property introduced to the generic `Renderer<E, S>`
only applies to the `PageRenderer` specialized sub-class. This commit
removes it from the root class and declares a
`PageRenderer.constructor()` method to accept and assign it.
  • Loading branch information
seanpdoyle committed Dec 31, 2022
1 parent 9defbe0 commit 2aaba5c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
15 changes: 14 additions & 1 deletion src/core/drive/page_renderer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Renderer } from "../renderer"
import { Render, Renderer } from "../renderer"
import { PageSnapshot } from "./page_snapshot"
import { ReloadReason } from "../native/browser_adapter"
import { activateScriptElement, waitForLoad } from "../../util"

export class PageRenderer extends Renderer<HTMLBodyElement, PageSnapshot> {
private readonly willRender: boolean

static renderElement(currentElement: HTMLBodyElement, newElement: HTMLBodyElement) {
if (document.body && newElement instanceof HTMLBodyElement) {
document.body.replaceWith(newElement)
Expand All @@ -12,6 +14,17 @@ export class PageRenderer extends Renderer<HTMLBodyElement, PageSnapshot> {
}
}

constructor(
currentSnapshot: PageSnapshot,
newSnapshot: PageSnapshot,
renderElement: Render<HTMLBodyElement>,
isPreview: boolean,
willRender = true
) {
super(currentSnapshot, newSnapshot, renderElement, isPreview)
this.willRender = willRender
}

get shouldRender() {
return this.newSnapshot.isVisitable && this.trackedElementsAreIdentical
}
Expand Down
9 changes: 1 addition & 8 deletions src/core/frames/frame_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,7 @@ export class FrameController

if (newFrameElement) {
const snapshot = new Snapshot(newFrameElement)
const renderer = new FrameRenderer(
this,
this.view.snapshot,
snapshot,
FrameRenderer.renderElement,
false,
false
)
const renderer = new FrameRenderer(this, this.view.snapshot, snapshot, FrameRenderer.renderElement, false)
if (this.view.renderPromise) await this.view.renderPromise
this.changeHistory()

Expand Down
5 changes: 2 additions & 3 deletions src/core/frames/frame_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ export class FrameRenderer extends Renderer<FrameElement> {
currentSnapshot: Snapshot<FrameElement>,
newSnapshot: Snapshot<FrameElement>,
renderElement: Render<FrameElement>,
isPreview: boolean,
willRender = true
isPreview: boolean
) {
super(currentSnapshot, newSnapshot, renderElement, isPreview, willRender)
super(currentSnapshot, newSnapshot, renderElement, isPreview)
this.delegate = delegate
}

Expand Down
4 changes: 1 addition & 3 deletions src/core/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ export abstract class Renderer<E extends Element, S extends Snapshot<E> = Snapsh
readonly currentSnapshot: S
readonly newSnapshot: S
readonly isPreview: boolean
readonly willRender: boolean
readonly promise: Promise<void>
renderElement: Render<E>
private resolvingFunctions?: ResolvingFunctions<void>
private activeElement: Element | null = null

constructor(currentSnapshot: S, newSnapshot: S, renderElement: Render<E>, isPreview: boolean, willRender = true) {
constructor(currentSnapshot: S, newSnapshot: S, renderElement: Render<E>, isPreview: boolean) {
this.currentSnapshot = currentSnapshot
this.newSnapshot = newSnapshot
this.isPreview = isPreview
this.willRender = willRender
this.renderElement = renderElement
this.promise = new Promise((resolve, reject) => (this.resolvingFunctions = { resolve, reject }))
}
Expand Down

0 comments on commit 2aaba5c

Please sign in to comment.