Extend IsChanged for sub viewmodels #23
Replies: 2 comments
-
This is a similar problem to #12: how to safely and reliably get change notifications from the child up to the parent. I'm somewhat reluctant to introduce behaviour where we leak memory unless the user takes a particular action to mitigate it, particularly if it's the result of a common case that the user can walk into by accident. That said, if the child VM is being assigned to a property which we're generating, we know when that's been unassigned, and we can remove our event subscription at that point. I rather suspect the best approach is going to be to tackle this at the same time as #12, which means waiting for partial properties. Thankfully there's now a proposal for those! |
Beta Was this translation helpful? Give feedback.
-
+1 for this. Would be awesome if this library could subscribe/unsubscribe INPC to classes set to generated properties. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I don't know if this is possible with source generators, but if it was it would be pretty useful, I think:
If in a viewmodel you have fields/properties which implement
INotifyPropertyChanged
andexpose a readable public property with the same name as the one used for
[IsChanged]
, then it would be nice if changes to the sub-viewmodels is-dirty flag would also change the one in the current viewmodel.Because this would have to work via subscribing to the event, there'd be a potential issue of leaks. But the generated code could just include a method
ReleaseSubscriptions()
and the writer of a viewmodel could implementIDisposable
and call it. A decent DI container (eg Autofac) will automatically callDispose()
at the end of lifetime for objects it created which implementIDisposable
, so this would be fairly comfortable.Should probably be an opt-in feature that one specifies via the
[IsChanged]
attribute, to avoid breaking existing code.Cheers,
MR
Beta Was this translation helpful? Give feedback.
All reactions