-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move ready() implementation up to IO/ZIO level * Extending MultiPage give hash based routing * Make TyrianRoutedAppF methods private * Popstate based routing * Remove Navigation class * Introduce a location class * Add deprecation warning for TyrianApp * Add a random hash link to the sandbox * Paranoid save - works, contains TODOs * Added an external link to the sandbox, which errors. * Added broken Location tests, ready to fix! * WIP: LocationDetails * LocationDetails path matching * LocationDetails works * Location type working * Clean up * Improve sandbox example * Only pushstate on internal links * Formatting * Restore TyrianApp now includes routing requirement * Updating Routing * Fixed scaladocs * Added an `all` Router + more scaladocs * Nav forward and back + scaladocs
- Loading branch information
1 parent
af1edf0
commit cf8772d
Showing
15 changed files
with
1,034 additions
and
105 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
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,46 @@ | ||
package tyrian | ||
|
||
import cats.effect.kernel.Async | ||
import cats.effect.kernel.Resource | ||
import org.scalajs.dom.Element | ||
import org.scalajs.dom.PopStateEvent | ||
import org.scalajs.dom.document | ||
import org.scalajs.dom.window | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation._ | ||
|
||
sealed trait Location: | ||
def locationDetails: LocationDetails | ||
def isInternal: Boolean | ||
def isExternal: Boolean | ||
def href: String | ||
def url: String | ||
|
||
object Location: | ||
|
||
final case class Internal(locationDetails: LocationDetails) extends Location: | ||
export locationDetails.* | ||
val isInternal: Boolean = true | ||
val isExternal: Boolean = false | ||
|
||
final case class External(locationDetails: LocationDetails) extends Location: | ||
export locationDetails.* | ||
val isInternal: Boolean = false | ||
val isExternal: Boolean = true | ||
|
||
/** Construct a Location from a given url, decides internal / external based on comparison with `currentLocation` | ||
*/ | ||
def fromUrl(url: String, currentLocation: Location.Internal): Location = | ||
val ld = LocationDetails.fromUrl(url) | ||
|
||
if ld.protocol.isEmpty then Location.Internal(ld) | ||
else if ld.origin == currentLocation.origin then Location.Internal(ld) | ||
else Location.External(ld) | ||
|
||
/** Location instances created from JS Location's are assumed to be internal links. | ||
*/ | ||
def fromJsLocation(location: org.scalajs.dom.Location): Location.Internal = | ||
Location.Internal( | ||
LocationDetails.fromUrl(location.href) | ||
) |
Oops, something went wrong.