-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from codergeek121/morph-and-turbo-reload
Allow Turbo to reload the page instead of morphing
- Loading branch information
Showing
19 changed files
with
154 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
.../hotwire/spark/reloaders/html_reloader.js → ...re/spark/reloaders/morph_html_reloader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/javascript/hotwire/spark/reloaders/replace_html_reloader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { log } from "../logger.js" | ||
|
||
export class ReplaceHtmlReloader { | ||
static async reload() { | ||
return new ReplaceHtmlReloader().reload() | ||
} | ||
|
||
async reload() { | ||
await this.#reloadWithTurbo() | ||
} | ||
|
||
#reloadWithTurbo() { | ||
log("Reload html with Turbo...") | ||
|
||
this.#maintainScrollPosition() | ||
|
||
return new Promise(resolve => { | ||
document.addEventListener("turbo:load", () => resolve(document), { once: true }) | ||
window.Turbo.visit(window.location) | ||
}) | ||
} | ||
|
||
#maintainScrollPosition() { | ||
document.addEventListener("turbo:render", () => { | ||
Turbo.navigator.currentVisit.scrolled = true | ||
}, { once: true }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails | ||
import "@hotwired/turbo-rails" | ||
import "controllers" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "application_system_test_case" | ||
|
||
class MorphReloadTest < ApplicationSystemTestCase | ||
setup do | ||
Hotwire::Spark.html_reload_method = "morph" | ||
end | ||
|
||
test "reload HTML changes" do | ||
visit root_path | ||
assert_no_text "This was morphed" | ||
|
||
edit_file "app/views/home/show.html.erb", replace: "_REPLACE_", with: "This was morphed!" | ||
|
||
assert_text "This was morphed" | ||
assert_no_css "[data-turbo-navigated]" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "application_system_test_case" | ||
|
||
class ReplaceReloadTest < ApplicationSystemTestCase | ||
setup do | ||
Hotwire::Spark.html_reload_method = "replace" | ||
end | ||
|
||
test "reload HTML changes" do | ||
visit root_path | ||
assert_no_text "This is pretty amazing" | ||
|
||
edit_file "app/views/home/show.html.erb", replace: "cool", with: "amazing" | ||
|
||
assert_text "This is pretty amazing" | ||
assert_css "[data-turbo-navigated]" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters