Left out FXRouter from previous commit

This commit is contained in:
Rohan Sircar 2020-12-23 14:14:44 +05:30
parent 5b50f161d2
commit 2df921807d

View File

@ -1,5 +1,7 @@
package nova.monadic_sfx.ui.components.router
import scala.concurrent.duration._
import io.circe.Codec
import io.circe.Decoder
import io.circe.Encoder
@ -7,15 +9,15 @@ import io.circe.generic.JsonCodec
import io.circe.generic.semiauto._
import io.odin.Logger
import monix.bio.Task
import monix.eval.Coeval
import monix.reactive.Observable
import nova.monadic_sfx.util.IOUtils
import nova.monadic_sfx.util.MutHistory
import nova.monadic_sfx.util.controls.JFXSpinner
import nova.monadic_sfx.util.reactive.store.Middlewares
import nova.monadic_sfx.util.reactive.store.Reducer
import nova.monadic_sfx.util.reactive.store.Store
import scalafx.scene.Parent
import monix.reactive.Observable
import nova.monadic_sfx.util.controls.JFXSpinner
import scala.concurrent.duration._
import monix.eval.Coeval
object FXRouter {
@ -23,6 +25,9 @@ object FXRouter {
sealed abstract class Action[+T]
final case class Replace[T](page: T) extends Action[T]
final case class HistoryEvent[T](page: T) extends Action[T]
final case object Forward extends Action[Nothing]
final case object Backward extends Action[Nothing]
object Action {
implicit def codec[T: Encoder: Decoder]: Codec[Action[T]] = deriveCodec
@ -32,7 +37,10 @@ object FXRouter {
}
class FXRouter[P]()(implicit E: Encoder[P], D: Decoder[P]) {
class FXRouter[P](history: MutHistory[P])(implicit
E: Encoder[P],
D: Decoder[P]
) {
import FXRouter._
def store(initialPage: P, logger: Logger[Task]): Task[FXStore[P]] =
@ -58,7 +66,12 @@ class FXRouter[P]()(implicit E: Encoder[P], D: Decoder[P]) {
action match {
// case Init => (state, None)
case Replace(p) =>
history.push(p)
(state.copy(page = p), None)
case HistoryEvent(p) =>
(state.copy(page = p), None)
case Forward => (state, None)
case Backward => (state, None)
}
def render(