From d2c680a43073d7564eaf0fc168702d66fd0ac689 Mon Sep 17 00:00:00 2001 From: Hugh <htcolema@uwaterloo.ca> Date: Mon, 9 Dec 2024 22:30:25 +0100 Subject: [PATCH] skip render if current view remains unchanged Rebasing on top of !27. --- .../webapp/client/graphics/WebClientAppInstance.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/src/main/scala/cs214/webapp/client/graphics/WebClientAppInstance.scala b/js/src/main/scala/cs214/webapp/client/graphics/WebClientAppInstance.scala index 423ab42..a011096 100644 --- a/js/src/main/scala/cs214/webapp/client/graphics/WebClientAppInstance.scala +++ b/js/src/main/scala/cs214/webapp/client/graphics/WebClientAppInstance.scala @@ -13,6 +13,9 @@ abstract class WebClientAppInstance[Event, View]( sendMessage: ujson.Value => Unit, target: Target ) extends StateMachineClientAppInstance[Event, View](userId, sendMessage), DOMClientUI[View], PatchableUI: + /** The currently-rendered view, if one exists. */ + private var currentView: Option[View] = None + /** Renders a [[View]] received from the server. The method also takes a * [[UserId]] to get information on the context and an [[onEvent]] callback * which it uses to send server events when specific actions are triggered on @@ -27,7 +30,9 @@ abstract class WebClientAppInstance[Event, View]( protected def render(userId: UserId, view: View): Frag override def displayView(view: View): Unit = - patchUI(target, render(userId, view)) + if Some(view) != currentView then + currentView = Some(view) + patchUI(target, render(userId, view)) override def patchUI(target: dom.Element, fr: Frag): Unit = target.replaceChildren(fr.render) -- GitLab