Skip to content

Commit

Permalink
Refactor to extract method & revert to class
Browse files Browse the repository at this point in the history
  • Loading branch information
krschacht committed Feb 29, 2024
1 parent a5a87e4 commit 87c9553
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/core/drive/morph_page_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class MorphPageRenderer extends PageRenderer {

#reloadRemoteFrames() {
this.#remoteFrames().forEach((frame) => {
if (this.#isFrameReloadedWithMorph(frame)) {
if (frame.shouldReloadWithMorph) {
frame.reload()
}
})
Expand All @@ -38,8 +38,4 @@ export class MorphPageRenderer extends PageRenderer {
return !frame.closest('[data-turbo-permanent]')
})
}

#isFrameReloadedWithMorph(element) {
return element.src && element.refresh === "morph"
}
}
2 changes: 1 addition & 1 deletion src/core/frames/frame_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export class FrameController {
const snapshot = new Snapshot(newFrameElement)
let renderer

if (this.element.src && this.element.refresh === "morph") {
if (this.element.shouldReloadWithMorph) {
renderer = new MorphFrameRenderer(this, this.view.snapshot, snapshot, MorphFrameRenderer.renderElement, false, false)
} else {
renderer = new FrameRenderer(this, this.view.snapshot, snapshot, FrameRenderer.renderElement, false, false)
Expand Down
2 changes: 1 addition & 1 deletion src/core/frames/morph_frame_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export class MorphFrameRenderer extends FrameRenderer {
detail: { currentElement, newElement }
})

MorphElements.morph(currentElement, newElement, 'innerHTML')
MorphElements.morph(currentElement, newElement, "innerHTML")
}
}
3 changes: 2 additions & 1 deletion src/core/morph_elements.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Idiomorph } from "idiomorph/dist/idiomorph.esm.js"
import { dispatch } from "../util"
import { FrameElement } from "../elements/frame_element"

export class MorphElements {
static morph(currentElement, newElement, morphStyle = "outerHTML") {
Expand All @@ -18,7 +19,7 @@ export class MorphElements {
}

static isFrameReloadedWithMorph(element) {
return element.src && element.refresh === "morph"
return (element instanceof FrameElement) && element.shouldReloadWithMorph
}

static shouldAddElement = (node) => {
Expand Down
4 changes: 4 additions & 0 deletions src/elements/frame_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export class FrameElement extends HTMLElement {
}
}

get shouldReloadWithMorph() {
return this.src && this.refresh === "morph"
}

/**
* Determines if the element is loading
*/
Expand Down

0 comments on commit 87c9553

Please sign in to comment.