Skip to content

Commit

Permalink
Fix BrowserRouter for WasmJs target by simplifying expect/actual func… (
Browse files Browse the repository at this point in the history
#415)

Fix BrowserRouter for WasmJs target by simplifying expect/actual functions

(cherry picked from commit 9e3a4c7)

Co-authored-by: Robert Jaros <[email protected]>
  • Loading branch information
hfhbd and rjaros authored Oct 27, 2024
1 parent 8ba33a2 commit 973728b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package app.softwork.routingcompose
internal actual typealias Window = org.w3c.dom.Window

internal actual typealias History = org.w3c.dom.History
internal actual fun History.pushState(data: Any?, title: String, url: String?) {
this.pushState(data, title, url)
internal actual fun History.pushState(title: String, url: String?) {
this.pushState(null, title, url)
}

internal actual typealias Location = org.w3c.dom.Location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ internal class BrowserRouter : Router {
currentLocation.value = window.location.newPath().takeUnless { it == "/" } ?: initPath
window.onpopstate = {
currentLocation.value = window.location.newPath()
Unit
}
}
return currentLocation
Expand All @@ -51,7 +50,7 @@ internal class BrowserRouter : Router {
if (hide) {
currentLocation.value = to
} else {
window.history.pushState(null, "", to)
window.history.pushState("", to)
/*
The history API unfortunately provides no callback to listen to
[window.history.pushState], so we need to notify subscribers when pushing a new path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ internal class HashRouter : Router {
currentHash.value = window.location.hash.currentURL() ?: initPath
window.onhashchange = {
currentHash.value = window.location.hash.currentURL() ?: ""
Unit
}
}
return currentHash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal expect var Window.onpopstate: () -> Unit
internal expect var Window.onhashchange: () -> Unit

internal expect abstract class History
internal expect fun History.pushState(data: Any?, title: String, url: String?)
internal expect fun History.pushState(title: String, url: String?)

internal expect abstract class Location {
var pathname: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ internal actual typealias Window = org.w3c.dom.Window

internal actual typealias History = org.w3c.dom.History

internal actual fun History.pushState(data: Any?, title: String, url: String?) {
this.pushState(data, title, url)
internal actual fun History.pushState(title: String, url: String?) {
this.pushState(null, title, url)
}

internal actual typealias Location = org.w3c.dom.Location
Expand Down

0 comments on commit 973728b

Please sign in to comment.