Replies: 1 comment 2 replies
-
On a personal level, I would say yes, immutable state is recommended, but both scenarios are equally valid, and (in theory) equally supported.
Nothing about
The main use-case for mutable models, I'd say, is for use with WPF/MVVM apps. Constantly swapping out |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I have a design question about SourceCache.
In Rx, immutable DTOs are usually preferred because they make state easier to reason about. But in DynamicData, SourceCache has a Refresh method which looks more useful for mutable models (when the object content changes but the key stays the same).
My scenario:
I separate a lightweight Location (id + parentId) from expensive LocationData (properties).
I want downstream to know if only the tree structure changed (rerender tree) or if the property data changed (rerender detail).
If I use immutable DTOs, I would have two streams: one for Location and one for LocationData. Both share the same key (id) so their lifetime is coupled — when a Location is removed, its LocationData is removed too.
If I use a model instead of immutable DTOs, I would implement the LocationData with a GetData method then trigger the data change by refresh Location, the view could filter out the structure changed by WhereReasonsAreNot(ChangeReason.Refresh)
, and only the property change by WhereReasonsAre(ChangeReason.Refresh)
So my questions are:
Is the recommended practice still to use immutable DTOs with SourceCache (and just call AddOrUpdate with a new object on change)?
Or is SourceCache designed mainly for mutable models, with Refresh as the normal way to signal changes?
In real-world apps, when should I prefer Refresh vs AddOrUpdate?
Thanks a lot for clarifying!
Beta Was this translation helpful? Give feedback.
All reactions