Skip to content

Commit

Permalink
Remove renderElement from Renderer constructor
Browse files Browse the repository at this point in the history
Remove the argument from all `Renderer` subclass constructor call sites.
In its place, define the default value for the `Renderer.renderElement`
property based on the `static renderElement(currentElement, newElement)`
defined by the inheriting class.

For the sake of consistency, define `MorphRenderer.renderElement` to
no-op. Currently, the `MorphRenderer` class never invokes the
`renderElement` method, so a no-op won't have adverse effects.
  • Loading branch information
seanpdoyle committed Oct 8, 2023
1 parent 7b8f1be commit e94307f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/core/drive/morph_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { dispatch, nextAnimationFrame } from "../../util"
import { Renderer } from "../renderer"

export class MorphRenderer extends Renderer {
static renderElement(currentElement, newElement) {
}

async render() {
if (this.willRender) await this.#morphBody()
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/drive/page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class PageView extends View {
const shouldMorphPage = this.isPageRefresh(visit) && this.snapshot.shouldMorphPage
const rendererClass = shouldMorphPage ? MorphRenderer : PageRenderer

const renderer = new rendererClass(this.snapshot, snapshot, PageRenderer.renderElement, isPreview, willRender)
const renderer = new rendererClass(this.snapshot, snapshot, isPreview, willRender)

if (!renderer.shouldRender) {
this.forceReloaded = true
Expand All @@ -32,7 +32,7 @@ export class PageView extends View {

renderError(snapshot, visit) {
visit?.changeHistory()
const renderer = new ErrorRenderer(this.snapshot, snapshot, ErrorRenderer.renderElement, false)
const renderer = new ErrorRenderer(this.snapshot, snapshot, false)
return this.render(renderer)
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/frames/frame_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,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, false, false)
if (this.view.renderPromise) await this.view.renderPromise
this.changeHistory()

Expand Down
8 changes: 6 additions & 2 deletions src/core/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { Bardo } from "./bardo"
export class Renderer {
#activeElement = null

constructor(currentSnapshot, newSnapshot, renderElement, isPreview, willRender = true) {
static renderElement(currentElement, newElement) {
// Abstract method
}

constructor(currentSnapshot, newSnapshot, isPreview, willRender = true) {
this.currentSnapshot = currentSnapshot
this.newSnapshot = newSnapshot
this.isPreview = isPreview
this.willRender = willRender
this.renderElement = renderElement
this.renderElement = this.constructor.renderElement
this.promise = new Promise((resolve, reject) => (this.resolvingFunctions = { resolve, reject }))
}

Expand Down

0 comments on commit e94307f

Please sign in to comment.