Skip to content
Snippets Groups Projects
Commit a85dbad5 authored by Clément Pit-Claudel's avatar Clément Pit-Claudel
Browse files

server: Remove Tick event encoder

parent e80cb764
Branches
Tags
1 merge request!25server: Refactor to use per-instance locking
...@@ -74,23 +74,15 @@ abstract class ClockDrivenStateMachine[Event, State, View] ...@@ -74,23 +74,15 @@ abstract class ClockDrivenStateMachine[Event, State, View]
*/ */
val clockDrivenWire: AppWire[Event, View] val clockDrivenWire: AppWire[Event, View]
override object wire extends AppWire[Either[Tick, Event], View]: override object wire extends ClockDrivenWire(clockDrivenWire)
override object eventFormat extends WireFormat[Either[Tick, Event]]:
override def decode(json: ujson.Value): Try[Either[Tick, Event]] =
Try:
val isClockEvent =
json.objOpt
.flatMap(_.get(ClockDrivenStateMachine.CLOCK_EVENT_HEADER))
.exists(_.bool)
if isClockEvent then Left(TickEventFormat.decode(json.obj.get("tick").get).get) private class ClockDrivenWire[Event, View](wire: AppWire[Event, View]) extends AppWire[Either[Tick, Event], View]:
else Right(clockDrivenWire.eventFormat.decode(json).get) override object eventFormat extends WireFormat[Either[Tick, Event]]:
override def decode(json: ujson.Value): Try[Either[Tick, Event]] = Try:
Right(wire.eventFormat.decode(json).get)
override def encode(t: Either[Tick, Event]): ujson.Value = override def encode(t: Either[Tick, Event]): ujson.Value =
throw IllegalStateException("This shouldn't be used. Please use the ScalApp's wire instead.") require(t.isRight, "Tick events should not be sent over the network.")
wire.eventFormat.encode(t.toOption.get)
override val viewFormat: WireFormat[View] = clockDrivenWire.viewFormat override val viewFormat: WireFormat[View] = wire.viewFormat
object ClockDrivenStateMachine:
val CLOCK_EVENT_HEADER = "X-Clock"
val CLOCK_EVENT_TICK_HEADER = "tick"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment