Skip to main content

bloc_signals_replay 1.5.0 copy "bloc_signals_replay: ^1.5.0" to clipboard
bloc_signals_replay: ^1.5.0 copied to clipboard

Undo and redo state history tracking utilities for CubitSignal and BlocSignal.

bloc_signals_replay #

pub package style: very good analysis

Replay, undo, and redo state tracking utilities for BlocSignal and CubitSignal state containers.


🌐 Ecosystem Packages #

The BlocSignal monorepo consists of 14 modular packages:

Package Version Description
bloc_signals pub Core pure Dart reactive state primitives bridging BLoC & Signals
bloc_signals_flutter pub Flutter UI bindings, providers, builders, listeners & selectors
bloc_signals_bloc pub Classic BLoC 8/9 interop adapters & bidirectional event bridges
bloc_signals_riverpod pub Bidirectional Riverpod 2/3 interop adapters & provider extensions
bloc_signals_jaspr pub Jaspr web component integration and state binding for BlocSignal
bloc_signals_hydrate pub Automated synchronous local state persistence & hydration
bloc_signals_replay pub Undo & redo state history tracking for CubitSignal and BlocSignal
bloc_signals_otel pub OpenTelemetry tracing and span generation for state transitions
bloc_signals_devtools pub Universal DevTools telemetry observer using dart:developer
bloc_signals_test pub Declarative unit testing utilities (blocSignalTest)
bloc_signals_lint pub Custom analyzer lint rules & automated IDE quick-fixes
bloc_signals_genui pub Pure-Dart A2UI streaming state machine & Generative UI runtime adapter
bloc_signals_genui_flutter pub Declarative Flutter surface containers & A2UI catalog widget adapters
bloc_signals_genui_jaspr pub Declarative Jaspr web components & DOM catalog adapters for A2UI

⚡ Overview #

bloc_signals_replay brings automatic undo and redo state management capabilities to BlocSignal and CubitSignal, mirroring Felix Angelov's replay_bloc package architecture.

  • ReplayMixin / ReplayCubit / ReplayCubitMixin: Undo and redo stack support for BlocSignalBase and method-driven CubitSignal containers.
  • ReplayBloc / ReplayBlocMixin: Undo and redo stack support for event-driven BlocSignal containers, with synthetic _Undo and _Redo transition tracing.
  • _ChangeStack: Configurable history limits and shouldReplay state filtering.

🚀 Quick Start #

ReplayCubit #

Extend ReplayCubit to automatically track state changes:

import 'package:bloc_signals_replay/bloc_signals_replay.dart';

class CounterCubit extends ReplayCubit<int> {
  CounterCubit() : super(initialState: 0);

  void increment() => emit(stateValue + 1);
}

void main() {
  final cubit = CounterCubit();

  cubit.increment(); // state is 1
  print(cubit.canUndo); // true

  cubit.undo();      // state reverts to 0
  print(cubit.canRedo); // true

  cubit.redo();      // state becomes 1
}

ReplayBloc #

Extend ReplayBloc for event-driven state containers:

import 'package:bloc_signals_replay/bloc_signals_replay.dart';

sealed class CounterEvent extends ReplayEvent {
  const CounterEvent();
}

final class Increment extends CounterEvent {
  const Increment();
}

class CounterBloc extends ReplayBloc<CounterEvent, int> {
  CounterBloc() : super(initialState: 0) {
    on<Increment>((event, emit) => emit(stateValue + 1));
  }
}

void main() {
  final bloc = CounterBloc();

  bloc.add(const Increment()); // state is 1
  bloc.undo();                 // state is 0
  bloc.redo();                 // state is 1
}

Stack Bounds, State Filtering & Transition Coalescing #

Pass a limit parameter, override shouldReplay to filter states, or override shouldCoalesce(previousState, currentState, nextState) to merge continuous edits (such as slider drags or rapid typing) into a single undo/redo step:

class BoundedCubit extends ReplayCubit<int> {
  // Cap undo stack depth to 5 states
  BoundedCubit() : super(initialState: 0, limit: 5);

  // Skip even states during replay
  @override
  bool shouldReplay(int state) => !state.isEven;

  // Coalesce consecutive increments within the same editing burst
  @override
  bool shouldCoalesce(int previousState, int currentState, int nextState) {
    return (nextState - currentState).abs() == 1 &&
        (currentState - previousState).abs() == 1;
  }
}

Memory Management & Sensitive State History #

Because ReplayMixin retains historical state instances in memory to power undo() and redo(), take the following precautions when managing large or sensitive state:

  • Bound History Depth (limit): Pass limit: (or maxHistoryLength:) in the constructor or assign limit at runtime to cap retained states. Set limit = 0 during sensitive flows (for example password entry, authentication tokens, or personally identifiable information) to clear existing history and disable recording.
  • Clear at Session Boundaries (clearHistory()): Call clearHistory() explicitly at logout or session boundaries to immediately release retained state references. When composed with HydratedMixin, calling await clear() automatically invokes onReset() and clears the replay stack in both mixin composition orders.
  • Reactive canUndo & canRedo: canUndo, canRedo, canUndoSignal, and canRedoSignal are backed by reactive Computed<bool> signals (autoDispose: false) and update atomically with stateValue inside batch(), so context.select((c) => c.canUndo), Watch, computed(), and effect() rebuild automatically.
  • Automatic Cleanup on Disposal (close()): Calling close() automatically invokes clearHistory(), releasing all retained state references and resetting canUndo and canRedo to false.
0
likes
160
points
390
downloads

Documentation

API reference

Publisher

verified publisherblocsignal.dev

Weekly Downloads

Undo and redo state history tracking utilities for CubitSignal and BlocSignal.

Repository (GitHub)
View/report issues
Contributing

Topics

#bloc #signals #replay #undo #state-management

License

MIT (license)

Dependencies

bloc_signals, meta, signals_core

More

Packages that depend on bloc_signals_replay