UndoRedoMixin<T extends JState> mixin
Bounded snapshot history for immutable controller states.
Only updateWithUndo records snapshots. Ordinary updates leave history intact; call clearHistory when replacing a document or loading remote data. undo and redo are synchronous. To order them with asynchronous intents, invoke them inside an intent using a sequential dispatcher.
Domain state and history are separate observables. History notifications follow the state update, including when only metadata changes. Snapshots retain state references: all state values and nested collections must be immutable. History does not reverse network, persistence or other effects.
- Superclass constraints
- JController<
T>
- JController<
Properties
- canRedo → bool
-
no setter
- canUndo → bool
-
no setter
- currentState → T
-
Returns the current state of type
T.no setterinherited - debugState → T
-
A development-only way to access state outside of StateNotifier.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
If a listener has been added using addListener and hasn't been removed yet.
no setterinherited
-
history
→ ValueListenable<
JUndoHistoryState> -
Read-only history metadata. The controller owns and disposes its notifier.
no setter
- mounted → bool
-
Whether dispose was called or not.
no setterinherited
- onError ↔ ErrorListener?
-
A callback for error reporting if one of the listeners added with addListener throws.
getter/setter pairinherited
-
redoHistory
→ List<
T> -
no setter
- redoStackSize → int
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
sideEffects
→ Stream<
JEffect> -
A broadcast stream of side effects emitted by the controller.
no setterinherited
- state ↔ T
-
The current "state" of this StateNotifier.
getter/setter pairinherited
-
stream
→ Stream<
T> -
A broadcast stream representation of a StateNotifier.
no setterinherited
-
undoHistory
→ List<
T> -
no setter
- undoStackSize → int
-
no setter
Methods
-
addListener(
Listener< T> listener, {bool fireImmediately = true}) → RemoveListener -
Subscribes to this object.
inherited
-
clearHistory(
) → void - Clears snapshots without changing domain state. Notifies history when its metadata changes. Recording stays enabled if it was enabled.
-
disableUndoRedo(
) → void - Disables recording, clears both stacks and notifies history.
-
dispose(
) → void -
Fails pending awaitable effects and closes the side effects stream.
Cancels queued intents if the dispatcher supports JPendingIntentCancellation.
Already running handlers and intents are not interrupted. External work
must check mounted or use its own cancellation API after asynchronous gaps.
override
-
emitAndWaitSideEffect<
V> (JEffect< V> effect, {Duration? timeout}) → Future<V> -
Emits a JEffect and waits for its completion or timeout.
Missing listeners and disposal fail with StateError. This does not cancel
UI handlers or external operations that have already started.
inherited
-
emitSideEffect(
JEffect effect) → void -
Emits a one-time JEffect to the UI.
inherited
-
enableUndoRedo(
{int maxHistorySize = 50}) → void - Enables recording. A smaller positive limit trims the oldest snapshots from both stacks. Invalid limits throw without changing history.
-
intent(
JIntent< T> intent) → Future<void> -
Handles a given JIntent to update the state.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onInit(
) → void -
Initialization lifecycle method.
inherited
-
redo(
) → bool - Restores the next snapshot under the same contract as undo.
-
setState(
T newState, {JIntent< JState> ? origin}) → void -
Sets a new state of type
Tif different from the current state.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
undo(
) → bool - Restores the previous snapshot. Returns false when unavailable, disposed or called from a cancelled intent. Real changes notify JObserver.
-
update(
T reducer(T state), {JIntent< JState> ? origin}) → void -
Updates the current state by applying the given
reducerfunction.inherited -
updateShouldNotify(
T old, T current) → bool -
Whether to notify listeners or not when state changes
inherited
-
updateWithUndo(
T reducer(T state), {JIntent< JState> ? origin}) → void - Applies a reducer and records the previous state only for a real change. Equal states, throwing reducers, cancellation and disposal leave history untouched. When recording is disabled this behaves like update.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited