Vixen
dd8b0a81
csharp
public sealed class ElementRefs<TElement> where TElement : UiElement

What an @for row's refs assigns into: one element per live iteration, found by the same key the loop is reconciled on.

Read the guide page for this →

Remarks

⚠ Why ref could not be made to do this. A ref is one assignment to one member and a loop has many rows, so the member would hold whichever row was built last — and, because BuildContext.For reuses a surviving key's region and does not re-run its body, whichever row was built last the first time the sequence contained it. That is VXML2010. A member holding a List<T> has the same defect: the body appends once per key ever, so a reordered or filtered sequence leaves the list in an order nothing corresponds to, silently.

⚠ So the handle is keyed on the iteration rather than filled by the body. The key is the one @for already reconciles on, taken from the loop rather than recomputed here, and the entry is registered against the row's region — so a row that leaves the sequence takes its entry with it, and a row that survives keeps the element it has always had whatever its position becomes. Reordering cannot hand back the wrong control because position is not what is being asked.

⚠ Enumeration is deliberately not offered. The order of the rows is the order of the sequence the panel already holds, and a second answer to that question is a second answer to get wrong. Iterate the model and look each row up.

The frame rule, and why the indexer throws. An @for body builds inside an effect, so the entries appear when the document's effects are next flushed and not on the line that changed the sequence. A lookup that answered null there would be a wrong answer to a right question, arriving as a NullReferenceException some distance away; Item says what happened instead. Code that expects a key to be absent asks TryGet.

Fields and properties (2)

  • public int Count

    How many rows are registered.

  • public TElement this[object key]

    The element registered for one iteration's key.

Methods (2)

  • public bool TryGet(object key, out TElement? element)

    The same, for a caller to whom an absent key is an answer rather than a fault.

  • public bool Contains(object key)

    Whether a key has an element.

Used by (9)

  • BranchingRefsVixen.Ui.Tests
  • BuildContextVixen.Ui
  • CompositionTestsVixen.Ui.Tests
  • MarkupTestsVixen.Ui.Controls.Tests
  • MixerVixen.Ui.Controls.Tests
  • AudioMixerViewVixen.Editor.AssetEditors
  • ComponentsViewVixen.Editor.App
  • ShapeVocabularyViewVixen.Editor.AssetEditors
  • VariationHarnessViewVixen.Editor.AssetEditors