Replies: 2 comments
-
Blazor has been quite fluid since it's release so I understand the frustration of having to use it. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for the insight. The What we're using right now is the .NET 8 version of Blazor. The template for it is "Blazor Web App, WebAssembly, Global Interactivity". |
Beta Was this translation helpful? Give feedback.
-
I come from an Angular background and highly enjoy working in a reactive way and really dislike the way Blazor does things (but have to use it).
Rx.NET and ReactiveUI seem like the perfect combination to make me happy, but I'm having trouble integrating the libraries in a way that doesn't make me fight Blazor too much (and usually when you're fighting with your main framework you're doing something wrong).
In particular I'm having trouble with Blazor
[Parameter]
s.The current use-case I wanted to implement was simply reacting to route param changes in my ViewModel.
Given a route template in the form of
users/{id:guid}
I simply want theid
in my view model.The default way is to put a
[Parameter]
on your component with a name matching the route value.Now I've already written an observable wrapper around
NavigationManager
that does the parsing for me and returns anIObservable<string>
given a route template and route param name.The problem is Blazor ALWAYS expects there to be a
[Parameter]
with a matching name if you have a param in your route.That sucks.
But to me, this is a more general problem:
How do I deal with Blazor's
[Parameter]
and the way Blazor expects me to do things when I have a ViewModel? Blazor REALLY wants you to implement all[Parameter]
s as auto-properties with nothing added to the setter and getter (although I don't really know why). It goes as far as issuing a warning if you don't use auto-properties.I really don't want to go the way of
OnParametersSet
with the ViewModel, which would be the Blazor default way to handle executing something when a parameter changes. I could of course use this pattern to put the[Parameter]
values into my ViewModel... but then they'd already be on the View, so what am I even using the ViewModel for?Should I just adopt above pattern and keep
[Parameter]
s exclusively in the view and useOnParametersSet
where I call a ViewModel command with a parameter when I need the functionality? Is that really the way?I really hope someone can give me some guidance or point me towards an article or a large code base using Blazor + ReactiveUI successfully.
Beta Was this translation helpful? Give feedback.
All reactions