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
| Member | Summary |
|---|---|
AtomsList(IReadOnlyList<T>, IEqualityComparer<T>) | Creates the list. |
Properties
| Member | Summary |
|---|---|
Count | How many items there are. |
Item | The item at a position. Writing an equal item changes nothing and notifies no one. |
RecordsHistory | Whether changes of this list enter the undo history. |
Value | 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. |
Methods
| Member | Summary |
|---|---|
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
| Name | Type | Description |
|---|---|---|
initial | IReadOnlyList<T><T> | What it starts with; empty when omitted. It is copied, not held. |
comparer | IEqualityComparer<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
| Name | Type | Description |
|---|---|---|
index | int | Which 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
| Name | Type | Description |
|---|---|---|
item | T | What 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
| Name | Type | Description |
|---|---|---|
items | IReadOnlyList<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
| Name | Type | Description |
|---|---|---|
item | T | What 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
| Name | Type | Description |
|---|---|---|
index | int | Where it goes. |
item | T | What 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
| Name | Type | Description |
|---|---|---|
item | T | What to take out. |
RemoveAt(int)
public void RemoveAt(int index);
Takes out the item at a position.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | Which 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
| Name | Type | Description |
|---|---|---|
index | int | Where to start. |
count | int | How 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
| Name | Type | Description |
|---|---|---|
items | IReadOnlyList<T><T> | What the list should hold instead. |
Subscribe(Action)
public IDisposable Subscribe(Action listener);
Calls back whenever the contents change.
Parameters
| Name | Type | Description |
|---|---|---|
listener | Action | What 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
| Type | Thrown when |
|---|---|
InvalidOperationException | Called from off the drawing thread. |