Atom<T> class
Namespace: Arlecchino.Atoms · Assembly: Arlecchino.Core
One piece of application state that notifies what reads it and marks the frame stale by itself. Whether an edit can be undone is decided by creating a TrackedAtom or a LocalAtom.
public abstract class Atom<T> : IReadableAtom<T>
Implements IReadableAtom<T>
Constructors
| Member | Summary |
|---|---|
Atom(T, IEqualityComparer<T>) | Creates an atom holding a starting value. |
Properties
| Member | Summary |
|---|---|
RecordsHistory | Whether edits of this atom enter the undo history. |
Value | The value. Writing an equal value changes nothing; any other write notifies subscribers, asks for a repaint, and records an undo step when the atom is undoable. |
Methods
| Member | Summary |
|---|---|
Post(T) | Hands a value to the drawing thread, to be written just before the next frame in the order it was posted. Nothing is written when this returns, and atoms that must change together belong in one FrameThread.Post. |
Subscribe(Action) | Calls back whenever the value changes. |
Constructors in detail
Atom(T, IEqualityComparer<T>)
public Atom(T initial, IEqualityComparer<T> comparer);
Creates an atom holding a starting value.
Parameters
| Name | Type | Description |
|---|---|---|
initial | T | The value to start with. |
comparer | IEqualityComparer<T><T> | How to decide that writing to it changed nothing; the default comparer for T is used when omitted. |
Properties in detail
RecordsHistory
public abstract bool RecordsHistory { get; }
Whether edits of this atom enter the undo history.
Type bool
Value
public T Value { get; set; }
The value. Writing an equal value changes nothing; any other write notifies subscribers, asks for a repaint, and records an undo step when the atom is undoable.
Type T
Methods in detail
Post(T)
public void Post(T value);
Hands a value to the drawing thread, to be written just before the next frame in the order it was posted. Nothing is written when this returns, and atoms that must change together belong in one FrameThread.Post.
Parameters
| Name | Type | Description |
|---|---|---|
value | T | The value to write on the drawing thread. |
Subscribe(Action)
public IDisposable Subscribe(Action listener);
Calls back whenever the value changes.
Parameters
| Name | Type | Description |
|---|---|---|
listener | Action | What to run on change. |
Returns IDisposable — Dispose it to stop listening.