Skip to content

Commit

Permalink
chore: refactored mvc names
Browse files Browse the repository at this point in the history
  • Loading branch information
alemazzo committed Oct 15, 2023
1 parent 11e993b commit a52f1ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
24 changes: 13 additions & 11 deletions src/main/scala/scatan/lib/mvc/ScalaJSView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ import org.scalajs.dom
* The type of the state of the view.
*/
trait ScalaJSView[State <: Model.State](
val container: String, // The id of the container element
val initialState: State // The initial state of the view
val container: String // The id of the container element
) extends View[State]:

private val _reactiveState = Var[State](initialState)
override def updateState(state: State): Unit =
_reactiveState.writer.onNext(state)

/** A signal that emits the current state of the application.
*/
def reactiveState: Signal[State] = _reactiveState.signal
def reactiveState: Signal[State]

/** The element that is rendered by this view.
*/
Expand Down Expand Up @@ -54,7 +49,14 @@ abstract class BaseScalaJSView[State <: Model.State, C <: Controller[State]](
container: String,
requirements: View.Requirements[C]
) extends BaseView[State, C](requirements)
with ScalaJSView[State](
container,
requirements.controller.state
)
with ScalaJSView[State](container):

private val _reactiveState = Var[State](controller.state)

override def updateState(state: State): Unit =
super.updateState(state)
_reactiveState.writer.onNext(state)

/** A signal that emits the current state of the application.
*/
def reactiveState: Signal[State] = _reactiveState.signal
14 changes: 13 additions & 1 deletion src/main/scala/scatan/lib/mvc/View.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ package scatan.lib.mvc
*/
trait View[State <: Model.State]:

/** The state of the application.
*/
def state: State

/** Displays the view.
*/
def show(): Unit
Expand Down Expand Up @@ -57,4 +61,12 @@ trait NavigatorView extends View[?]:
abstract class BaseView[State <: Model.State, C <: Controller[State]](requirements: View.Requirements[C])
extends View[State]
with NavigatorView
with View.Dependencies(requirements)
with View.Dependencies(requirements):

override def state: State = _state

private var _state: State = controller.state
override private[mvc] def updateState(state: State): Unit =
_state = state


0 comments on commit a52f1ca

Please sign in to comment.