Skip to content

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

can_undo property

can_undo

Returns whether the store can undo some mutation

can_redo property

can_redo

Returns whether the store can redo some mutation

undo_context property

undo_context

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

redo_context

Returns the context of the mutation that redo() would reapply, or None when there is nothing to redo (or no context was given)

__init__

__init__(state, strict=True)

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.

undo

undo()

Undoes the last mutation

redo

redo()

Redoes the next mutation

Decorators

reliev.store.mutation

mutation(_fn: M) -> M
mutation(*, strict: bool | None = None, context: ContextArg | None = None) -> Callable[[M], M]
mutation(_fn=None, *, strict=None, context=None)

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

computed(_fn: Callable[[Any], T]) -> ComputedProperty[T]
computed(*, deep: bool = True) -> Callable[[Callable[[Any], T]], ComputedProperty[T]]
computed(_fn=None, *, deep=True)

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.