Skip to content

Conversation

amondnet
Copy link
Collaborator

@amondnet amondnet commented Dec 15, 2023

Describe the changes proposed in this Pull Request.

Allow a custom equals parameter for observable collections, like observable stream, observable and computed .

#771
#482

If the PR fixes a specific issue, reference the issue with Fixes #.


Pull Request Checklist

  • If the changes are being made to code, ensure the version in pubspec.yaml is updated.
  • Increment the major/minor/patch/patch-count, depending on the complexity of change
  • Add the necessary unit tests to ensure the coverage does not drop
  • Update the Changelog to include all changes made in this PR, organized by version
  • Run the melos run set_version command from the root directory
  • Include the necessary reviewers for the PR
  • Update the docs if there are any API changes or additions to functionality

Copy link

netlify bot commented Dec 15, 2023

👷 Deploy request for mobx pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit d13d88d

Copy link

codecov bot commented Dec 15, 2023

Codecov Report

Merging #970 (d13d88d) into main (d14a27e) will decrease coverage by 0.62%.
Report is 3 commits behind head on main.
The diff coverage is 83.33%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #970      +/-   ##
==========================================
- Coverage   99.00%   98.38%   -0.62%     
==========================================
  Files          57       57              
  Lines        2005     2043      +38     
==========================================
+ Hits         1985     2010      +25     
- Misses         20       33      +13     
Flag Coverage Δ
flutter_mobx 100.00% <ø> (ø)
mobx 97.69% <83.33%> (-0.88%) ⬇️
mobx_codegen 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...rc/api/observable_collections/observable_list.dart 99.20% <90.00%> (-0.80%) ⬇️
...src/api/observable_collections/observable_map.dart 98.41% <89.47%> (-1.59%) ⬇️
...src/api/observable_collections/observable_set.dart 91.17% <76.92%> (-8.83%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d14a27e...d13d88d. Read the comment docs.

@amondnet amondnet force-pushed the add-equals-observable-collection branch from 076d509 to 851e078 Compare December 15, 2023 10:23
@amondnet amondnet marked this pull request as draft December 15, 2023 10:25
@amondnet amondnet force-pushed the add-equals-observable-collection branch from 851e078 to d13d88d Compare December 15, 2023 10:30
@amondnet amondnet self-assigned this Dec 19, 2023
@amondnet amondnet force-pushed the add-equals-observable-collection branch from b1f29d8 to fda5217 Compare September 28, 2025 18:23
@amondnet amondnet marked this pull request as ready for review September 28, 2025 18:23
@amondnet amondnet requested a review from Copilot September 28, 2025 18:26
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR allows custom equality functions to be specified for MobX observable collections (ObservableList, ObservableMap, and ObservableSet). This enables developers to define custom comparison logic for determining when values are considered equal, which can optimize change detection and support custom equality semantics.

  • Adds EqualityComparer<T>? equals parameter to all observable collection constructors
  • Implements custom equality logic in value comparison operations for all three collection types
  • Updates cast methods to preserve custom equality functions with optional overrides

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
mobx/test/observable_collections_equals_test.dart Comprehensive test suite covering custom equals functionality across all collection types
mobx/pubspec.yaml Version bump from 2.5.0 to 2.6.0 for minor feature addition
mobx/lib/version.dart Updates version constant to match pubspec
mobx/lib/src/api/observable_collections/observable_set.dart Implements custom equals support for ObservableSet with updated constructors and equality logic
mobx/lib/src/api/observable_collections/observable_map.dart Adds custom equals parameter for value comparisons in ObservableMap
mobx/lib/src/api/observable_collections/observable_list.dart Integrates custom equals functionality into ObservableList operations
mobx/lib/src/api/observable_collections.dart Adds required imports for collection package and utils
mobx/CHANGELOG.md Documents the new custom equals feature in version 2.6.0

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}

T? _findValue(Object? value) {
if (value is T?) {
Copy link
Preview

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type check value is T? is incorrect for non-nullable types T. When T is non-nullable (e.g., String), T? becomes String?, but value with type Object? cannot be checked against T? directly. This should use value is T to check if value can be cast to the non-nullable type T.

Suggested change
if (value is T?) {
if (value is T) {

Copilot uses AI. Check for mistakes.

_list.cast<R>(),
equals ??
(_equals != null
? (R? a, R? b) => _equals!(a as T?, b as T?)
Copy link
Preview

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsafe casting from R? to T? without type checking. If R and T are incompatible types, this will cause a runtime exception. Should add type compatibility checks or use a safer casting approach.

Suggested change
? (R? a, R? b) => _equals!(a as T?, b as T?)
? (R? a, R? b) {
if (a is T? && b is T?) {
return _equals!(a, b);
}
return false;
}

Copilot uses AI. Check for mistakes.

equals ??
(_equals == null
? null
: (RV? a, RV? b) => _equals!(a as V?, b as V?)));
Copy link
Preview

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsafe casting from RV? to V? without type checking. If RV and V are incompatible types, this will cause a runtime exception. Should add type compatibility checks or use a safer casting approach.

Suggested change
: (RV? a, RV? b) => _equals!(a as V?, b as V?)));
: (RV? a, RV? b) {
if (a is V? && b is V?) {
return _equals!(a, b);
}
// If types are incompatible, consider them not equal
return false;
}));

Copilot uses AI. Check for mistakes.

equals ??
(_equals == null
? null
: (R? a, R? b) => _equals!(a as T?, b as T?)));
Copy link
Preview

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsafe casting from R? to T? without type checking. If R and T are incompatible types, this will cause a runtime exception. Should add type compatibility checks or use a safer casting approach.

Suggested change
: (R? a, R? b) => _equals!(a as T?, b as T?)));
: (R? a, R? b) {
if (a is! T || b is! T) return false;
return _equals!(a as T?, b as T?);
}));

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant