-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract BrowserHistory interface for testing
- Loading branch information
Showing
12 changed files
with
256 additions
and
262 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
...tlin/com/arkivanov/decompose/router/stack/webhistory/DefaultWebHistoryControllerWindow.kt
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
...pose/src/jsMain/kotlin/com/arkivanov/decompose/router/webhistory/DefaultBrowserHistory.kt
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,24 @@ | ||
package com.arkivanov.decompose.router.webhistory | ||
|
||
import kotlinx.browser.window | ||
|
||
internal actual object DefaultBrowserHistory : BrowserHistory { | ||
|
||
actual override val state: String? get() = window.history.state?.unsafeCast<String>() | ||
|
||
actual override fun go(delta: Int) { | ||
window.history.go(delta = delta) | ||
} | ||
|
||
actual override fun pushState(data: String?, url: String?) { | ||
window.history.pushState(data = data, title = "", url = url) | ||
} | ||
|
||
actual override fun replaceState(data: String?, url: String?) { | ||
window.history.replaceState(data = data, title = "", url = url) | ||
} | ||
|
||
actual override fun setOnPopStateListener(listener: (state: String?) -> Unit) { | ||
window.onpopstate = { listener(it.state?.unsafeCast<String>()) } | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
...tlin/com/arkivanov/decompose/router/stack/webhistory/DefaultWebHistoryControllerWindow.kt
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
.../src/wasmJsMain/kotlin/com/arkivanov/decompose/router/webhistory/DefaultBrowserHistory.kt
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,24 @@ | ||
package com.arkivanov.decompose.router.webhistory | ||
|
||
import kotlinx.browser.window | ||
|
||
internal actual object DefaultBrowserHistory : BrowserHistory { | ||
|
||
actual override val state: String? get() = window.history.state?.toString() | ||
|
||
actual override fun go(delta: Int) { | ||
window.history.go(delta = delta) | ||
} | ||
|
||
actual override fun pushState(data: String?, url: String?) { | ||
window.history.pushState(data = data?.toJsString(), title = "", url = url) | ||
} | ||
|
||
actual override fun replaceState(data: String?, url: String?) { | ||
window.history.replaceState(data = data?.toJsString(), title = "", url = url) | ||
} | ||
|
||
actual override fun setOnPopStateListener(listener: (state: String?) -> Unit) { | ||
window.onpopstate = { listener(it.state?.toString()) } | ||
} | ||
} |
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
8 changes: 0 additions & 8 deletions
8
...tlin/com/arkivanov/decompose/router/stack/webhistory/DefaultWebHistoryControllerWindow.kt
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
decompose/src/webMain/kotlin/com/arkivanov/decompose/router/webhistory/BrowserHistory.kt
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,11 @@ | ||
package com.arkivanov.decompose.router.webhistory | ||
|
||
internal interface BrowserHistory { | ||
|
||
val state: String? | ||
|
||
fun go(delta: Int) | ||
fun pushState(data: String?, url: String?) | ||
fun replaceState(data: String?, url: String?) | ||
fun setOnPopStateListener(listener: (state: String?) -> Unit) | ||
} |
11 changes: 11 additions & 0 deletions
11
...ose/src/webMain/kotlin/com/arkivanov/decompose/router/webhistory/DefaultBrowserHistory.kt
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,11 @@ | ||
package com.arkivanov.decompose.router.webhistory | ||
|
||
internal expect object DefaultBrowserHistory : BrowserHistory { | ||
|
||
override val state: String? | ||
|
||
override fun go(delta: Int) | ||
override fun pushState(data: String?, url: String?) | ||
override fun replaceState(data: String?, url: String?) | ||
override fun setOnPopStateListener(listener: (state: String?) -> Unit) | ||
} |
Oops, something went wrong.