escamoteur / functional_listener

MIT License
61 stars 10 forks source link

Incorrect mapped value after removeListener #13

Open karabanovbs opened 1 month ago

karabanovbs commented 1 month ago

Reproduction:

import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:functional_listener/functional_listener.dart';

void main() {
  group('MapValueNotifier', () {
    test('should return same value', () {
      void listener() {}

      final original = ValueNotifier(0);
      final mapped = original.map((value) => value);

      mapped.addListener(listener);
      mapped.removeListener(listener);

      original.value = 123;

      expect(original.value, mapped.value);
    });
  });
}

Expected: Value of original and mapper notifier should be same

Actual: Value of original and mapper notifier is different

escamoteur commented 1 month ago

Maybe I miss something here but why should the original and the mapped one be equal if the mapping does a +1? Am 6. Aug. 2024, 21:53 +0100 schrieb KarabanovBoris @.***>:

Reproduction: import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:functional_listener/functional_listener.dart';

void main() { group('MapValueNotifier', () { test('should return same value', () { void listener() {}

 final original = ValueNotifier(0);
 final mapped = original.map((value) => value + 1);

 mapped.addListener(listener);
 mapped.removeListener(listener);

 original.value = 123;

 expect(original.value, mapped.value);

}); }); } Expected: Value of original and mapper notifier should be same Actual: Value of original and mapper notifier is different — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

karabanovbs commented 1 month ago

Maybe I miss something here but why should the original and the mapped one be equal if the mapping does a +1? Am 6. Aug. 2024, 21:53 +0100 schrieb KarabanovBoris @.>: Reproduction: import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:functional_listener/functional_listener.dart'; void main() { group('MapValueNotifier', () { test('should return same value', () { void listener() {} final original = ValueNotifier(0); final mapped = original.map((value) => value + 1); mapped.addListener(listener); mapped.removeListener(listener); original.value = 123; expect(original.value, mapped.value); }); }); } Expected: Value of original and mapper notifier should be same Actual: Value of original and mapper notifier is different — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.>

Yes, you are right. Pls see this reproduction, also i will edit original post.

import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:functional_listener/functional_listener.dart';

void main() {
  group('MapValueNotifier', () {
    test('should return same value', () {
      void listener() {}

      final original = ValueNotifier(0);
      final mapped = original.map((value) => value);

      mapped.addListener(listener);
      mapped.removeListener(listener);

      original.value = 123;

      expect(original.value, mapped.value);
    });
  });
}
karabanovbs commented 1 month ago

When the last listener was removed MapValueNotifier didn't update value anymore. However before the first listener is added, the value update is correct.

karabanovbs commented 1 month ago

@escamoteur Have you any opinion about it?

escamoteur commented 1 month ago

Hey, sorry, currently busy in a project. Thanks for PR I look into it this evening Am 8. Aug. 2024, 10:25 +0100 schrieb KarabanovBoris @.***>:

@escamoteur Have you any opinion about it? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>