Permalink
Browse files

Updated PathActivation to use a Path instead of String

  • Loading branch information...
darkfrog26 committed Nov 5, 2018
1 parent d285a98 commit b42d4f6b09972b866bd7f9a6184fa8d68b1021a8
Showing with 63 additions and 41 deletions.
  1. +6 −1 app/js/src/main/scala/io/youi/app/screen/ContentScreen.scala
  2. +4 −4 app/js/src/main/scala/io/youi/app/screen/PathActivation.scala
  3. +4 −1 core/shared/src/main/scala/io/youi/http/package.scala
  4. +2 −1 example/js/src/main/scala/io/youi/example/screen/CommunicationScreen.scala
  5. +3 −2 example/js/src/main/scala/io/youi/example/screen/ExampleBootstrapScreen.scala
  6. +2 −1 example/js/src/main/scala/io/youi/example/screen/LoginScreen.scala
  7. +3 −2 example/js/src/main/scala/io/youi/example/ui/AnimationExample.scala
  8. +2 −1 example/js/src/main/scala/io/youi/example/ui/BootstrapButtonExample.scala
  9. +2 −1 example/js/src/main/scala/io/youi/example/ui/BootstrapLoginExample.scala
  10. +2 −1 example/js/src/main/scala/io/youi/example/ui/CanvasExample.scala
  11. +2 −1 example/js/src/main/scala/io/youi/example/ui/DrawableExample.scala
  12. +2 −1 example/js/src/main/scala/io/youi/example/ui/GridLayoutExample.scala
  13. +2 −1 example/js/src/main/scala/io/youi/example/ui/HelloWorld.scala
  14. +2 −1 example/js/src/main/scala/io/youi/example/ui/HitTestExample.scala
  15. +2 −1 example/js/src/main/scala/io/youi/example/ui/ImageChangeExample.scala
  16. +2 −3 example/js/src/main/scala/io/youi/example/ui/ImageExample.scala
  17. +2 −1 example/js/src/main/scala/io/youi/example/ui/ParallaxExample.scala
  18. +2 −4 example/js/src/main/scala/io/youi/example/ui/SVGImageExample.scala
  19. +2 −1 example/js/src/main/scala/io/youi/example/ui/Scale9Example.scala
  20. +2 −2 example/js/src/main/scala/io/youi/example/ui/SnapExample.scala
  21. +4 −5 example/js/src/main/scala/io/youi/example/ui/TextViewExample.scala
  22. +2 −1 example/js/src/main/scala/io/youi/example/ui/UIExamples.scala
  23. +3 −2 example/js/src/main/scala/io/youi/example/ui/VerticalLayoutExample.scala
  24. +2 −1 example/js/src/main/scala/io/youi/example/ui/VideoExample.scala
  25. +2 −1 example/js/src/main/scala/io/youi/example/ui/VirtualSizeExample.scala
@@ -3,6 +3,7 @@ package io.youi.app.screen
import reactify.{Val, Var}
import io.youi.{History, dom}
import io.youi.dom._
import io.youi.net.Parameters
import io.youi.stream.StreamURL
import org.scalajs.dom._
@@ -23,7 +24,11 @@ trait ContentScreen extends Screen with PathActivation {
}
if (contentOption.isEmpty) { // Content hasn't been loaded yet
val url = History.url().replacePathAndParams(path).withParam("part", "true").withParam("selector", "screen")
val url = History
.url()
.copy(path = path, parameters = Parameters.empty)
.withParam("part", "true")
.withParam("selector", "screen")
StreamURL.stream(url).map { htmlString =>
val screen = dom.fromString[html.Element](htmlString).headOption.getOrElse(throw new RuntimeException(s"No content found in: [$htmlString] for URL: $url"))
loadScreen(screen)
@@ -1,18 +1,18 @@
package io.youi.app.screen
import io.youi.{HistoryStateChange, StateType, http}
import io.youi.net.{URL, URLMatcher}
import io.youi.net.{Parameters, Path, URL, URLMatcher}
trait PathActivation extends URLActivation {
def path: String
def path: Path
def stateType: StateType = StateType.Push
def clearParams: Boolean = false
override lazy val matcher: URLMatcher = http.path.exact(path)
override def updateURL(current: URL): Option[HistoryStateChange] = if (current.path.decoded != path) {
override def updateURL(current: URL): Option[HistoryStateChange] = if (current.path != path) {
val url = if (clearParams) {
current.replacePathAndParams(path)
current.copy(path = path, parameters = Parameters.empty)
} else {
current.withPath(path)
}
@@ -2,7 +2,7 @@ package io.youi
import java.io.File
import io.youi.net.{URL, URLMatcher}
import io.youi.net.{Path, URL, URLMatcher}
import scala.language.implicitConversions
@@ -39,6 +39,9 @@ package object http {
def exact(path: String): URLMatcher = new URLMatcher {
override def matches(url: URL): Boolean = url.path.decoded == path
}
def exact(path: Path): URLMatcher = new URLMatcher {
override def matches(url: URL): Boolean = url.path == path
}
def matches(regex: String): URLMatcher = new URLMatcher {
override def matches(url: URL): Boolean = url.path.decoded.matches(regex)
}
@@ -2,6 +2,7 @@ package io.youi.example.screen
import io.youi.dom._
import io.youi.example.ClientExampleApplication._
import io.youi.net._
import org.scalajs.dom.{Event, html, window}
import scala.concurrent.Future
@@ -21,7 +22,7 @@ object CommunicationScreen extends ExampleScreen {
def broadcastInput: html.Input = content.byId[html.Input]("communicationBroadcast")
def broadcastButton: html.Button = content.byId[html.Button]("communicationBroadcastButton")
override def path: String = "/communication.html"
override def path: Path = path"/communication.html"
override protected def load(): Future[Unit] = super.load().map { _ =>
configure()
@@ -2,14 +2,15 @@ package io.youi.example.screen
import io.youi.app.screen.PathActivation
import io.youi.dom
import org.scalajs.dom.{Event, document, html}
import io.youi.net._
import org.scalajs.dom.{document, html}
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.language.implicitConversions
object ExampleBootstrapScreen extends PathActivation {
override def path: String = "/bootstrap.html"
override def path: Path = path"/bootstrap.html"
implicit def bc2E[E <: html.Element, T <: BootstrapComponent[E, T]](bc: BootstrapComponent[E, T]): E = bc.element
@@ -2,14 +2,15 @@ package io.youi.example.screen
import io.youi.dom
import io.youi.example.ClientExampleApplication
import io.youi.net._
import org.scalajs.dom._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
object LoginScreen extends ExampleScreen {
override def path: String = "/login.html"
override def path: Path = path"/login.html"
def form: html.Form = dom.byId[html.Form]("loginScreen")
def message: html.Div = dom.byId[html.Div]("message")
@@ -1,11 +1,12 @@
package io.youi.example.ui
import io.youi._
import io.youi.component.{ImageView, HTMLTextView}
import io.youi.component.{HTMLTextView, ImageView}
import io.youi.easing.Easing
import io.youi.example.screen.UIExampleScreen
import io.youi.font.GoogleFont
import io.youi.image.Image
import io.youi.net._
import io.youi.style.Position
import io.youi.task._
@@ -15,7 +16,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
class AnimationExample extends UIExampleScreen {
override def title: String = "Animation Example"
override def path: String = "/examples/animation.html"
override def path: Path = path"/examples/animation.html"
override def createUI(): Future[Unit] = Image("/images/icon.png").map { img =>
GoogleFont.`Open Sans`.`regular`.load().map { fnt =>
@@ -4,6 +4,7 @@ import io.youi._
import io.youi.component.bootstrap.{Button, ButtonType}
import io.youi.example.screen.UIExampleScreen
import io.youi.font.GoogleFont
import io.youi.net._
import io.youi.theme.bootstrap.ButtonTheme
import reactify._
@@ -12,7 +13,7 @@ import scala.concurrent.Future
class BootstrapButtonExample extends UIExampleScreen {
override def title: String = "Bootstrap Button"
override def path: String = "/examples/bootstrap/button.html"
override def path: Path = path"/examples/bootstrap/button.html"
override def createUI(): Future[Unit] = GoogleFont.`Lobster`.load().map { fnt =>
val button = new Button {
@@ -4,13 +4,14 @@ import io.youi.{Color, Template, dom}
import io.youi.component.bootstrap.Button
import io.youi.component.extras.HTMLComponent
import io.youi.example.screen.UIExampleScreen
import io.youi.net._
import org.scalajs.dom._
import scala.concurrent.Future
class BootstrapLoginExample extends UIExampleScreen {
override def title: String = "Bootstrap Login"
override def path: String = "/examples/bootstrap/login.html"
override def path: Path = path"/examples/bootstrap/login.html"
private lazy val form: html.Form = Template.byId[html.Form]("../login-example.html", "login-form", "youi")
@@ -4,12 +4,13 @@ import io.youi.Color
import io.youi.component.CanvasComponent
import io.youi.drawable.Context
import io.youi.example.screen.UIExampleScreen
import io.youi.net._
import scala.concurrent.Future
class CanvasExample extends UIExampleScreen {
override def title: String = "Canvas Example"
override def path: String = "/examples/canvas.html"
override def path: Path = path"/examples/canvas.html"
override def createUI(): Future[Unit] = Future.successful {
val canvas = new CanvasComponent {
@@ -6,14 +6,15 @@ import io.youi.drawable.{Group, TextDrawable, Transformation}
import io.youi.example.screen.UIExampleScreen
import io.youi.font.{CanvasFont, CanvasText, GoogleFont}
import io.youi.image.Image
import io.youi.net._
import io.youi.paint.{Border, Stroke}
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
class DrawableExample extends UIExampleScreen {
override def title: String = "Drawable Example"
override def path: String = "/examples/drawable.html"
override def path: Path = path"/examples/drawable.html"
override def createUI(): Future[Unit] = for {
image <- Image("/images/cuteness.jpg")
@@ -4,14 +4,15 @@ import io.youi._
import io.youi.component.Container
import io.youi.example.screen.UIExampleScreen
import io.youi.layout.GridLayout
import io.youi.net._
import io.youi.paint.Paint
import reactify._
import scala.concurrent.Future
class GridLayoutExample extends UIExampleScreen {
override def title: String = "Grid Layout"
override def path: String = "/examples/grid.html"
override def path: Path = path"/examples/grid.html"
override def createUI(): Future[Unit] = {
val grid = new Container {
@@ -4,14 +4,15 @@ import io.youi._
import io.youi.component.HTMLTextView
import io.youi.example.screen.UIExampleScreen
import io.youi.font.GoogleFont
import io.youi.net._
import reactify._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
class HelloWorld extends UIExampleScreen {
override def title: String = "Hello World"
override def path: String = "/examples/hello.html"
override def path: Path = path"/examples/hello.html"
override def createUI(): Future[Unit] = GoogleFont.`Lobster`.load().map { fnt =>
val textView = new HTMLTextView {
@@ -3,12 +3,13 @@ package io.youi.example.ui
import io.youi._
import io.youi.component.Container
import io.youi.example.screen.UIExampleScreen
import io.youi.net._
import scala.concurrent.Future
class HitTestExample extends UIExampleScreen {
override def title: String = "Hit Test"
override def path: String = "/examples/hit.html"
override def path: Path = path"/examples/hit.html"
override def createUI(): Future[Unit] = Future.successful {
container.children += Container(
@@ -3,13 +3,14 @@ package io.youi.example.ui
import io.youi.component.ImageView
import io.youi.example.screen.UIExampleScreen
import io.youi.image.Image
import io.youi.net._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
class ImageChangeExample extends UIExampleScreen {
override def title: String = "Image Change"
override def path: String = "/examples/image-change.html"
override def path: Path = path"/examples/image-change.html"
lazy val imageView: ImageView = new ImageView
@@ -1,20 +1,19 @@
package io.youi.example.ui
import io.youi.app.screen.{PathActivation, Screen, UIScreen}
import io.youi.component._
import io.youi.example.screen.UIExampleScreen
import io.youi.image.Image
import io.youi.net._
import io.youi.style.Position
import io.youi.task._
import io.youi.ui
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
class ImageExample extends UIExampleScreen {
override def title: String = "Image Example"
override def path: String = "/examples/image.html"
override def path: Path = path"/examples/image.html"
override def createUI(): Future[Unit] = Image("/images/icon.png").map { img =>
container.children += Container(
@@ -4,6 +4,7 @@ import io.youi._
import io.youi.component.HTMLTextView
import io.youi.example.screen.UIExampleScreen
import io.youi.font.GoogleFont
import io.youi.net._
import io.youi.style.{Overflow, Position}
import reactify._
@@ -12,7 +13,7 @@ import scala.concurrent.Future
class ParallaxExample extends UIExampleScreen {
override def title: String = "Parallax Example"
override def path: String = "/examples/parallax.html"
override def path: Path = path"/examples/parallax.html"
override def createUI(): Future[Unit] = GoogleFont.`Lobster`.load().map { fnt =>
ui.overflow.y := Overflow.Auto
@@ -1,20 +1,18 @@
package io.youi.example.ui
import io.youi._
import io.youi.app.screen.UIScreen
import io.youi.component.ImageView
import io.youi.component.extras.CanvasImageViewImplementation
import io.youi.dom._
import io.youi.example.screen.UIExampleScreen
import io.youi.image.{Image, SVGImage}
import io.youi.net._
import org.scalajs.dom.raw.SVGCircleElement
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
class SVGImageExample extends UIExampleScreen {
override def title: String = "SVG Image"
override def path: String = "/examples/svg-image.html"
override def path: Path = path"/examples/svg-image.html"
private val svgString =
"""
@@ -3,14 +3,15 @@ package io.youi.example.ui
import io.youi.component.Scale9
import io.youi.example.screen.UIExampleScreen
import io.youi.image.Image
import io.youi.net._
import reactify._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
class Scale9Example extends UIExampleScreen {
override def title: String = "Scale 9"
override def path: String = "/examples/scale9.html"
override def path: Path = path"/examples/scale9.html"
override def createUI(): Future[Unit] = Image("/images/scale9.png").map { image =>
container.children += new Scale9(image) {
@@ -1,18 +1,18 @@
package io.youi.example.ui
import io.youi._
import io.youi.app.screen.UIScreen
import io.youi.component.Container
import io.youi.example.screen.UIExampleScreen
import io.youi.layout.snap.Snap
import io.youi.net._
import io.youi.paint.Paint
import reactify._
import scala.concurrent.Future
class SnapExample extends UIExampleScreen {
override def title: String = "Snap"
override def path: String = "/examples/snap.html"
override def path: Path = path"/examples/snap.html"
override def createUI(): Future[Unit] = {
val box = new Box {
@@ -1,19 +1,18 @@
package io.youi.example.ui
import io.youi.app.screen.UIScreen
import io.youi.component.{Container, HTMLTextView}
import io.youi.example.screen.UIExampleScreen
import io.youi.font.{GoogleFont, OpenTypeFont}
import io.youi.paint.{Border, Paint, Stroke}
import io.youi.{Color, History, ui}
import io.youi.font.GoogleFont
import io.youi.net._
import io.youi.Color
import reactify._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
class TextViewExample extends UIExampleScreen {
override def title: String = "TextView Example"
override def path: String = "/examples/text.html"
override def path: Path = path"/examples/text.html"
override def createUI(): Future[Unit] = {
for {
Oops, something went wrong.

0 comments on commit b42d4f6

Please sign in to comment.