Skip to content
Permalink
Browse files

Updated to use new @= for non-functionality assignments to avoid unex…

…pected side-effects
  • Loading branch information...
darkfrog26 committed Sep 27, 2019
1 parent 1684183 commit 3d5752a3e649cedfaac6abc0ef20cb4661cc787d
Showing with 549 additions and 528 deletions.
  1. +4 −4 app/js/src/main/scala/io/youi/app/ClientConnectivity.scala
  2. +1 −1 app/js/src/main/scala/io/youi/app/screen/ContentScreen.scala
  3. +1 −1 app/js/src/main/scala/io/youi/app/screen/Screen.scala
  4. +13 −13 app/js/src/main/scala/io/youi/app/screen/ScreenManager.scala
  5. +3 −3 app/js/src/main/scala/io/youi/app/screen/UIScreen.scala
  6. +1 −1 app/js/src/main/scala/io/youi/app/screen/URLActivation.scala
  7. +6 −6 app/jvm/src/main/scala/io/youi/app/ServerApplication.scala
  8. +1 −1 app/shared/src/main/scala/io/youi/app/ApplicationConnectivity.scala
  9. +2 −2 core/js/src/main/scala/io/youi/ajax/AjaxAction.scala
  10. +1 −1 core/js/src/main/scala/io/youi/ajax/AjaxManager.scala
  11. +4 −4 core/js/src/main/scala/io/youi/ajax/AjaxRequest.scala
  12. +5 −5 core/js/src/main/scala/io/youi/http/WebSocketUtil.scala
  13. +1 −1 core/shared/src/main/scala/io/youi/ErrorSupport.scala
  14. +2 −2 core/shared/src/main/scala/io/youi/ItemContainer.scala
  15. +7 −7 core/shared/src/main/scala/io/youi/http/Connection.scala
  16. +7 −7 dom/src/main/scala/io/youi/History.scala
  17. +1 −1 example/js/src/main/scala/io/youi/example/screen/CommunicationScreen.scala
  18. +1 −1 example/js/src/main/scala/io/youi/example/screen/LoginScreen.scala
  19. +11 −11 example/js/src/main/scala/io/youi/example/ui/AnimationExample.scala
  20. +4 −4 example/js/src/main/scala/io/youi/example/ui/BootstrapButtonExample.scala
  21. +2 −2 example/js/src/main/scala/io/youi/example/ui/BootstrapLoginExample.scala
  22. +2 −2 example/js/src/main/scala/io/youi/example/ui/CanvasExample.scala
  23. +4 −4 example/js/src/main/scala/io/youi/example/ui/DrawableExample.scala
  24. +4 −4 example/js/src/main/scala/io/youi/example/ui/FontAwesomeExample.scala
  25. +12 −12 example/js/src/main/scala/io/youi/example/ui/GridLayoutExample.scala
  26. +4 −4 example/js/src/main/scala/io/youi/example/ui/HelloWorld.scala
  27. +14 −14 example/js/src/main/scala/io/youi/example/ui/HitTestExample.scala
  28. +4 −4 example/js/src/main/scala/io/youi/example/ui/ImageChangeExample.scala
  29. +20 −20 example/js/src/main/scala/io/youi/example/ui/ImageExample.scala
  30. +4 −4 example/js/src/main/scala/io/youi/example/ui/MaterialIconsExample.scala
  31. +14 −14 example/js/src/main/scala/io/youi/example/ui/MeasuredExample.scala
  32. +23 −23 example/js/src/main/scala/io/youi/example/ui/ModalExample.scala
  33. +4 −4 example/js/src/main/scala/io/youi/example/ui/ParallaxExample.scala
  34. +33 −33 example/js/src/main/scala/io/youi/example/ui/RecycledScrollingExample.scala
  35. +4 −4 example/js/src/main/scala/io/youi/example/ui/SVGImageExample.scala
  36. +18 −18 example/js/src/main/scala/io/youi/example/ui/Scale9Example.scala
  37. +5 −5 example/js/src/main/scala/io/youi/example/ui/SelectExample.scala
  38. +4 −4 example/js/src/main/scala/io/youi/example/ui/SnapExample.scala
  39. +14 −14 example/js/src/main/scala/io/youi/example/ui/TextInputExample.scala
  40. +22 −22 example/js/src/main/scala/io/youi/example/ui/TextViewExample.scala
  41. +6 −6 example/js/src/main/scala/io/youi/example/ui/UIExamples.scala
  42. +13 −13 example/js/src/main/scala/io/youi/example/ui/VerticalLayoutExample.scala
  43. +1 −1 example/js/src/main/scala/io/youi/example/ui/VideoExample.scala
  44. +6 −6 example/js/src/main/scala/io/youi/example/ui/VirtualSizeExample.scala
  45. +21 −21 example/js/src/main/scala/io/youi/example/ui/component/Header.scala
  46. +1 −1 example/jvm/src/main/scala/io/youi/example/ServerExampleCommunication.scala
  47. +1 −1 example/jvm/src/main/scala/io/youi/example/WebSocketExample.scala
  48. +1 −1 project/build.properties
  49. +9 −8 project/plugins.sbt
  50. +3 −3 server/src/main/scala/io/youi/server/ServerConfig.scala
  51. +4 −4 serverUndertow/src/main/scala/io/youi/server/UndertowServerImplementation.scala
  52. +6 −6 serverUndertow/src/main/scala/io/youi/server/WebSocketClient.scala
  53. +1 −1 ui/js/src/main/scala/io/youi/AnimationFrame.scala
  54. +2 −2 ui/js/src/main/scala/io/youi/component/AbstractContainer.scala
  55. +1 −1 ui/js/src/main/scala/io/youi/component/Container.scala
  56. +1 −1 ui/js/src/main/scala/io/youi/component/HTMLSelect.scala
  57. +1 −1 ui/js/src/main/scala/io/youi/component/HTMLTextArea.scala
  58. +1 −1 ui/js/src/main/scala/io/youi/component/HTMLTextInput.scala
  59. +17 −17 ui/js/src/main/scala/io/youi/component/Scale9.scala
  60. +16 −16 ui/js/src/main/scala/io/youi/component/UIModal.scala
  61. +6 −6 ui/js/src/main/scala/io/youi/component/bootstrap/AccordionEntry.scala
  62. +1 −1 ui/js/src/main/scala/io/youi/component/editor/ContentEditor.scala
  63. +4 −0 ui/js/src/main/scala/io/youi/component/extras/ComponentSize.scala
  64. +8 −7 ui/js/src/main/scala/io/youi/component/extras/HTMLComponent.scala
  65. +1 −1 ui/js/src/main/scala/io/youi/component/extras/HTMLComponentPosition.scala
  66. +4 −4 ui/js/src/main/scala/io/youi/component/recycled/BetterRecycledScroller.scala
  67. +2 −2 ui/js/src/main/scala/io/youi/component/recycled/RecycledRenderer.scala
  68. +10 −10 ui/js/src/main/scala/io/youi/component/recycled/RecycledScroller.scala
  69. +18 −18 ui/js/src/main/scala/io/youi/component/selection/Selection.scala
  70. +2 −2 ui/js/src/main/scala/io/youi/datatransfer/DataTransferManager.scala
  71. +4 −4 ui/js/src/main/scala/io/youi/datatransfer/DragTarget.scala
  72. +1 −1 ui/js/src/main/scala/io/youi/datatransfer/FileSystemSupport.scala
  73. +2 −2 ui/js/src/main/scala/io/youi/drawable/Cacheable.scala
  74. +3 −3 ui/js/src/main/scala/io/youi/event/DragSupport.scala
  75. +7 −7 ui/js/src/main/scala/io/youi/event/Events.scala
  76. +6 −6 ui/js/src/main/scala/io/youi/event/Gestures.scala
  77. +14 −14 ui/js/src/main/scala/io/youi/event/HTMLEvents.scala
  78. +3 −3 ui/js/src/main/scala/io/youi/event/Mouse.scala
  79. +1 −1 ui/js/src/main/scala/io/youi/font/CachedFont.scala
  80. +1 −1 ui/js/src/main/scala/io/youi/font/MaterialIconView.scala
  81. +2 −2 ui/js/src/main/scala/io/youi/image/AnimatedImage.scala
  82. +1 −1 ui/js/src/main/scala/io/youi/image/SVGImage.scala
  83. +2 −2 ui/js/src/main/scala/io/youi/layout/FlowLayout.scala
  84. +6 −6 ui/js/src/main/scala/io/youi/layout/GridLayout.scala
  85. +4 −0 ui/js/src/main/scala/io/youi/theme/ComponentTheme.scala
  86. +8 −0 ui/js/src/main/scala/io/youi/theme/HTMLComponentTheme.scala
  87. +2 −2 ui/js/src/main/scala/io/youi/theme/StyleConnect.scala
  88. +2 −1 ui/js/src/main/scala/io/youi/theme/StyleProp.scala
  89. +2 −0 ui/js/src/main/scala/io/youi/theme/mixins/HTMLFontTheme.scala
  90. +6 −6 ui/js/src/main/scala/io/youi/ui.scala
  91. +1 −1 ui/js/src/main/scala/io/youi/util/LazyFuture.scala
  92. +13 −13 ui/js/src/main/scala/io/youi/video/Video.scala
  93. +1 −1 ui/js/src/main/scala/io/youi/virtual/VirtualSizeSupport.scala
  94. +1 −1 ui/js/src/main/scala/io/youi/youi.scala
  95. +1 −1 ui/shared/src/main/scala/io/youi/Updates.scala
@@ -18,7 +18,7 @@ class ClientConnectivity(connectivity: ApplicationConnectivity, application: Cli
val webSocket: Var[Option[WebSocket]] = Var(None)

connection.receive.text.attach {
case "PING" => connection.send.text := "PONG"
case "PING" => connection.send.text @= "PONG"
case _ => // Ignore
}

@@ -33,18 +33,18 @@ class ClientConnectivity(connectivity: ApplicationConnectivity, application: Cli
}

def connect(): Unit = {
connectivity.activeConnections := Set(connection)
connectivity.activeConnections @= Set(connection)

disconnect()
webSocket := Some(WebSocketUtil.connect(application.communicationURL, connection))
webSocket @= Some(WebSocketUtil.connect(application.communicationURL, connection))
}

def disconnect(): Unit = synchronized {
webSocket().foreach { ws =>
if (ws.readyState == WebSocket.OPEN) {
ws.close()
}
webSocket := None
webSocket @= None
}
}

@@ -74,7 +74,7 @@ trait ContentScreen extends Screen with PathActivation {

hideContent(span)
pageTag.appendChild(span)
contentOptionVar := Some(span)
contentOptionVar @= Some(span)
}

protected def showContent(content: html.Element): Unit = {
@@ -22,7 +22,7 @@ trait Screen {
protected def load(): Future[Unit] = Future.successful(())

protected def activate(): Future[Unit] = {
ui.title := title
ui.title @= title
registration.values.foreach(_.activate())
Future.successful(())
}
@@ -34,18 +34,18 @@ trait ScreenManager {
scribe.info("Window loading complete. Loading application...")
load().foreach { _ =>
scribe.info("Application loaded.")
loaded.asInstanceOf[Var[Boolean]] := true
loaded.asInstanceOf[Var[Boolean]] @= true
}
})
} else {
scribe.info("Application initialized. Loading application...")
load().foreach { _ =>
scribe.info("Application loaded.")
loaded.asInstanceOf[Var[Boolean]] := true
loaded.asInstanceOf[Var[Boolean]] @= true
}
}
}
case Failure(t) => ErrorSupport.error := new RuntimeException("Error during application initialization!", t)
case Failure(t) => ErrorSupport.error @= new RuntimeException("Error during application initialization!", t)
}

active.changes {
@@ -54,7 +54,7 @@ trait ScreenManager {

protected def init(): Future[Unit] = {
// Redirect Hookup errors to error support
Hookup.error.attach(t => ErrorSupport.error := t)
Hookup.error.attach(t => ErrorSupport.error @= t)

Future.successful(())
}
@@ -91,7 +91,7 @@ trait ScreenManager {
}

private[screen] def addScreen(screen: Screen): Unit = synchronized {
allScreens := (allScreens() ::: List(screen))
allScreens @= (allScreens() ::: List(screen))
}

def load(screen: Screen): Future[Unit] = managerFuture.map { _ =>
@@ -101,9 +101,9 @@ trait ScreenManager {

def applyState(applying: ScreenState, applied: ScreenState, call: => Future[Unit]): Unit = if (state.index < applying.index || state == ScreenState.Disposed) {
future = future.flatMap { _ =>
screen.currentState := applying
screen.currentState @= applying
call.map { _ =>
screen.currentState := applied
screen.currentState @= applied
}
}
}
@@ -123,9 +123,9 @@ trait ScreenManager {

def applyState(applying: ScreenState, applied: ScreenState, call: => Future[Unit], applyToStates: ScreenState*): Unit = if (applyToStates.contains(state)) {
future = future.flatMap { _ =>
screen.currentState := applying
screen.currentState @= applying
call.map { _ =>
screen.currentState := applied
screen.currentState @= applied
}
}
}
@@ -141,9 +141,9 @@ trait ScreenManager {

private def deactivate(screen: Screen): Future[Unit] = {
if (screen.state() == ScreenState.Activated) {
screen.currentState := ScreenState.Deactivating
screen.currentState @= ScreenState.Deactivating
val future = Screen.deactivate(screen).map { _ =>
screen.currentState := ScreenState.Deactivated
screen.currentState @= ScreenState.Deactivated
}

future.failed.foreach(YouIApplication().error)
@@ -156,9 +156,9 @@ trait ScreenManager {

def dispose(screen: Screen): Future[Unit] = {
if (screen.state() != ScreenState.Disposed) {
screen.currentState := ScreenState.Disposing
screen.currentState @= ScreenState.Disposing
val future = Screen.dispose(screen).map { _ =>
screen.currentState := ScreenState.Disposed
screen.currentState @= ScreenState.Disposed
}

future.failed.foreach(YouIApplication().error)
@@ -10,7 +10,7 @@ import scala.concurrent.Future
trait UIScreen extends Screen with PathActivation {
protected lazy val container: Container = {
val c = new Container
c.id := title
c.id @= title
c
}

@@ -24,7 +24,7 @@ trait UIScreen extends Screen with PathActivation {

def createUI(): Future[Unit]

override protected def activate(): Future[Unit] = super.activate().map(_ => container.display := Display.Block)
override protected def activate(): Future[Unit] = super.activate().map(_ => container.display @= Display.Block)

override protected def deactivate(): Future[Unit] = super.deactivate().map(_ => container.display := Display.None)
override protected def deactivate(): Future[Unit] = super.deactivate().map(_ => container.display @= Display.None)
}
@@ -14,7 +14,7 @@ trait URLActivation extends Screen {
if (state() == ScreenState.Activated) {
urlChanged(url)
} else {
ScreenManager().active := this
ScreenManager().active @= this
}
}

@@ -57,7 +57,7 @@ trait ServerApplication extends YouIApplication with Server {

override protected def init(): Future[Unit] = super.init().map { _ =>
// Redirect Hookup errors to error support
Hookup.error.attach(t => ErrorSupport.error := t)
Hookup.error.attach(t => ErrorSupport.error @= t)

connectivityEntries.attachAndFire { entries =>
ServerApplication.this.synchronized {
@@ -249,15 +249,15 @@ trait ServerApplication extends YouIApplication with Server {
override def handle(httpConnection: HttpConnection): Future[HttpConnection] = appComm.activeConnections.synchronized {
val connection = new Connection(client = false)
connection.store.update("httpConnection", httpConnection)
appComm.activeConnections := (appComm.activeConnections() + connection)
connected := connection
appComm.activeConnections @= (appComm.activeConnections() + connection)
connected @= connection
connection.connected.attach { b =>
if (!b) appComm.activeConnections.synchronized {
appComm.activeConnections := (appComm.activeConnections() - connection)
appComm.activeConnections @= (appComm.activeConnections() - connection)
HookupServer().foreach { hs =>
hs.remove(connection)
}
disconnected := connection
disconnected @= connection
}
}
connection.receive.text.attach {
@@ -270,7 +270,7 @@ trait ServerApplication extends YouIApplication with Server {

private def pingClients(): Unit = connectivityEntries().foreach { entry =>
entry.connections().foreach { connection =>
connection.send.text := "PING"
connection.send.text @= "PING"
}
}

@@ -25,6 +25,6 @@ class ApplicationConnectivity private[app](val application: YouIApplication,
// Make sure the application knows about it
application.synchronized {
val entries = application.connectivityEntries()
application.connectivityEntries.asInstanceOf[Var[Set[ApplicationConnectivity]]] := entries + this
application.connectivityEntries.asInstanceOf[Var[Set[ApplicationConnectivity]]] @= entries + this
}
}
@@ -17,9 +17,9 @@ class AjaxAction(request: AjaxRequest) {

private[ajax] def start(manager: AjaxManager): Unit = {
if (!cancelled()) {
_state := ActionState.Running
_state @= ActionState.Running
future.onComplete { result =>
_state := ActionState.Finished
_state @= ActionState.Finished
manager.remove(this)
}
request.send()
@@ -31,7 +31,7 @@ class AjaxManager(val maxConcurrent: Int) extends Logging {

def enqueue(action: AjaxAction): Future[XMLHttpRequest] = {
_queue = _queue.enqueue(action)
action._state := ActionState.Enqueued
action._state @= ActionState.Enqueued
checkQueue()
action.future
}
@@ -35,10 +35,10 @@ class AjaxRequest(url: URL,
}
}
req.upload.addEventListener("progress", (evt: ProgressEvent) => {
total.asInstanceOf[Var[Double]] := evt.total
loaded.asInstanceOf[Var[Double]] := evt.loaded
total.asInstanceOf[Var[Double]] @= evt.total
loaded.asInstanceOf[Var[Double]] @= evt.loaded
val p = math.round(math.floor((evt.loaded / evt.total) * 100)).toInt
percentage.asInstanceOf[Var[Int]] := p
percentage.asInstanceOf[Var[Int]] @= p
})
req.open(method.value, url.toString)
req.responseType = responseType
@@ -56,6 +56,6 @@ class AjaxRequest(url: URL,

def cancel(): Unit = if (percentage.get != 100) {
req.abort()
cancelled.asInstanceOf[Var[Boolean]] := true
cancelled.asInstanceOf[Var[Boolean]] @= true
}
}
@@ -39,27 +39,27 @@ object WebSocketUtil {
}
}
ws.onopen = (_: Event) => {
listener._connected := true
listener._connected @= true
}
ws.onerror = (_: Event) => {
listener.error := new RuntimeException("WebSocket error!")
listener.error @= new RuntimeException("WebSocket error!")
listener.close()
}
ws.onclose = (_: CloseEvent) => {
listener.close()
}
ws.onmessage = (evt: MessageEvent) => {
evt.data match {
case s: String => listener.receive.text := s
case s: String => listener.receive.text @= s
case blob: Blob => {
val fileReader = new FileReader
fileReader.onload = (_: Event) => {
val arrayBuffer = fileReader.result.asInstanceOf[ArrayBuffer]
listener.receive.binary := TypedArrayBuffer.wrap(arrayBuffer)
listener.receive.binary @= TypedArrayBuffer.wrap(arrayBuffer)
}
fileReader.readAsArrayBuffer(blob)
}
case ab: ArrayBuffer => listener.receive.binary := TypedArrayBuffer.wrap(ab)
case ab: ArrayBuffer => listener.receive.binary @= TypedArrayBuffer.wrap(ab)
}
}
ws
@@ -7,7 +7,7 @@ import reactify.Channel
import reactify.reaction.Reaction

trait ErrorSupport {
def error(t: Throwable): Unit = ErrorSupport.error := t
def error(t: Throwable): Unit = ErrorSupport.error @= t

def errorSupport[R](f: => R): R = try {
f
@@ -9,10 +9,10 @@ class ItemContainer[T](implicit ord: Ordering[T]) extends Iterable[T] {
val items: Val[List[T]] = list

def +=(item: T): Unit = synchronized {
list := (item :: list()).sorted
list @= (item :: list()).sorted
}
def -=(item: T): Unit = synchronized {
list := list().filterNot(_ == item)
list @= list().filterNot(_ == item)
}
def apply(): List[T] = items()

@@ -42,10 +42,10 @@ class Connection(client: Boolean) {
if (Connection.debug) scribe.info(s"Receive: $s")
}
send.close.on {
_connected := false
_connected @= false
}
receive.close.on {
_connected := false
_connected @= false
}

connected.attach { b =>
@@ -55,8 +55,8 @@ class Connection(client: Boolean) {
if (b) {
hookup()
backlog.foreach {
case s: String => send.text := s
case b: ByteBuffer => send.binary := b
case s: String => send.text @= s
case b: ByteBuffer => send.binary @= b
}
backlog.clear()
} else {
@@ -76,15 +76,15 @@ class Connection(client: Boolean) {
}
// Send output from Hookups
val reaction = hookups.io.output.attach { json =>
send.text := s"[HKP]${json.spaces2}"
send.text @= s"[HKP]${json.spaces2}"
}
store("applicationConnectivity") = reaction
// Receive input from connection
receive.text.attach { s =>
if (s.startsWith("[HKP]")) {
parse(s.substring(5)) match {
case Left(pf) => throw pf
case Right(json) => hookups.io.input := json
case Right(json) => hookups.io.input @= json
}
}
}
@@ -103,7 +103,7 @@ class Connection(client: Boolean) {

def close(): Unit = if (connected()) {
send.close.set(())
_connected := false
_connected @= false
}
}

0 comments on commit 3d5752a

Please sign in to comment.
You can’t perform that action at this time.