Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SetItems method in ResourceDictionary #18354

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

StefanKoell
Copy link
Contributor

What does the pull request do?

This PR provides a new method to the ResourceDictionary called AddOrUpdateRange which allows to batch multiple updates in one go and notify all subscribers about the change at the very end once the resources have been updated.

See discussion: #18346

What is the current behavior?

At the moment, adding or updating existing resources are immediately notifying all subscribers about resource changes. In complex application this can become quite expensive and slow when your updating multiple (tens or hundreds) resources by code.

What is the updated/expected behavior with this PR?

When using the AddOrUpdateRange methods, the notification of all subscribers happens only once at the end of the method, regardless of the number of updates performed.

Checklist

Breaking changes

None.

Obsoletions / Deprecations

None.

Fixed issues

#18346

@maxkatz6 maxkatz6 added the needs-api-review The PR adds new public APIs that should be reviewed. label Mar 2, 2025
@MrJul MrJul added the feature label Mar 3, 2025
@MrJul
Copy link
Member

MrJul commented Mar 5, 2025

Public API for review:

namespace Avalonia.Controls
{
    public class ResourceDictionary : ResourceProvider, IResourceDictionary, IThemeVariantProvider
    {
+        public void AddOrUpdateRange(IEnumerable<KeyValuePair<object, object?>> values);
    }
}

@maxkatz6
Copy link
Member

maxkatz6 commented Mar 6, 2025

This API should be added to the AvaloniaDictionary as well, I would say. Even as a single Reset operation, it still would be better.

@MrJul
Copy link
Member

MrJul commented Mar 6, 2025

The API review focused on the naming, as we're fine with the behavior.

Points:

After some debate, SetItems won.

@MrJul MrJul added api-change-requested The new public APIs need some changes. and removed needs-api-review The PR adds new public APIs that should be reviewed. labels Mar 6, 2025
@MrJul MrJul changed the title Implement AddOrUpdateRange method in ResourceDictionary Implement SetItems method in ResourceDictionary Mar 8, 2025
@MrJul MrJul added api-approved The new public APIs have been approved. and removed api-change-requested The new public APIs need some changes. labels Mar 8, 2025
Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@MrJul MrJul enabled auto-merge March 8, 2025 15:21
@MrJul MrJul added this pull request to the merge queue Mar 9, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved The new public APIs have been approved. feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants