API Reference
The public API is three names, all importable directly from reliev: the Store base class and the mutation and computed decorators.
Store
reliev.store.Store
Store that tracks mutations to state in order to enable undo/redo functionality
undo_context
property
Returns the context of the mutation that undo() would revert,
or None when there is nothing to undo (or no context was given)
redo_context
property
Returns the context of the mutation that redo() would reapply,
or None when there is nothing to redo (or no context was given)
__init__
Creates a store with the given state as the initial state.
When strict is False, calling mutations that do not result
in an actual change will be ignored.
Decorators
reliev.store.mutation
Mark a store method as a mutation that records an undo/redo entry.
context attaches a user-defined value to the recorded history
entry, which can be read back through Store.undo_context and
Store.redo_context, for instance to build user-facing undo/redo
labels. It can be:
- any (hashable) value, stored as-is — for example a plain string, a
translation key, or a tuple such as
("added_items", 3) - a callable, invoked with the same
(self, *args, **kwargs)as the mutation itself (before the mutation runs), whose return value is stored as the context
Callers can override the context for a single call by passing the
reserved keyword argument mutation_context, which is consumed by the
decorator and not passed on to the mutation itself.
reliev.store.computed
Expose a method as a read-only, observ-backed reactive property.
The decorated method must take only self. It is replaced by a
property whose getter lazily builds an observ computed expression
(one per instance, cached in the instance __dict__) and returns
its current value. Assignment raises AttributeError, since
property has no setter.
History entries
reliev.store.HistoryEntry
Bases: NamedTuple
A single recorded mutation in the store's undo/redo history.