Skip to content

Commit

Permalink
fix: Observable.value setter (covariant) (#993)
Browse files Browse the repository at this point in the history
* fix(observable): check if new value is an instance of WillChangeNotification unchanged before setting it

* chore(observable): Bump version to 2.3.2 and update CHANGELOG.md with bug fix for Observable value setter
  • Loading branch information
altynbek132 authored Mar 28, 2024
1 parent 40bb244 commit 6ac04c7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions mobx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.2

- Fix Observable.value setter when class with operator ==(covariant) is used as a value

## 2.3.1

- Fix preserving stacktrace in Computed and Reaction when exception thrown inside argument function
Expand Down
3 changes: 2 additions & 1 deletion mobx/lib/src/core/observable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class Observable<T> extends Atom
final oldValue = _value;
final newValueDynamic = _prepareNewValue(value);

if (newValueDynamic == WillChangeNotification.unchanged) {
if (newValueDynamic is WillChangeNotification &&
newValueDynamic == WillChangeNotification.unchanged) {
return;
}
final newValue = newValueDynamic as T;
Expand Down
2 changes: 1 addition & 1 deletion mobx/lib/version.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated via set_version.dart. !!!DO NOT MODIFY BY HAND!!!

/// The current version as per `pubspec.yaml`.
const version = '2.3.1';
const version = '2.3.2';
2 changes: 1 addition & 1 deletion mobx/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mobx
version: 2.3.1
version: 2.3.2
description: "MobX is a library for reactively managing the state of your applications. Use the power of observables, actions, and reactions to supercharge your Dart and Flutter apps."

repository: https://github.com/mobxjs/mobx.dart
Expand Down
15 changes: 15 additions & 0 deletions mobx/test/observable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ void main() {
x.value = 100;
expect(x.nonObservableValue, 100);
});

test('set value covariant', () async {
final x = Observable<_Covariant?>(null);
x.value = _Covariant();
});
});

group('createAtom()', () {
Expand Down Expand Up @@ -111,3 +116,13 @@ void main() {
});
});
}

class _Covariant {
@override
// ignore: hash_and_equals
bool operator ==(covariant _Covariant other) {
if (identical(this, other)) return true;

return other is _Covariant;
}
}

0 comments on commit 6ac04c7

Please sign in to comment.