Skip to content

How to produce single update on .Clear() when using .GroupOn() #621

Answered by RolandPheasant
Bulgrak asked this question in Q&A
Discussion options

You must be logged in to vote

The reason is you have a nested observable list and each one of these is producing an extra notification. You can achieve the desired result and simplify the code by using GroupWithImmutableState instead on GroupOn. The former produces an array of items instead of a nested observable cache for each group category.

var latestTopicByCategoryObservable = topicSourceList.Connect()
    .GroupWithImmutableState(x => x.Category)
    .Transform(grouping => grouping.Items.OrderByDescending(t => t.Timestamp).First());

latestTopicByCategoryObservable.Subscribe(x =>
{
    Console.WriteLine(x.TotalChanges);
});

The above code produces a single change set for Clear.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Bulgrak
Comment options

Answer selected by Bulgrak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants