Table of Contents

Method Map

Namespace
SodaFlow.Collections
Assembly
SodaFlow.Collections.dll

Map<TKey, TIdentity, TState, TResult>(ReactiveCollection<TKey, TIdentity, TState>, Func<TKey, TResult>, int, Action<TResult>?)

One object for each key, in the order of this collection, thus a list can bind to a stable object.

public static MappedItems<TResult> Map<TKey, TIdentity, TState, TResult>(this ReactiveCollection<TKey, TIdentity, TState> collection, Func<TKey, TResult> project, int retainedBeyondTheView = 512, Action<TResult>? onEvicted = null) where TKey : notnull where TIdentity : notnull

Parameters

collection ReactiveCollection<TKey, TIdentity, TState>

The collection or view to project.

project Func<TKey, TResult>

Builds the object for one key. It runs one time for each key that this code keeps.

retainedBeyondTheView int

The number of keys that left to keep objects for. The default is correct for a screen with pages across a large collection. Use a larger value when a move back to a page is frequent and a new build of a row is expensive, and a smaller value when the objects are large.

onEvicted Action<TResult>

This receives an object whose key this code removed, and it is the position to release the resources of that object. A projection that builds bindables must dispose them here, or they continue after the rows that held them.

Returns

MappedItems<TResult>

The projected objects and the path to release them. Bind to Items, and dispose this object with the other resources of the caller.

Type Parameters

TKey

The type of the keys.

TIdentity

The type of the immutable part of an item.

TState

The type of the mutable part of an item.

TResult

The type of the object for each key.

Remarks

This is the last step of a chain and not one more stage in one. The result is a cell of projected objects and not a collection, because a projection has no identity and no state for a subsequent stage to filter on or to sort on.

project runs one time for each key and this code keeps the object. Thus, a collection whose items changed, and whose members and order did not change, gives the same objects in the same sequence. That stops a new build of each row of a bound list at a change to the value of one row. Build the bindings of a row from StateCell<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, TKey) and IdentityCell<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, TKey) in the projection, and each row then follows its own item.

The objects that this code keeps have a limit. Without a limit, a projection across a large collection holds an object for each key that it showed. The limit counts the keys that left. This code keeps each key that is here now, at each value of the limit, thus a limit below the size of the collection cannot remove a row that the code reads again immediately. The keys that left go out in the sequence of their departure, and the first key to go out is the key with the longest interval since it left. Thus, a move between the same two pages costs nothing.