Vixen
02b45cc4
csharp
public sealed class CollectionSignal<T>

A list whose changes are reported one at a time rather than as "something changed".

No guide page documents this yet — the page shows what the code says about itself.

Remarks

This is what @for binds to. A plain Signal<List<T>> can say that a list changed and nothing more, so the only correct response is to reconcile the whole thing — which for the hierarchy panel of a scene with ten thousand entities is the difference between appending one row and rebuilding ten thousand.

So mutations are recorded in a bounded log, and a reconciler reads the entries it has not seen. The log being bounded is the interesting decision: a consumer that falls far enough behind is told to resynchronise from scratch rather than the collection retaining an unbounded history on its behalf. Falling behind means not having reconciled for ChangeLogCapacity changes, which for a UI drained every frame does not happen, and for one that has been off-screen for a minute is exactly when a full rebuild is the cheaper answer anyway.

Reading Count or any item makes the reader depend on the collection as a whole. That is the coarse path, and it is the right one for a binding that shows "17 items"; the change log is the fine one.

Fields and properties (4)

  • public int ChangeLogCapacity

    How many changes the log remembers.

  • public long Revision

    How many changes this collection has ever recorded.

  • public int Count

    How many items there are.

  • public T this[int index]

    The item at .

Methods (11)

  • public CollectionSignal(int capacity = 0, int changeLogCapacity = 64)

    Creates an empty collection.

  • public CollectionSignal(IEnumerable<T> initial, int changeLogCapacity = 64)

    Creates a collection holding .

  • public ReadOnlySpan<T> Peek()

    The items, without recording a dependency.

  • public void Add(T item)

    Appends an item.

  • public void Insert(int index, T item)

    Inserts an item.

  • public void RemoveAt(int index)

    Removes the item at .

  • public bool Remove(T item)

    Removes the first occurrence of .

  • public void Move(int from, int to)

    Moves one item without removing and re-adding it.

  • public void Clear()

    Removes everything.

  • public bool TryGetChangesSince(long revision, out ReadOnlySpan<CollectionChange> changes)

    The changes since , if the log still remembers them.

  • public List<T>.Enumerator GetEnumerator()

    Enumerates the items, recording a dependency on the collection.

Used by (4)

  • CollectionSignalTestsVixen.Ui.Reactive.Tests
  • BackgroundTaskManagerVixen.Editor.Ui
  • EditorProjectVixen.Editor.Core
  • SelectionVixen.Editor.Core