For example, I have an observable of some collections which indicates statuses of objects (I get it periodically through REST API).
class User
{
int Id { get; }
string Name { get; }
string Status { get; }
}
IObservable<User> source;
I want to create a DynamicCache
object and update it each time the source
gives me a new result. So I wrote:
var models = new SourceCache<User,int>(user => user.Id);
models.Connect()
.Transform(u => new UserViewModel() {...})
...
.Bind(out viewModels)
.Subscribe();
source.Subscribe(ul => models.EditDiff(ul, (a, b) => a.Status == b.Status));
But now every time a user changes its status, .Transform(...)
method creates a new instance of UserViewModel
, which isn't the desired behaviour.
Can I somehow determine a rule of updating existing ViewModel's properties (in the derived collection) when source item with the same Id is changing instead of creating a new one every time?