rodydavis / signals.dart

Reactive programming made simple for Dart and Flutter
http://dartsignals.dev
Apache License 2.0
378 stars 44 forks source link

ChangeStackSignal behavior #265

Closed rodrigopequeno closed 1 month ago

rodrigopequeno commented 1 month ago

I'm using ChangeStackSignal and I noticed when updating to the latest version (5.2.0/5.2.1) a different behavior than version 4.5.1.

Using the example in the documentation as a basis: Link

final s = ChangeStackSignal(0, limit: 2);
s.value = 1;
s.value = 2;
s.value = 3;
print(s.value); // 3
s.undo();
s.undo();
print(s.value); // 1
print(s.canUndo); // false
s.redo();
print(s.value); // 2

The test below fails on expect(s.value, 1) as the current value is 3:

void main() {
  test(
    'should do undo N times',
    () {
      final s = changeStack(0, limit: 2);
      s.value = 1;
      s.value = 2;
      s.value = 3;
      expect(s.value, 3); // 3
      s.undo();
      s.undo();
      expect(s.value, 1); // 1
      expect(s.canUndo, false); // false
      s.redo();
      expect(s.value, 2); // 2
    },
  );
}
rodydavis commented 1 month ago

Thanks for reporting, will try to reproduce!

rodydavis commented 1 month ago

Fixed and will be on the next release!