Proof of concept extracting private Blazor component into a Circuit/Session bound Compute service powered by Stl.Fusion.
See the updates to sample project Blazorise.
Goals
- End-to-end Real Time, from database to multiple hosts and multiple Blazor clients; thanks to Fusion.
- Isolation of UI state and update logic into an live/observable model.
- The PageState fusion service serves up an immutable object that can efficiently be rendered through fusion LiveComponents. Child components can check for reference equality of state child nodes passed to them as parameters
- Efficient rendering without the need to implement Blazor's ShouldComponentRender nor to strategically call StateHasChanged.
- This translates to good scalability of complex user interfaces. All components can be simple, 'Pure'; free of complex code and side-effects or inter-component rendering dependencies. All logic is testable and delegated away into the Actions in the stores.
- Testing the stores is a good substitute for testing the actual Blazor components and much easier.
Done:
- TodoPageState contains the client-side state for the todo page, such as current page size and page marker.
- The state is owned by the TodoPageStateService. It manipulates the state through Commands, such as LoadMore. This in turn depends on the TodoService for live requerying.
- Started extracted the logic from the todopage.razor, making it a render-only component
Issues and Todos:
- The state in TodoPageStateService behaves as ServiceLifetime.Transient and is reset after each request, even though the service is marked as ServiceLifetime.Scoped here as per MS Docs. Due to this bug the state (including current PageSize) is lost on every request and hence loading more pages does not work.
- Finish extracting all logic and commands in todopage.razor and todoitem.razor
- Testers still to be implemented.