Skip to content

Commit

Permalink
feat: StreamRenderingComponent for stream rendering SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed May 23, 2024
1 parent a2e27b4 commit 84cfcf0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Bolero.Server/Components.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ type BoleroScript() =
override this.BuildRenderTree(builder) =
builder.AddMarkupContent(0, BoleroHostConfig.Body(this.Config))

#if NET8_0_OR_GREATER
[<AbstractClass; StreamRendering true>]
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(_, _) = () }
Expand Down

0 comments on commit 84cfcf0

Please sign in to comment.