From 84cfcf0ebca8fad58de15f283927e2515381357d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Denuzi=C3=A8re?= Date: Thu, 23 May 2024 20:41:22 +0200 Subject: [PATCH] feat: StreamRenderingComponent for stream rendering SSR --- src/Bolero.Server/Components.fs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Bolero.Server/Components.fs b/src/Bolero.Server/Components.fs index b3f955a..c15d3f3 100644 --- a/src/Bolero.Server/Components.fs +++ b/src/Bolero.Server/Components.fs @@ -59,6 +59,30 @@ type BoleroScript() = override this.BuildRenderTree(builder) = builder.AddMarkupContent(0, BoleroHostConfig.Body(this.Config)) +#if NET8_0_OR_GREATER +[] +type StreamRenderingComponent<'model>() = + inherit Component<'model>() + + let mutable model = Unchecked.defaultof<'model> + + abstract InitialModel : 'model + + abstract LoadModel : unit -> Task<'model> + + abstract Render : 'model -> Node + + override this.OnInitializedAsync() = + model <- this.InitialModel + task { + let! newModel = this.LoadModel() + model <- newModel + } + + override this.Render() = + this.Render(model) +#endif + module Rendering = let private emptyContent = Task.FromResult { new IHtmlContent with member _.WriteTo(_, _) = () }