Skip to content

Commit

Permalink
test: fix tests in dart 2.19 (#879)
Browse files Browse the repository at this point in the history
* test: fix tests in dart 2.19

* test: fix tests in dart 2.19

* test: fix tests in dart 2.19
  • Loading branch information
amondnet authored Nov 13, 2022
1 parent 021f4a0 commit 0391ef0
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 13 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.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)
Expand Down
2 changes: 2 additions & 0 deletions mobx/lib/src/core.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:async';
import 'dart:collection';

import 'package:meta/meta.dart';

import '../mobx.dart';
import 'utils.dart';

Expand Down
2 changes: 1 addition & 1 deletion mobx/lib/src/core/atom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Atom {
final Map<_ListenerKind, Set<void Function()>?> _observationListeners = {};

void reportObserved() {
_context._reportObserved(this);
_context.reportObserved(this);
}

void reportChanged() {
Expand Down
6 changes: 3 additions & 3 deletions mobx/lib/src/core/computed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Computed<T> extends Atom implements Derivation, ObservableValue<T> {

T? computeValue({required bool track}) {
_isComputing = true;
_context._pushComputation();
_context.pushComputation();

T? value;
if (track) {
Expand All @@ -114,15 +114,15 @@ class Computed<T> extends Atom implements Derivation, ObservableValue<T> {
}
}

_context._popComputation();
_context.popComputation();
_isComputing = false;

return value;
}

@override
void _suspend() {
_context._clearObservables(this);
_context.clearObservables(this);
_value = null;
}

Expand Down
12 changes: 8 additions & 4 deletions mobx/lib/src/core/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ class ReactiveContext {
return result;
}

void _reportObserved(Atom atom) {
@protected
void reportObserved(Atom atom) {
final derivation = _state.trackingDerivation;

if (derivation != null) {
Expand Down Expand Up @@ -404,7 +405,8 @@ class ReactiveContext {
}
}

void _clearObservables(Derivation derivation) {
@protected
void clearObservables(Derivation derivation) {
final observables = derivation._observables;
derivation._observables = {};

Expand Down Expand Up @@ -521,11 +523,13 @@ class ReactiveContext {
_state.allowStateChanges = allow;
}

void _pushComputation() {
@protected
void pushComputation() {
_state.computationDepth++;
}

void _popComputation() {
@protected
void popComputation() {
_state.computationDepth--;
}

Expand Down
6 changes: 3 additions & 3 deletions mobx/lib/src/core/reaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ReactionImpl implements Reaction {
_isRunning = false;

if (_isDisposed) {
_context._clearObservables(this);
_context.clearObservables(this);
}

_context.endBatch();
Expand All @@ -85,7 +85,7 @@ class ReactionImpl implements Reaction {
_isRunning = false;

if (_isDisposed) {
_context._clearObservables(this);
_context.clearObservables(this);
}

if (_context._hasCaughtException(this)) {
Expand Down Expand Up @@ -142,7 +142,7 @@ class ReactionImpl implements Reaction {
// ignore: cascade_invocations
_context
..startBatch()
.._clearObservables(this)
..clearObservables(this)
..endBatch();
}

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.1.1';
const version = '2.1.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.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
Expand Down
15 changes: 15 additions & 0 deletions mobx/test/reaction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

});
});
});
}

0 comments on commit 0391ef0

Please sign in to comment.