Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor renderElement static methods to instance methods #1312

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/drive/error_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { activateScriptElement } from "../../util"
import { Renderer } from "../renderer"

export class ErrorRenderer extends Renderer {
static renderElement(currentElement, newElement) {
renderElement(currentElement, newElement) {
const { documentElement, body } = document

documentElement.replaceChild(newElement, body)
Expand Down
2 changes: 1 addition & 1 deletion src/core/drive/morphing_page_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { dispatch } from "../../util"
import { morphElements } from "../morphing"

export class MorphingPageRenderer extends PageRenderer {
static renderElement(currentElement, newElement) {
renderElement(currentElement, newElement) {
morphElements(currentElement, newElement, {
callbacks: {
beforeNodeMorphed: element => !canRefreshFrame(element)
Expand Down
2 changes: 1 addition & 1 deletion src/core/drive/page_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { activateScriptElement, waitForLoad } from "../../util"
import { Renderer } from "../renderer"

export class PageRenderer extends Renderer {
static renderElement(currentElement, newElement) {
renderElement(currentElement, newElement) {
if (document.body && newElement instanceof HTMLBodyElement) {
document.body.replaceWith(newElement)
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/core/frames/frame_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { activateScriptElement, nextRepaint } from "../../util"
import { Renderer } from "../renderer"

export class FrameRenderer extends Renderer {
static renderElement(currentElement, newElement) {
renderElement(currentElement, newElement) {
const destinationRange = document.createRange()
destinationRange.selectNodeContents(currentElement)
destinationRange.deleteContents()
Expand All @@ -15,8 +15,8 @@ export class FrameRenderer extends Renderer {
}
}

constructor(delegate, currentSnapshot, newSnapshot, renderElement, isPreview, willRender = true) {
super(currentSnapshot, newSnapshot, renderElement, isPreview, willRender)
constructor(delegate, currentSnapshot, newSnapshot, isPreview, willRender = true) {
super(currentSnapshot, newSnapshot, isPreview, willRender)
this.delegate = delegate
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/frames/morphing_frame_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { morphChildren } from "../morphing"
import { dispatch } from "../../util"

export class MorphingFrameRenderer extends FrameRenderer {
static renderElement(currentElement, newElement) {
renderElement(currentElement, newElement) {
dispatch("turbo:before-frame-morph", {
target: currentElement,
detail: { currentElement, newElement }
Expand Down
3 changes: 1 addition & 2 deletions src/core/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Bardo } from "./bardo"
export class Renderer {
#activeElement = null

static renderElement(currentElement, newElement) {
renderElement(currentElement, newElement) {
// Abstract method
}

Expand All @@ -12,7 +12,6 @@ export class Renderer {
this.newSnapshot = newSnapshot
this.isPreview = isPreview
this.willRender = willRender
this.renderElement = this.constructor.renderElement
this.promise = new Promise((resolve, reject) => (this.resolvingFunctions = { resolve, reject }))
}

Expand Down
4 changes: 2 additions & 2 deletions src/elements/stream_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { nextRepaint } from "../util"
* </turbo-stream>
*/
export class StreamElement extends HTMLElement {
static async renderElement(newElement) {
async renderElement(newElement) {
await newElement.performAction()
}

Expand Down Expand Up @@ -164,7 +164,7 @@ export class StreamElement extends HTMLElement {
return new CustomEvent("turbo:before-stream-render", {
bubbles: true,
cancelable: true,
detail: { newStream: this, render: StreamElement.renderElement }
detail: { newStream: this, render: this.renderElement }
})
}

Expand Down
Loading