Skip to main content

AtomsList<T> class

Namespace: Arlecchino.Atoms.Collections · Assembly: Arlecchino.Core

A list held as one piece of application state, changed in place. Every change notifies what reads the list, marks the frame stale and records an undo step.

public abstract class AtomsList<T> : IReadableAtom<IReadOnlyList<T>>

Implements IReadableAtom<IReadOnlyList<T><T>>

Constructors

MemberSummary
AtomsList(IReadOnlyList<T>, IEqualityComparer<T>)Creates the list.

Properties

MemberSummary
CountHow many items there are.
ItemThe item at a position. Writing an equal item changes nothing and notifies no one.
RecordsHistoryWhether changes of this list enter the undo history.
ValueWhat the list holds now, as a live view rather than a copy. It is read-only all the way down, so every change goes through the members below.

Methods

MemberSummary
Add(T)Puts an item at the end.
Add(IReadOnlyList<T>)Puts several items at the end at once. One notification, one frame and one undo step for the lot, which is what a loop of AtomsList.Add cannot give — that would undo a page of rows one row at a time.
Clear()Takes everything out. An empty list changes nothing.
GetEnumerator()Walks what the list holds, so foreach over the list itself reads the way it does over a list. Reach for AtomsList.Value where a sequence is wanted, LINQ included.
IndexOf(T)Where an item is, or -1 when the list does not hold it.
Insert(int, T)Puts an item at a position, moving the rest along.
Remove(T)Takes out the first item equal to this one, and does nothing when there is none.
RemoveAt(int)Takes out the item at a position.
RemoveRange(int, int)Takes out several items in a row at once, with one notification, one frame and one undo step for the lot. Trimming a list one item at a time would come back the same way.
Reset(IReadOnlyList<T>)Replaces the contents in one go, for the case the list is not edited but reloaded — a query answered, a folder read again, a filter applied. Contents equal to what is already there change nothing.
Subscribe(Action)Calls back whenever the contents change.
Touch()Says that an item already in the list changed inside itself, so everything watching the list hears about it. Replace the item instead, unless its identity has to survive the change.

Constructors in detail

AtomsList(IReadOnlyList<T>, IEqualityComparer<T>)

public AtomsList(IReadOnlyList<T> initial, IEqualityComparer<T> comparer);

Creates the list.

Parameters

NameTypeDescription
initialIReadOnlyList<T><T>What it starts with; empty when omitted. It is copied, not held.
comparerIEqualityComparer<T><T>How AtomsList.Remove finds an item, and how writing to the indexer decides it changed nothing; the default comparer for T is used when omitted.

Properties in detail

Count

public int Count { get; }

How many items there are.

Type int

Item

public T this[int index] { get; set; }

The item at a position. Writing an equal item changes nothing and notifies no one.

Parameters

NameTypeDescription
indexintWhich one.

Type T

RecordsHistory

public abstract bool RecordsHistory { get; }

Whether changes of this list enter the undo history.

Type bool

Value

public IReadOnlyList<T> Value { get; }

What the list holds now, as a live view rather than a copy. It is read-only all the way down, so every change goes through the members below.

Type IReadOnlyList<T><T>

Methods in detail

Add(T)

public void Add(T item);

Puts an item at the end.

Parameters

NameTypeDescription
itemTWhat to add.

Add(IReadOnlyList<T>)

public void Add(IReadOnlyList<T> items);

Puts several items at the end at once. One notification, one frame and one undo step for the lot, which is what a loop of AtomsList.Add cannot give — that would undo a page of rows one row at a time.

Parameters

NameTypeDescription
itemsIReadOnlyList<T><T>What to add. Adding none changes nothing.

Clear()

public void Clear();

Takes everything out. An empty list changes nothing.

GetEnumerator()

public List<T> GetEnumerator();

Walks what the list holds, so foreach over the list itself reads the way it does over a list. Reach for AtomsList.Value where a sequence is wanted, LINQ included.

Returns Enumerator<T><T> — The enumerator, which throws when the list changes while it is being walked.

IndexOf(T)

public int IndexOf(T item);

Where an item is, or -1 when the list does not hold it.

Parameters

NameTypeDescription
itemTWhat to look for.

Returns int — The position of the first item equal to it.

Insert(int, T)

public void Insert(int index, T item);

Puts an item at a position, moving the rest along.

Parameters

NameTypeDescription
indexintWhere it goes.
itemTWhat to insert.

Remove(T)

public void Remove(T item);

Takes out the first item equal to this one, and does nothing when there is none.

Parameters

NameTypeDescription
itemTWhat to take out.

RemoveAt(int)

public void RemoveAt(int index);

Takes out the item at a position.

Parameters

NameTypeDescription
indexintWhich one.

RemoveRange(int, int)

public void RemoveRange(int index, int count);

Takes out several items in a row at once, with one notification, one frame and one undo step for the lot. Trimming a list one item at a time would come back the same way.

Parameters

NameTypeDescription
indexintWhere to start.
countintHow many to take out. Taking none changes nothing.

Reset(IReadOnlyList<T>)

public void Reset(IReadOnlyList<T> items);

Replaces the contents in one go, for the case the list is not edited but reloaded — a query answered, a folder read again, a filter applied. Contents equal to what is already there change nothing.

Parameters

NameTypeDescription
itemsIReadOnlyList<T><T>What the list should hold instead.

Subscribe(Action)

public IDisposable Subscribe(Action listener);

Calls back whenever the contents change.

Parameters

NameTypeDescription
listenerActionWhat to run on change.

Returns IDisposable — Dispose it to stop listening.

Touch()

public void Touch();

Says that an item already in the list changed inside itself, so everything watching the list hears about it. Replace the item instead, unless its identity has to survive the change.

Exceptions

TypeThrown when
InvalidOperationExceptionCalled from off the drawing thread.