rodydavis / signals.dart

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

Enhance value assignment equality for IterableSignals #243

Open leoafarias opened 5 months ago

leoafarias commented 5 months ago

The current implementation of the equality check in the IterableSignal class (which ListSignal extends) compares the iterable references instead of comparing the actual values of the iterable.

This behavior is expected when assigning a list using signal, but in my opinion using listSignal, or some of the other IterableSignals, this should be handled.

final value1 = [1, 2, 3];
final value2 = [1, 2, 3];

final list = listSignal(value1);

effect(() {
  print('list changed');
  print(list.value);
});

list.value = value2;

// prints: list changed
// prints: [1,2,3]

Suggestions

  1. Adapt our equality check within IterableSignal to align more with how collection functions are handled, thus ensuring a comparison based on the value.
  2. Allow the provision of a specific equality function for each iterable signal function, enabling more flexible and customised evaluation.
rodydavis commented 5 months ago

Do you mean you want ListSignal to compare with DeepCollectionEquality?

leoafarias commented 5 months ago

Yes, but if you don't want to bring as a dependency, maybe we can create an equivalent. Let me know what makes sense, and I can give a try on a PR.

rodydavis commented 5 months ago

I'm trying to hold off adding dependencies as long as possible to maximize compatibility with projects.

I think having something equivalent would be a great addition!

leoafarias commented 5 months ago

I agree, will create a PR for you to review if it makes sense.

rodydavis commented 5 months ago

Sounds great!