-
Notifications
You must be signed in to change notification settings - Fork 35
Observe the path configuration loading state #195
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
8f30cf4
Initial spike at providing a path configuration loadState to observe …
jayohms caff8fa
Update the PathConfigurationLoader so it doesn't hold onto a context
jayohms 0b57648
Observe the loadState to update the PathConfiguration data
jayohms f0d7d84
Observe the load state in init
jayohms f6b0d0f
Extract the serializable data into a PathConfigurationData class so j…
jayohms 6e6065b
Use an Unconfined dispatcher to collect the load state and fix tests
jayohms 0808825
Use the IO scope to load the path config from the disk/network
jayohms 9a2910a
Only load the bundled configuration if the cached configuration isn't…
jayohms 0cb0c00
Clean up tests
jayohms 65a55ce
Load the path configuration after enabling debug logging
jayohms 60a421b
Implement .equals() and .hashCode() for PathConfigurationData so its …
jayohms d320eab
Use a sealed class for Loading so you don't have to check each indivi…
jayohms b8750ee
Load the bundled or cached configuration synchronously so that the pr…
jayohms 6bf6c3e
Don't use a separate data instance to hold state
jayohms a3143f6
Clean up getting the current configuration
jayohms 851e7e4
Cancel the previous load() request if it's called again
jayohms 048ab48
Rename Idle -> NotLoaded
jayohms 81b37a8
Use a data class with the @ConsistentCopyVisibility annotation to avo…
jayohms ffb8306
Use if/else instead of when
jayohms d847641
Cancel the previous job before loading the bundled/cached config
jayohms 3b7a1f0
Use sealed interfaces to simplify state setup
jayohms 41a4aad
Upgrade OkHttp and implement the okhttp-coroutines dependency so fetc…
jayohms 7fb7974
Make PathConfiguration have an internal constructor since using it ou…
jayohms 3fcb5c5
Remove unneeded CoroutinesTestRule
jayohms 0ed305e
Use lowercase log event keys for consistency with other logging
jayohms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
47 changes: 47 additions & 0 deletions
47
core/src/main/kotlin/dev/hotwire/core/turbo/config/PathConfigurationData.kt
This file contains hidden or 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,47 @@ | ||
| package dev.hotwire.core.turbo.config | ||
|
|
||
| import com.google.gson.annotations.SerializedName | ||
| import java.net.URL | ||
|
|
||
| @ConsistentCopyVisibility | ||
| data class PathConfigurationData internal constructor( | ||
| @SerializedName("rules") | ||
| internal val rules: List<PathConfigurationRule> = emptyList(), | ||
|
|
||
| /** | ||
| * Gets the top-level settings specified in the app's path configuration. | ||
| * The settings are map of key/value `String` items. | ||
| */ | ||
| @SerializedName("settings") | ||
| val settings: PathConfigurationSettings = PathConfigurationSettings() | ||
| ) { | ||
| /** | ||
| * Retrieve the path properties based on the cascading rules in your | ||
| * path configuration. | ||
| * | ||
| * @param location The absolute url to match against the configuration's | ||
| * rules. Only the url's relative path will be used to find the matching | ||
| * regex rules. | ||
| * @return The map of key/value `String` properties | ||
| */ | ||
| fun properties(location: String): PathConfigurationProperties { | ||
| val properties = PathConfigurationProperties() | ||
| val path = path(location) | ||
|
|
||
| for (rule in rules + historicalLocationRules) { | ||
| if (rule.matches(path)) properties.putAll(rule.properties) | ||
| } | ||
|
|
||
| return properties | ||
| } | ||
|
|
||
| private fun path(location: String): String { | ||
| val url = URL(location) | ||
|
|
||
| return if (url.query == null) { | ||
| url.path | ||
| } else { | ||
| "${url.path}?${url.query}" | ||
| } | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
core/src/main/kotlin/dev/hotwire/core/turbo/config/PathConfigurationLoadState.kt
This file contains hidden or 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,37 @@ | ||
| package dev.hotwire.core.turbo.config | ||
|
|
||
| /** | ||
| * Represents the current state of the path configuration loading process. | ||
| * Observe [PathConfiguration.loadState] to receive updates as the configuration | ||
| * is loaded from each source. | ||
| */ | ||
| sealed interface PathConfigurationLoadState { | ||
| /** | ||
| * The initial state before any configuration has been loaded. | ||
| */ | ||
| data object NotLoaded : PathConfigurationLoadState | ||
|
|
||
| /** | ||
| * The configuration was successfully loaded from a source. Check the | ||
| * specific subclass to determine the source: [BundledAssetLoaded], | ||
| * [CachedRemoteLoaded], or [RemoteLoaded]. | ||
| */ | ||
| sealed interface Loaded : PathConfigurationLoadState { | ||
| val configuration: PathConfigurationData | ||
|
|
||
| /** | ||
| * The configuration was loaded from the locally bundled asset file. | ||
| */ | ||
| data class BundledAssetLoaded(override val configuration: PathConfigurationData) : Loaded | ||
|
|
||
| /** | ||
| * The configuration was loaded from a previously cached remote file. | ||
| */ | ||
| data class CachedRemoteLoaded(override val configuration: PathConfigurationData) : Loaded | ||
|
|
||
| /** | ||
| * The configuration was freshly loaded from the remote server. | ||
| */ | ||
| data class RemoteLoaded(override val configuration: PathConfigurationData) : Loaded | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.