Skip to main content

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

MemberSummary
Atom(T, IEqualityComparer<T>)Creates an atom holding a starting value.

Properties

MemberSummary
RecordsHistoryWhether edits of this atom enter the undo history.
ValueThe 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

MemberSummary
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

NameTypeDescription
initialTThe value to start with.
comparerIEqualityComparer<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

NameTypeDescription
valueTThe value to write on the drawing thread.

Subscribe(Action)

public IDisposable Subscribe(Action listener);

Calls back whenever the value changes.

Parameters

NameTypeDescription
listenerActionWhat to run on change.

Returns IDisposable — Dispose it to stop listening.