Skip to content

Commit b67c143

Browse files
committed
fix(replay_bloc): trim history to the limit on redo
1 parent f3b9af0 commit b67c143

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎packages/replay_bloc/lib/src/change_stack.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class _ChangeStack<T> {
4848
if (canRedo) {
4949
final change = _redos.removeFirst();
5050
_history.addLast(change);
51+
_trimHistory();
5152
return _shouldReplay(change._newValue) ? change.execute() : redo();
5253
}
5354
}

‎packages/replay_bloc/test/replay_cubit_test.dart‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,27 @@ void main() {
181181
expect(states, const <int>[1, 2, 3, 4, 3]);
182182
});
183183

184+
test('trims history to a lowered limit on redo', () async {
185+
final states = <int>[];
186+
final cubit = CounterCubit();
187+
final subscription = cubit.stream.listen(states.add);
188+
cubit
189+
..increment()
190+
..increment()
191+
..increment()
192+
..undo()
193+
..undo()
194+
..limit = 1
195+
..redo()
196+
..redo()
197+
..undo()
198+
..undo()
199+
..undo();
200+
await cubit.close();
201+
await subscription.cancel();
202+
expect(states, const <int>[1, 2, 3, 2, 1, 2, 3, 2]);
203+
});
204+
184205
test('reverts to initial state', () async {
185206
final states = <int>[];
186207
final cubit = CounterCubit();

0 commit comments

Comments
 (0)