diff --git a/mobx/CHANGELOG.md b/mobx/CHANGELOG.md index e195b9802..9a40ef47b 100644 --- a/mobx/CHANGELOG.md +++ b/mobx/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.1.2 + +- Fix tests in dart 2.19 - [@amondnet](https://github.com/amondnet) + ## 2.1.1 - Allow a custom equals parameter for ObservableStream - [@amondnet](https://github.com/amondnet) diff --git a/mobx/lib/src/core.dart b/mobx/lib/src/core.dart index 171742da5..f02caf09e 100644 --- a/mobx/lib/src/core.dart +++ b/mobx/lib/src/core.dart @@ -1,6 +1,8 @@ import 'dart:async'; import 'dart:collection'; +import 'package:meta/meta.dart'; + import '../mobx.dart'; import 'utils.dart'; diff --git a/mobx/lib/src/core/atom.dart b/mobx/lib/src/core/atom.dart index 8614a8129..f9b579772 100644 --- a/mobx/lib/src/core/atom.dart +++ b/mobx/lib/src/core/atom.dart @@ -52,7 +52,7 @@ class Atom { final Map<_ListenerKind, Set?> _observationListeners = {}; void reportObserved() { - _context._reportObserved(this); + _context.reportObserved(this); } void reportChanged() { diff --git a/mobx/lib/src/core/computed.dart b/mobx/lib/src/core/computed.dart index 79929519f..717a23b57 100644 --- a/mobx/lib/src/core/computed.dart +++ b/mobx/lib/src/core/computed.dart @@ -96,7 +96,7 @@ class Computed extends Atom implements Derivation, ObservableValue { T? computeValue({required bool track}) { _isComputing = true; - _context._pushComputation(); + _context.pushComputation(); T? value; if (track) { @@ -114,7 +114,7 @@ class Computed extends Atom implements Derivation, ObservableValue { } } - _context._popComputation(); + _context.popComputation(); _isComputing = false; return value; @@ -122,7 +122,7 @@ class Computed extends Atom implements Derivation, ObservableValue { @override void _suspend() { - _context._clearObservables(this); + _context.clearObservables(this); _value = null; } diff --git a/mobx/lib/src/core/context.dart b/mobx/lib/src/core/context.dart index faae12389..30ce706b2 100644 --- a/mobx/lib/src/core/context.dart +++ b/mobx/lib/src/core/context.dart @@ -264,7 +264,8 @@ class ReactiveContext { return result; } - void _reportObserved(Atom atom) { + @protected + void reportObserved(Atom atom) { final derivation = _state.trackingDerivation; if (derivation != null) { @@ -404,7 +405,8 @@ class ReactiveContext { } } - void _clearObservables(Derivation derivation) { + @protected + void clearObservables(Derivation derivation) { final observables = derivation._observables; derivation._observables = {}; @@ -521,11 +523,13 @@ class ReactiveContext { _state.allowStateChanges = allow; } - void _pushComputation() { + @protected + void pushComputation() { _state.computationDepth++; } - void _popComputation() { + @protected + void popComputation() { _state.computationDepth--; } diff --git a/mobx/lib/src/core/reaction.dart b/mobx/lib/src/core/reaction.dart index 5ba9468fb..cbfce29e7 100644 --- a/mobx/lib/src/core/reaction.dart +++ b/mobx/lib/src/core/reaction.dart @@ -64,7 +64,7 @@ class ReactionImpl implements Reaction { _isRunning = false; if (_isDisposed) { - _context._clearObservables(this); + _context.clearObservables(this); } _context.endBatch(); @@ -85,7 +85,7 @@ class ReactionImpl implements Reaction { _isRunning = false; if (_isDisposed) { - _context._clearObservables(this); + _context.clearObservables(this); } if (_context._hasCaughtException(this)) { @@ -142,7 +142,7 @@ class ReactionImpl implements Reaction { // ignore: cascade_invocations _context ..startBatch() - .._clearObservables(this) + ..clearObservables(this) ..endBatch(); } diff --git a/mobx/lib/version.dart b/mobx/lib/version.dart index 416e1234e..ddccdbb3f 100644 --- a/mobx/lib/version.dart +++ b/mobx/lib/version.dart @@ -1,4 +1,4 @@ // Generated via set_version.dart. !!!DO NOT MODIFY BY HAND!!! /// The current version as per `pubspec.yaml`. -const version = '2.1.1'; +const version = '2.1.2'; diff --git a/mobx/pubspec.yaml b/mobx/pubspec.yaml index 3b85993d9..3112e93d3 100644 --- a/mobx/pubspec.yaml +++ b/mobx/pubspec.yaml @@ -1,5 +1,5 @@ name: mobx -version: 2.1.1 +version: 2.1.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." homepage: https://github.com/mobxjs/mobx.dart diff --git a/mobx/test/reaction_test.dart b/mobx/test/reaction_test.dart index a920c1cce..e7816afdd 100644 --- a/mobx/test/reaction_test.dart +++ b/mobx/test/reaction_test.dart @@ -321,6 +321,21 @@ void main() { expect(reaction1.hasObservables, isTrue); }); + + test('when disposed, clearObservables', () { + final x = Observable(0); + + final reaction = ReactionImpl(mainContext, () {}, name: 'test_reaction_1') + ..track(() => x.value + 1); + expect(reaction.hasObservables, isTrue); + + reaction.dispose(); + final prevDerivation = reaction.startTracking(); + reaction.endTracking(prevDerivation); + + expect(reaction.hasObservables, isFalse); + + }); }); }); }