Class ChangeSetComputor
- Namespace
- Cratis.Arc.Queries
- Assembly
- Cratis.Arc.Core.dll
Computes ChangeSet deltas between consecutive snapshots of observable collection queries.
public class ChangeSetComputor
- Inheritance
-
ChangeSetComputor
- Inherited Members
- Extension Methods
Remarks
When a collection snapshot is received, this computor compares it with the previous snapshot to determine which items were Added, Replaced, or Removed since the last update.
Identity-based delta (including Replaced detection) is used when the item type
exposes a property conventionally named Id (case-insensitive). Without an identity property, a
JSON-hash fallback is used that only surfaces Added and
Removed.
Constructors
ChangeSetComputor(JsonSerializerOptions)
Computes ChangeSet deltas between consecutive snapshots of observable collection queries.
public ChangeSetComputor(JsonSerializerOptions serializerOptions)
Parameters
serializerOptionsJsonSerializerOptionsThe JsonSerializerOptions used for item comparison.
Remarks
When a collection snapshot is received, this computor compares it with the previous snapshot to determine which items were Added, Replaced, or Removed since the last update.
Identity-based delta (including Replaced detection) is used when the item type
exposes a property conventionally named Id (case-insensitive). Without an identity property, a
JSON-hash fallback is used that only surfaces Added and
Removed.
Methods
Compute(IEnumerable<object>?, IEnumerable<object>)
Computes the delta between two consecutive collection snapshots.
public ChangeSet Compute(IEnumerable<object>? previous, IEnumerable<object> current)
Parameters
previousIEnumerable<object>The previous snapshot, or null for the first update.
currentIEnumerable<object>The current snapshot.
Returns
Remarks
ComputeByJson(object[], object[])
Computes the delta using JSON-hash comparison (fallback when no identity property is found).
public ChangeSet ComputeByJson(object[] previousItems, object[] currentItems)
Parameters
previousItemsobject[]The previous snapshot items.
currentItemsobject[]The current snapshot items.
Returns
Remarks
ComputeFromKnownChanges(IReadOnlyList<CollectionChange>, IEnumerable<object>, IEnumerable<object>?)
Builds the delta an emission already stated, rather than rediscovering it by comparison.
public ChangeSet ComputeFromKnownChanges(IReadOnlyList<CollectionChange> changes, IEnumerable<object> current, IEnumerable<object>? previous)
Parameters
changesIReadOnlyList<CollectionChange>The changes the emission carried.
currentIEnumerable<object>The current snapshot, used to resolve the items the changes name.
previousIEnumerable<object>The previous snapshot, used to resolve removed items which are no longer in
current.
Returns
Remarks
An item named by a change but present in neither snapshot is skipped rather than reported as a change to nothing - it is better to under-report a delta than to emit an entry a client cannot act on.
ComputeWithIdentity(object[], object[], PropertyInfo)
Computes the delta using a discovered identity property.
public ChangeSet ComputeWithIdentity(object[] previousItems, object[] currentItems, PropertyInfo idProperty)
Parameters
previousItemsobject[]The previous snapshot items.
currentItemsobject[]The current snapshot items.
idPropertyPropertyInfoThe property used to extract the item identity key.
Returns
Remarks
Items with a new identity key are Added; items whose key is gone are Removed; items with the same key but a different JSON representation are Replaced.
FindIdentityProperty(Type)
Discovers the property that represents the identity of an item.
public static PropertyInfo? FindIdentityProperty(Type type)
Parameters
typeTypeThe item type to inspect.
Returns
- PropertyInfo
The identity PropertyInfo, or null if not found.
Remarks
Looks for a property conventionally named Id (case-insensitive), including inherited interface properties.
The result is cached per type, so the reflection runs once per item type rather than on every emission. The cache
is cleared when Hot Reload updates types, so an identity property added while the application runs is found.