diff --git a/tyrian/js/src/main/scala/tyrian/runtime/Renderer.scala b/tyrian/js/src/main/scala/tyrian/runtime/Renderer.scala index 82562267..f363423b 100644 --- a/tyrian/js/src/main/scala/tyrian/runtime/Renderer.scala +++ b/tyrian/js/src/main/scala/tyrian/runtime/Renderer.scala @@ -2,12 +2,13 @@ package tyrian.runtime import cats.effect.kernel.Async import cats.effect.kernel.Ref -import cats.effect.kernel.Resource +import cats.effect.syntax.all.* import snabbdom.VNode import tyrian.Html import tyrian.Location final case class Renderer(vnode: VNode, state: RendererState, lastTriggered: Long): + def redraw[Model, Msg]( time: Long, model: Model, @@ -16,18 +17,14 @@ final case class Renderer(vnode: VNode, state: RendererState, lastTriggered: Lon router: Location => Msg ): Renderer = this.copy( - vnode = Rendering.render(vnode, model, view, onMsg, router), + vnode = Rendering.render(vnode, model, view, onMsg, router), // TODO: Replace state = RendererState.Running, lastTriggered = time ) object Renderer: - def init[F[_]](vnode: VNode)(using F: Async[F]): Resource[F, F[Ref[F, Renderer]]] = - Resource.eval( - F.delay( - F.ref( - Renderer(vnode, RendererState.Idle, 0) - ) - ) + def init[F[_]](vnode: VNode)(using F: Async[F]): F[Ref[F, Renderer]] = + F.ref( + Renderer(vnode, RendererState.Idle, 0) ) diff --git a/tyrian/js/src/main/scala/tyrian/runtime/TyrianRuntime.scala b/tyrian/js/src/main/scala/tyrian/runtime/TyrianRuntime.scala index ba7de7ed..4b1e2503 100644 --- a/tyrian/js/src/main/scala/tyrian/runtime/TyrianRuntime.scala +++ b/tyrian/js/src/main/scala/tyrian/runtime/TyrianRuntime.scala @@ -27,17 +27,15 @@ object TyrianRuntime: view: Model => Html[Msg], subscriptions: Model => Sub[F, Msg] )(using F: Async[F]): F[Nothing] = - Dispatcher - .sequential[F] - .both(Renderer.init(toVNode(node))) - .use { case (d, r) => - val loop = mainLoop(d, router, initCmd, update, view, subscriptions) - val model = F.ref(initModel) - val currentSubs = AtomicCell[F].of(List.empty[(String, F[Unit])]) - val msgQueue = Queue.unbounded[F, Msg] + Dispatcher.sequential[F].use { dispatcher => + val loop = mainLoop(dispatcher, router, initCmd, update, view, subscriptions) + val model = F.ref(initModel) + val currentSubs = AtomicCell[F].of(List.empty[(String, F[Unit])]) + val msgQueue = Queue.unbounded[F, Msg] + val renderer = Renderer.init(toVNode(node)) - (model, currentSubs, msgQueue, r).flatMapN(loop) - } + (model, currentSubs, msgQueue, renderer).flatMapN(loop) + } def mainLoop[F[_], Model, Msg]( dispatcher: Dispatcher[F],