C
C#2w ago
BondAddict

Does anyone have advice on dealing with Blazor not being reactive out of the box?

I have an application that I inherited at work that has some large models with lots of nested properties and collections. I've tried implementing Fody/PropertyChange.Fody and I'm currently looking at ReactiveUI/ReactiveUI.Fody/ReactiveUI.SourceGenerator. ReactiveUI looks to be a good way to go, but their documentation is incredibly confusing. My main issue is that I need to be notified anytime an item in any of my collections is changed (edit). I've already swapped all my List<T> properties to use ObservableCollection<T> instead, but that only kicks off PropertyChanged if the collection has items added or removed and doesn't notify if an item itself changes. I'm used to Angular/Vue which have reactivity baked into their core, but it just feels like I'm having to fight my tools to get basic functionality. I know that I can wire up INotifyPropertyChanged to every class and manually hook up all the property change detection, but that seems like a ton of work considering that two apps I support both have reactivity that totally broken already. Fody/Fody.PropertyChanged added all the boiler plate hook-ups (when I decompiled my dll) but due to the collections not being reactive, the changes never made it up to my parent model. The app is Blazor Server pointed to .Net 8 As a side note, I've been looking at BindingList<T> which has notification events for items changing, but it sounds like that was just added to be used with Win Forms.
3 Replies
mg
mg2w ago
assuming you're referring to the UI not updating when the state changes, the issues i've had with that were mostly resolved by ensuring all my UI event handlers were EventCallbacks, which automatically re-render components after the callback finishes
Imtiaz
Imtiaz2w ago
EventCallback should be able to do the trick. You can then trigger the refresh UI command in the parent component.
BondAddict
BondAddictOP2w ago
I'm not concerned about the ui. I just need to know when the model changes so I can fire a backend function. Currently only certain changes notify my EditContext or actual model.

Did you find this page helpful?