Skip to content

Experiment: Collections with property keys#1985

Draft
tomasherceg wants to merge 3 commits intomainfrom
experiment/keyed-collections
Draft

Experiment: Collections with property keys#1985
tomasherceg wants to merge 3 commits intomainfrom
experiment/keyed-collections

Conversation

@tomasherceg
Copy link
Member

@tomasherceg tomasherceg commented Jan 10, 2026

Currently, when we receive a modified collection from the server, DotVVM updates the client viewmodel by either expanding or shrinking the collection and potentially reusing the first N observables.

For example, when we remove a record from the middle of the collection, it removes the last element and updates the data in the elements that were shifted. This generates many client-side events that degrade performance, and it also prevents us from introducing new features, such as the animated foreach binding where the items could appear or disappear using transitions.

This is just an experiment that needs to be further expanded:

  • Server-side support - when a property is marked with the [Key] attribute, it will be validated (it must be a primitive type) and written in the type metadata
  • Test that preserving the observable objects actually works with foreach binding and the DOM elements are not recreated
  • Extract the function to calculate object key to allow using it in other scenarios as well (currently, it takes values of all key properties in the order they are in type metadata, and serializes them as JSON, which leads to a composite key that is comparable)
  • Handle situations with duplicate keys
  • Support for keys in nullable properties
  • Support for custom primitive types
  • Enhance the concept so it works automatically for collections of primitive types
  • It could work automatically for dictionaries as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant